msdn的解释:
The WM_NCLBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
使用WM_NCLBUTTONDOWN 消息:
利用标题栏的消息,欺骗windows使得点击客户区可实现窗体的移动。在打击客户区的时候假传消息给windows,告诉他现在左击标题栏。
void CDragWindowDlg::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);
}
C# 使用WM_NCLBUTTONDOWN消息实现任意位置移动窗体 public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,
int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if ((e.Clicks == 1))
{
ReleaseCapture();
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
}
posted on 2010-03-18 10:40
漂漂 阅读(1604)
评论(0) 编辑 收藏 引用 所属分类:
深入vc++