benny5609的专栏

人生,到世上走一遭,只不过是单纯的体验与学习认识,当我们在临死的时候,可以光荣地对自己说:"我已领略过"便不枉此生。...

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

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

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);

}

 
阅读更多
个人分类: Windows
上一篇HDC vs CDC
下一篇VCKBase_50_篇2:Unicode
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭