Which message calls the button to send the WM_COMMAND message

I know that a button, when pressed, sends a WM_COMMAND message to this parent element, but what message does it receive that make it send this message? I override the default WndProc button and the button does not receive the WM_COMMAND message, so I need to know which message the button calls to send the WM_COMMAND message so that I can replicate this functionality.

+4
source share
4 answers

I found that this is actually a combination of WM_LBUTTONDOWN, WM_MOUSELEAVE and several other things. For example, WM_COMMAND will be launched only if the mouse is pressed on the button and is still on the button when WM_LBUTTONUP is launched. As for space, type, etc., I believe that it just processes the message VK_ENTER and so on.

+3
source

I seem to recall it WM_LBUTTONUP, but use the Spy program to find out for sure.

0
source

You cannot override the WM_COMMAND message because the WM_LBUTTONDOWN message is converted to a WM_COMMAND message and sends it to the parent control. This is a mechanism that runs in the background.

You asked about the space and enter the key. This can be controlled using virtual key codes such as vk_enter , vk_tab ... etc.,

0
source

The WM_COMMAND message always gets parental control. If you want to programmatically click a button, you can do this:

 ::SendMessage( button_handle, BM_CLICK, 0, 0 ); 

In LPARAM WM_COMMAND, the button button_handle is executed. This way you can retrieve information about the button that calls

 ::GetWindowLongPtr( HWND( lParam ), GWL_USERDATA ); 

You should have installed this information before, like this

 ::SetWindowLongPtr( button_handle, GWL_USERDATA, reinterpret_cast<LONG_PTR>( some_info ) ); 

for example, some_info can follow a pointer to a button wrapper object

0
source

Source: https://habr.com/ru/post/1332831/


All Articles