Calling an event handler programmatically in an MFC application
I am working on an MFC application (C ++)
My checkbox has an event handler associated with ON_BN_CLICKED
. It works great when the user checks / unchecks the checkbox i.e. The event handler is called.
However, when I programmatically inspect the window: no ((CButton *)this->GetDlgItem(x))-> ->SetCheck(1);
event handler is called.
What can I do to call a programmatic event handler?
source to share
This is normal behavior. WM_COMMAND is dispatched when a "click" or "custom post" button has changed the button.
This does not conflict with the child controls. Other child controls, such as the edit control, also send a WM_COMMAND EN_CHANGE message when the SetWindowText program is executed by the program (MFC blocks this message in DoDataExchange).
source to share
Try sending BN_CLICKED :
this->SendMessage(WM_COMMAND,
MAKELONG(IDC_BUTTON1, BN_CLICKED),
((CButton *)this->GetDlgItem(x))->GetSafeHwnd());
source to share