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


1 answer


Submit either WM_CLOSE

or WM_SYSCOMMAND

instead wParam=SC_CLOSE

.



WM_CLOSE

and WM_SYSCOMMAND / SC_CLOSE

ask to close the window. WM_DESTROY

informs the window that it has been closed. Saying "you were closed" to the window does not close it.

+2


source







All Articles