سؤال

I know that a Button, when clicked, sends the WM_COMMAND message to it's parent, but what message does it receive that makes it send this message? I am overriding the default WndProc of a button and the button does not receive the WM_COMMAND message, so I need to know what message causes a button to send the WM_COMMAND message so I can replicate that functionality.

هل كانت مفيدة؟

المحلول

I found that it's actually a combination of WM_LBUTTONDOWN, WM_MOUSELEAVE, and a few other things. For example, the WM_COMMAND will only be fired if the mouse was depressed on the button, and is still on the button when WM_LBUTTONUP is fired. As for space, enter, etc, I believe it just handles the VK_ENTER message and stuff.

نصائح أخرى

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

WM_COMMAND message is always received by controls parent. If you want to click button programmatically you can do this:

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

LPARAM of WM_COMMAND holds button_handle. So you can extract information about you button calling

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

You must have been set this information earlier like this

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

for example some_info can by pointer to button wrapper object

It is not possible to override WM_COMMAND message because WM_LBUTTONDOWN message is converted as WM_COMMAND message and send it to parent control. This is the mechanism that is done in the background.

You asked about space and enter key.This can be controlled by virtual key codes like vk_enter , vk_tab...etc.,

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top