Joining win32
I want any window to close as soon as the mouse hovers over the close button on its non-client area. I tried to catch wm_ncmousemove using WH_GETMESSAGE in SetWindowsHookEx and then using SendMessage to send a WM_DESTROY message to the specified window, but the window doesn't close. Any help ????
LRESULT CALLBACK CallWndProc(int code, WPARAM wParam, LPARAM lParam)
{
MSG* msg = (MSG*) lParam;
if(code == HC_ACTION)
{
if(msg->message == WM_NCMOUSEMOVE)
{
if(msg->wParam == HTCLOSE)
{
SendMessage(hwndTarget, WM_DESTROY, wParam, lParam);
}
}
}
return CallNextHookEx(g_hkMsg, code, wParam, lParam);
}
INT WINAPI InstallW(HWND hwnd, HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow)
{
DWORD dwTarget = 0;
POINT point;
GetCursorPos(&point);
hwndTarget = WindowFromPoint(point);
dwTarget = GetWindowThreadProcessId(hwndTarget, NULL);
g_hkMsg = SetWindowsHookEx(WH_GETMESSAGE, CallWndProc, g_hInstance, 0);
if(g_hkMsg)
{
MessageBox(NULL, L"Message hook installed, press OK to uninstall.", L"HLHookTest", MB_ICONEXCLAMATION);
UnhookWindowsHookEx(g_hkMsg);
}
else
MessageBox(NULL, L"Hook installation failed.", L"HLHookTest", MB_ICONERROR);
return 0;
}
+1
source to share