I WM_EXITSIZEMOVE
trying to catch WM_ENTERSIZEMOVE
and WM_EXITSIZEMOVE
messages for a window whose handle is a member of the class. To do this, use SetWindowsHookExA
with the WH_GETMESSAGE
parameter. The second parameter of the function ( HOOKPROC
) indicates the function inside my class:
class WindowDisplayHelper : // public ... { public: // some other public methods here void SetMsgHook(); protected: LRESULT CALLBACK GetMsgProcHook(int code, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK MsgPoc(int code, WPARAM wParam, LPARAM lParam); private: // some other private members there HWND m_windowHandle; bool m_isWindowResizing = false; static HHOOK m_msgHook; static WindowsDisplayHelperMasterWindow* m_pThis; };
.cpp file:
WindowDisplayHelper* WindowDisplayHelper ::m_pThis = nullptr; HHOOK WindowDisplayHelper ::m_msgHook = NULL; void WindowDisplayHelper ::SetMsgHook() { m_pThis = this; m_msgHook = SetWindowsHookEx(WH_GETMESSAGE, MsgPoc, NULL, 0); } LRESULT CALLBACK WindowDisplayHelper::MsgPoc(int code, WPARAM wParam, LPARAM lParam) { if (m_pThis != nullptr) { return m_pThis->GetMsgProcHook(code, wParam, lParam); } return CallNextHookEx(0, code, wParam, lParam); } LRESULT CALLBACK WindowDisplayHelper::GetMsgProcHook(int code, WPARAM wParam, LPARAM lParam) { DUMPER_INFO("Hooked"); if (code < 0) { return CallNextHookEx(0, code, wParam, lParam); } MSG* lpmsg = (MSG*)lParam; DUMPER_INFO("Hooked for HWND: %p. Current window %p", lpmsg->hwnd, m_windowHandle); if (lpmsg->hwnd != m_windowHandle) { return CallNextHookEx(0, code, wParam, lParam); } if (lpmsg->message == WM_ENTERSIZEMOVE && !m_isWindowResizing) { DUMPER_INFO("Start window resizing"); m_isWindowResizing = true; } else if (lpmsg->message == WM_EXITSIZEMOVE && m_isWindowResizing) { DUMPER_INFO("Stop window resizing"); m_isWindowResizing = false; } return CallNextHookEx(0, code, wParam, lParam); }
The process of creating a WindowDisplayHelper
object:
auto helper = boost::make_shared<WindowDisplayHelper>(windowHandle); helper->SetMsgHook(); AddDisplayHelper(displayId, helper); return true;
And although I call SetMsgHook
after creating the WindowDisplayHelper
object, it looks like the hook is not installed: m_isWindowResizing
all the time == false and no logs are visible. Because the hook handler is inside the class, then I had to resort to tricks with a static pointer to this, but something didn’t work. I tried to specify the thread id (the result of GetCurrentThreadId
), but this also did not help. Can you please tell me why my window message handling function doesn't work?
SetWindowsHookEx
look suspicious. Not clearly, whence m_windowHandle undertakes? - VTT