VC画线几个常见方法

首先,在VIEW类中增加一个私有的成员变量m_ptOrigin,再增加两个windows的消息响应,一个是WM_LBUTTONDOWN,一个是WM_LBUTTONUP. 1:利用HDC去画线; 2:利用CDC画线; 3:利用CClientDC画线; 4:利用CWindowDC画线; 5:利用Cpen画线; 代码如下(仅包含了WM_LBUTTONDOWN和WM_LBUTTONUP中的代码): void CBlogView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_ptOrigin=point; CView::OnLButtonDown(nFlags, point); } void CBlogView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default /* HDC hdc; hdc=::GetDC(m_hWnd); MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,NULL); LineTo(hdc,point.x,point.y); ::ReleaseDC(m_hWnd,hdc);//利用SDK的HDC画线 */ /* CDC *pDC=GetDC(); pDC->MoveTo(m_ptOrigin); pDC->LineTo(point); ReleaseDC(pDC);//利用CDC画线 */ /* CClientDC dc(this); dc.MoveTo(m_ptOrigin); dc.LineTo(point);//利用CClientDC画线 */ /* CWindowDC dc(GetDesktopWindow()); dc.MoveTo(m_ptOrigin); dc.LineTo(point);//利用CWindowDC画线。 */ /* CPen pen(PS_SOLID,1,RGB(123,123,123)); CClientDC dc(this); CPen *pOldPen=dc.SelectObject(&pen); dc.MoveTo(m_ptOrigin); dc.LineTo(point); dc.SelectObject(pOldPen);//用Cpen去画线 */ CView::OnLButtonUp(nFlags, point); }

你可能感兴趣的:(windows,null)