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
source share