subclass a button, how let it know CLICK event
-
when a button is clicked, the parent of the button will receive WM_COMMAND message. Check whether the high-order word of the wparam is BN_CLICKED. if( message == WM_COMMAND && BN_CLICKED == HIWORD( wParam)) { // button is clicked. } the lparam will be having the handle of button.
nave
-
The basic technique used to subclass a window using straight Win32 is as follows: - Declare a variable of type
WNDPROC
to point to the old window procedure before subclassing. i.e.WNDPROC g_pSuperClass;
- Write a replacement window procedure which defers all unhandled messages to the old one. i.e.LRESULT CALLBACK MyWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return CallWindowProc(g_pSuperClass, hwnd, uMsg, wParam, lParam); }
- Now subclass the window with code like this:g_pSuperClass = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hwndButton, GWLP_WNDPROC)); SetWindowLongPtr(hwndButton, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&MyWindowProc));
Now to specialize the window alter the code inMyWindowProc
. To handle the click event however you don't need to subclass the window. The button sends theBN_CLICK
notification to its parent when it's clicked. This messages is packaged in aWM_COMMAND
message.Steve
-
when a button is clicked, the parent of the button will receive WM_COMMAND message. Check whether the high-order word of the wparam is BN_CLICKED. if( message == WM_COMMAND && BN_CLICKED == HIWORD( wParam)) { // button is clicked. } the lparam will be having the handle of button.
nave
-
but i want my button handle click, only use itself message. LRESULT ButtonProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { ........ } return DefWindowProc(message, wParam, lParam); }