The bad behaviour was caused by a not-yet fully understood modification in another CDockablePane that messed up the focus; it causes the button to loose the focus and I did not visually see that when I thought I clicked on the button, I was putting the focus back to it; and if I was lucky enough to click fast enough on the button before it loosed focus again.
We reverted the small changes that cause that more important problem.
I've got a simple MFC application with menus, and a menu item and a CDockablePane containing a CButton.
The application creates a worker thread ( by doing a
Both menu item and the button will call the same code; the code will stop the thread.
When running the application, the thread is created and is doing its job, when the menu item is selected, the handler is called and the code stopping the thread works normally.
When I try clicking on the button (the button is enabled) nothing happen, the handler is not called, or I have to click like demented person and eventually the handler will be called.
ON_BN_CLICKED(IDC_STOP_BUTTON, &MyWindow::OnButtonStop )
The button is created in a window (CWnd) inside the CDockablePane.
The button is enabled/disabled by using ON_UPDATE_COMMAND_UI (as explained in Applying an update UI notification interface to user-defined controls
]) with the WM_IDLEUPDATECMDUI message to call
I don't know if there is a way or if there is a message that will give that particular UI a "nudge" to handle the button message with a higher priority.