关闭

使用画line的方法介绍HDC CDC CClientDC CWindowDC用法

标签: constructionwindows文档null
1154人阅读 评论(0) 收藏 举报
分类:

建立项目,采用单文档结构

HDC:

首先在CYourClassView类中add windows message handler, 一个是LButtonDown, 另一个是LButtonUp. 添加成员变量:m_ptOrigin用来记录初始点位置。

view结构体中初始化m_ptOrigin变量:

CYourClassView:: CYourClassView ()

{

       // TODO: add construction code here

       m_ptOrigin=0;

}

LButtonDown函数里面添加代码:

void CYourClassView::OnLButtonDown(UINT nFlags, CPoint point)

{

       // TODO: Add your message handler code here and/or call default

       m_ptOrigin=point;

       CView::OnLButtonDown(nFlags, point);

}

LButtonUp中添加代码,首先使用HDC:

void CYourClassView::OnLButtonUp(UINT nFlags, CPoint point)

{

       // TODO: Add your message handler code here and/or call default

       HDC hdc;

       hdc=::GetWindowDC(m_hWnd);

       MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,NULL);

       LineTo(hdc,point.x,point.y);

       ::ReleaseDC(m_hWnd,hdc);

       CView::OnLButtonUp(nFlags, point);

}

使用CDC:

void CYourClassView::OnLButtonUp(UINT nFlags, CPoint point)

{

       // TODO: Add your message handler code here and/or call default

       CDC *pdc=GetDC();

       pdc->MoveTo(m_ptOrigin);

       pdc->LineTo(point);

       ReleaseDC(pdc);

       CView::OnLButtonUp(nFlags, point);

}

使用CClientDC:

void CYourClassView::OnLButtonUp(UINT nFlags, CPoint point)

{

       // TODO: Add your message handler code here and/or call default

       CClientDC dc(this);

       dc.MoveTo(m_ptOrigin);

       dc.LineTo(point);

       CView::OnLButtonUp(nFlags, point);

}

使用CWindowDC:

void CYourClassView::OnLButtonUp(UINT nFlags, CPoint point)

{

       // TODO: Add your message handler code here and/or call default

       CWindowDC dc(this);

       dc.MoveTo(m_ptOrigin);

       dc.LineTo(point);

       CView::OnLButtonUp(nFlags, point);

}

 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1337683次
    • 积分:20793
    • 等级:
    • 排名:第364名
    • 原创:810篇
    • 转载:12篇
    • 译文:1篇
    • 评论:227条
    最新评论
    ATL/WTL
    Big Deal
    Book