[cpp] view plain copy
- // 派生自CButton类,主要过滤WM_LBUTTONDOWN 、WM_LBUTTONUP和WM_MOUSEMOVE消息。
- BOOL m_bFlag = FALSE; // 成员变量,用来标示鼠标是否按下, 初始化为FALSE
- CPoint m_pt; // 成员变量,用来保存当前坐标值
- BOOL CXXButton::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
- switch(pMsg->message)
- {
- case WM_LBUTTONDOWN:
- {
- m_pt = pMsg->pt;
- m_bFlag = TRUE;
- }
- break;
- case WM_LBUTTONUP:
- {
- m_bFlag = FALSE;
- }
- break;
- case WM_MOUSEMOVE:
- {
- if(m_bFlag)
- {
- int cx = pMsg->pt.x - m_pt.x;
- int cy = pMsg->pt.y - m_pt.y;
- CRect rc;
- GetWindowRect(&rc);
- GetParent()->ScreenToClient(&rc);
- int nWidth = rc.Width();
- int nHeight = rc.Height();
- rc.left += cx;
- rc.top += cy;
- rc.right = rc.left + nWidth;
- rc.bottom = rc.top + nHeight;
- MoveWindow(rc);
- m_pt = pMsg->pt;
- }
- }
- break;
- default:
- break;
- }
- return CButton::PreTranslateMessage(pMsg);
- }
http://blog.csdn.net/visualeleven/article/details/7177775
时间: 2024-10-16 14:33:37