MFC中窗口划线的问题

第一步   创建对应窗口的DC指针

CWnd *pwnd = GetDlgItem(IDC_Xiaoy_STATIC);
CDC *pDC = this->GetDC();
this->DrawLine(pDC);


第二用dc指针实现划线 

void CMFC_OCTDlg::DrawLine(CDC* pDC)
{
CRect ClientRect; 
CPen pen;
pen.CreatePen(PS_SOLID, 2, RGB(255, 255, 255));
m_Picture.GetClientRect(ClientRect);
CPoint StartPoint(0,0),EndPoint(50,50); 
int height = ClientRect.bottom*2.5;
int width = ClientRect.right*2.5; 
pDC->SelectObject(&pen);
pDC->SetMapMode(MM_LOMETRIC);  // cast light upon x positive value point right, Y positive value point upon 
pDC->MoveTo(0, 10);
pDC->LineTo(width-100,10);
// draw scale  
for (int i = 0; i < width; i += 10)
{
if (i / 100 == 0)  //the diatance of scale is 1cm 
{
pDC->MoveTo(i, 0);
pDC->LineTo(i, -70);


pDC->MoveTo(0, -height + i);
pDC->LineTo(70, -height + i);


pDC->MoveTo(width - i, -height + 100);
pDC->LineTo(width - i, -height + 30);


pDC->MoveTo(width, -i);
pDC->LineTo(width - 70, -i);


}
else if (i % 50 == 0) //the distance of little scale is 50mm
{
pDC->MoveTo(i, 0);
pDC->LineTo(i, -60);


pDC->MoveTo(0, -height + i);
pDC->LineTo(60, -height + i);


pDC->MoveTo(width - i, -height + 100);
pDC->LineTo(width - i, -height + 40);


pDC->MoveTo(width, -i);
pDC->LineTo(width - 60, -i);
}
else
{
pDC->MoveTo(i,0);
pDC->LineTo(i,-50);


pDC->MoveTo(0, -height + i);
pDC->LineTo(60, -height + i);


pDC->MoveTo(width - i, -height + 100);
pDC->LineTo(width - i, -height + 50); 


pDC->MoveTo(width, -i);
pDC->LineTo(width - 50, -i);
}
}


}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值