这段是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吧
你需要算出标题栏的区域.
谢谢,就是如你所说,SystemInformation.CaptionHeight这个值没有搞清楚
结贴
c++ 有API可以计算的