这段是WM_MOUSE_LL响应函数里面的
        private void HookOnMouseActivity(object sener, HookEx.MouseExEventArgs e) {
            Point location = e.Location;            if (e.Button == MouseButtons.Left) {
                Rectangle captionRect = new Rectangle(this.Location, new Size(this.Width, SystemInformation.CaptionHeight));
                if (captionRect.Contains(location)) {
                    SetWindowLong(this.Handle, GWL_EXSTYLE,
                        (int)GetWindowLong(this.Handle, GWL_EXSTYLE) & (~WS_DISABLED));
                    SendMessage(this.Handle, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
                } else {
                    SetWindowLong(this.Handle, GWL_EXSTYLE,
                        (int)GetWindowLong(this.Handle, GWL_EXSTYLE) | WS_DISABLED);
                }
            }
        }
翻译成下面的vc++代码
g_hwnd 为我的程序的HWND 给值在我的dlg程序的 initdialog里面,g_hwnd=this->m_hWnd;
//这段是WM_MOUSE_LL响应函数里面的
if(nCode==HC_ACTION)
{
if(wParam==WM_LBUTTONDOWN||wParam==WM_LBUTTONUP)
{
CRect rectwindow;
::GetWindowRect(g_hwnd,&rectwindow); MSLLHOOKSTRUCT* msl = (MSLLHOOKSTRUCT *)lParam;
if(rectwindow.PtInRect(msl->pt))
{
SetWindowLong(g_hwnd, GWL_EXSTYLE,GetWindowLong(g_hwnd, GWL_EXSTYLE) & (~WS_DISABLED));
                SendMessage(g_hwnd, WM_SETFOCUS, 0, 0);
}
else
{
SetWindowLong(g_hwnd, GWL_EXSTYLE,GetWindowLong(g_hwnd, GWL_EXSTYLE)|WS_DISABLED);
}
}
}请问这样转换对不对,还有,this.handle 就是当前窗口的 HWND吧

解决方案 »

  1.   

    如果在窗体中那this.handle 就是当前窗口的 HWND你那样转的逻辑不对,C#中是得到标题栏的区域,判断是在标题栏的区域按下左键就进行处理,而你的VC++是得到指定窗口的边框矩形的尺寸.判断是在窗口的边框矩形的尺寸内按下左键就进行处理.判断处理的区域不一.http://hi.baidu.com/yh121212/blog/item/521172c646b7211b9c163d3c.html
    你需要算出标题栏的区域.
      

  2.   


    谢谢,就是如你所说,SystemInformation.CaptionHeight这个值没有搞清楚
    结贴
    c++ 有API可以计算的