随笔 - 224  文章 - 41  trackbacks - 0
<2024年7月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

享受编程

常用链接

留言簿(11)

随笔分类(159)

随笔档案(224)

文章分类(2)

文章档案(4)

经典c++博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜

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 漂漂 阅读(1576) 评论(0)  编辑 收藏 引用 所属分类: 深入vc++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理