本文共 1338 字,大约阅读时间需要 4 分钟。
//范例1/
声明:
CRect lastRect; CRectTracker m_rectTracker;
void CUseCRectTrackerDlg::OnLButtonDown(UINT nFlags, CPoint point) { CRect clientRect; GetClientRect(clientRect); m_rectTracker.m_rect = CRect(point.x - 10,0,point.x,clientRect.Height()); m_rectTracker.m_nStyle = CRectTracker::hatchInside; CClientDC dc(this); m_rectTracker.Draw(&dc); lastRect = m_rectTracker.m_rect; CDialogEx::OnLButtonDown(nFlags, point); }
void CUseCRectTrackerDlg::OnMouseMove(UINT nFlags, CPoint point) { if (nFlags == MK_LBUTTON ) { CRect clientRect; GetClientRect(clientRect); this->InvalidateRect(lastRect); UpdateWindow(); m_rectTracker.m_rect = CRect(point.x - 10,0,point.x,clientRect.Height()); m_rectTracker.m_nStyle = CRectTracker::hatchInside; CClientDC dc(this); m_rectTracker.Draw(&dc); lastRect = m_rectTracker.m_rect; } CDialogEx::OnMouseMove(nFlags, point); }
void CUseCRectTrackerDlg::OnLButtonUp(UINT nFlags, CPoint point) { this->Invalidate(TRUE); CDialogEx::OnLButtonUp(nFlags, point); }
PS:可能需要的辅助函数
this->SetCapture(); ::ReleaseCapture(); //捕获鼠标的输入
ClipCursor(&clipRect); ClipCursor(NULL); //限制鼠标移动的位置
PS:可能需要的辅助函数
this->SetCapture(); ::ReleaseCapture(); //捕获鼠标的输入
ClipCursor(&clipRect); ClipCursor(NULL); //限制鼠标移动的位置
//范例2/
PS:可能需要的辅助函数
this->SetCapture(); ::ReleaseCapture(); //捕获鼠标的输入
ClipCursor(&clipRect); ClipCursor(NULL); //限制鼠标移动的位置
转载地址:http://nlnws.baihongyu.com/