In Visual Studio, MFC CToolBar buttons are updated by ON_UPDATE_COMMAND_UI
which is sent during idle state. I suppose this mechanism is buggy if I change enable/disable state of the button in ON_UPDATE_COMMAND_UI
handler.
Specifically:
Suppose the button is now in enabled state. At a certain time, the code 'wants' the button to be disabled (and of-course should not be clicked by user), but the button will be really disabled at next idle period, as in following figure:
In red area in the figure, the code state, in my opinion, is unstable and the developer must handle this unstable state by checking the button state manually. I have no idea if I have missed something or have some misunderstanding of this mechanism?
PS: The procedure for Menu is OK. It always calls ON_UPDATE_COMMAND_UI
handler and check the button state before ON_COMMAND
handler.
My question is how to make the ON_UPDATE_COMMAND_UI
handler be called before ON_COMMAND
handler just like Menus do?