16,473
社区成员
发帖
与我相关
我的任务
分享
void Ctest1Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
mouse_PressDown=true;
point_Start=point;
//ScreenToClient(&point_Start);
CDialog::OnLButtonDown(nFlags, point);
}
void Ctest1Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(mouse_PressDown)
{
CBitmap bitmap;
CDC memory_DC;
//ScreenToClient(&point);
CDC *dc;
CPen pen;
pen.CreatePen(0,2,RGB(255,255,255));
dc=this->GetDC();
CRect rect;
GetClientRect(&rect);
memory_DC.CreateCompatibleDC(dc);
bitmap.CreateCompatibleBitmap(dc,rect.Width(),rect.Height());
memory_DC.SelectObject(&bitmap);
memory_DC.SelectObject(&pen);
memory_DC.SetBkMode(TRANSPARENT);
memory_DC.MoveTo(point_Start);
memory_DC.LineTo(point);
dc->BitBlt(0,0,rect.Width(),rect.Height(),&memory_DC,0,0,SRCCOPY);
this->ReleaseDC(dc);
}
CDialog::OnMouseMove(nFlags, point);
}
void Ctest1Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
mouse_PressDown=false;
CDialog::OnLButtonUp(nFlags, point);
}
1.定义起始位置点
CPoint m_pStart;
2.在OnLButtonDown(UINT nFlags, CPoint point)中
m_pStart = point;
3.在OnLButtonUp(UINT nFlags, CPoint point)中
HDC hdc = ::GetDC(m_hWnd);
MoveToEx(hdc,m_pStart.x,m_pStart.y,NULL);
LineTo(hdc,point.x,point.y);
::ReleaseDC(m_hWnd,hdc);