- <strong>方法一:直接在OnNcHitTest中虚拟发送HTCAPTION消息</strong>
方法二:直接在OnLButtonDown中虚拟发送WM_NCLBUTTONDOWN,HTCAPTION消息
- void CaaaDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
- CDialog::OnLButtonDown(nFlags, point);
- }
方法三:通过在OnMouseMove中手动进行处理
- void CaaaDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- static CPoint PrePoint = CPoint(0, 0);
- if(MK_LBUTTON == nFlags)
- {
- if(point != PrePoint)
- {
- CPoint ptTemp = point - PrePoint;
- CRect rcWindow;
- GetWindowRect(&rcWindow);
- rcWindow.OffsetRect(ptTemp.x, ptTemp.y);
- MoveWindow(&rcWindow);
- return ;
- }
- }
- PrePoint = point;
- CDialog::OnMouseMove(nFlags, point);
- }
控件拖动:
控件拖动只能采用上述的第三种方法
转载自:
本文介绍了在C++编程环境下实现窗口拖动的三种不同方法:直接在OnNcHitTest中虚拟发送HTCAPTION消息;直接在OnLButtonDown中虚拟发送WM_NCLBUTTONDOWN,HTCAPTION消息;通过在OnMouseMove中手动进行处理。此外,还提供了控件拖动的具体实现方式。

6017

被折叠的 条评论
为什么被折叠?



