扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point) { //MessageBox("Left Button Clicks DrawView"); m_ptOrigin = point ; //这里先定义了一个内部变量保存直线的起始点 CView::OnLButtonDown(nFlags, point); } |
//方法一 void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { HDC hdc; hdc = ::GetDC(m_hWnd); //调用全局函数 MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,0); LineTo(hdc,point.x,point.y); ::ReleaseDC(m_hWnd,hdc); CView::OnLButtonUp(nFlags, point); } //方法二 void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CDC *pDC = GetDC(); pDC->MoveTo(m_ptOrigin); pDC->LineTo(point); ReleaseDC(pDC); } //方法三 void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CClientDC dc(this) ; //CClientDC对象构造的时候就调用了GetDC,析构的时候调用 ReleaseDC ,只能访问客户区 CClientDC dc(GetParent()); dc.MoveTo(m_ptOrigin); dc.LineTo(point); } //方法四 void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CWindowDC dc(this) ; //CWindowDC可以访问客户区和非客户区 dc.MoveTo(m_ptOrigin); dc.LineTo(point); } void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CWindowDC dc(GetDesktopWindow()) ; //现在可以访问桌面 dc.MoveTo(m_ptOrigin); dc.LineTo(point); } |
//画连续的线条 void CDrawView::OnMouseMove(UINT nFlags, CPoint point) { if ( m_bDraw ) { CClientDC dc(this) ; dc.MoveTo(m_ptOrigin); //移动到原来的点 dc.LineTo(point); //绘制直线 m_ptOrigin = point ; //将现在的点赋值给原来的坐标,以便下次调用 } CView::OnMouseMove(nFlags, point); } //改变画笔的颜色 void CDrawView::OnMouseMove(UINT nFlags, CPoint point) { if ( m_bDraw ) { CClientDC dc(this) ; CPen pen( PS_SOLID , 1 , RGB(255,128,128) ); CPen *pOldPen = dc.SelectObject(&pen); dc.MoveTo(m_ptOrigin); dc.LineTo(point); m_ptOrigin = point ; dc.SelectObject(pOldPen); } CView::OnMouseMove(nFlags, point); } //画扇型 void CDrawView::OnMouseMove(UINT nFlags, CPoint point) { if ( m_bDraw ) { CClientDC dc(this) ; CPen pen( PS_SOLID , 1 , RGB(255,128,128) ); CPen *pOldPen = dc.SelectObject(&pen); dc.MoveTo(m_ptOrigin); dc.LineTo(m_ptOld); dc.MoveTo(m_ptOrigin); dc.LineTo(point); m_ptOld = point ; dc.SelectObject(pOldPen); } CView::OnMouseMove(nFlags, point); } //画带边线的扇型 void CDrawView::OnMouseMove(UINT nFlags, CPoint point) { if ( m_bDraw ) { CClientDC dc(this) ; CPen pen( PS_SOLID , 1 , RGB(255,128,128) ); CPen *pOldPen = dc.SelectObject(&pen); dc.MoveTo(m_ptOrigin); dc.LineTo(m_ptOld); dc.MoveTo(m_ptOrigin); dc.LineTo(point); dc.MoveTo(m_ptOld); dc.LineTo(point); m_ptOld = point ; dc.SelectObject(pOldPen); } CView::OnMouseMove(nFlags, point); } //看看绘图的模式设置方法 void CDrawView::OnMouseMove(UINT nFlags, CPoint point) { if ( m_bDraw ) { CClientDC dc(this) ; dc.SetROP2(R2_BLACK); //绘图的模式设置,始终绘制黑色图形 CPen pen( PS_SOLID , 1 , RGB(255,128,128) ); CPen *pOldPen = dc.SelectObject(&pen); dc.MoveTo(m_ptOrigin); dc.LineTo(m_ptOld); dc.MoveTo(m_ptOrigin); dc.LineTo(point); dc.MoveTo(m_ptOld); dc.LineTo(point); m_ptOld = point ; dc.SelectObject(pOldPen); } CView::OnMouseMove(nFlags, point); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者