ON_COMMAND_UI for Dialog Tutorial/Example
-
I have an MFC Dialog based application. Using other code samples I added a toolbar to my dialog and added support for the tooltips, etc. It works great. I have a couple instances where I need to disable some of the buttons on the toolbar. I figured out a way to do this with using CToolBar::GetToolBarCtrl function and using the SetState function with the indeterminate flag. However, all my reading suggests that the proper way to do this is to use ON_COMMAND_UI for the button I want to disable. Well, ON_COMMAND_UI needs a CFrame to work correctly. For a dialog, the ON_COMMAND_UI handlers you set up for each button on the toolbar is never even called so I can't call the pCmdUI->Enable(false) to disable the item. If you are writing a dialog based app (as I am) your best bet currently appears to be to use WM_KICKIDLE instead. However, that doesn't give me the ON_COMMAND_UI handler I need (the CCmdUI pointer). I could use OnKickIdle and call the OnCommandIUI handlers myself creating and passing a pointer to a CCmdUI object I populate myself but I can't seem to get this to work. Could someone tell me the proper way and demonstrate fully? I've tried so many different things without success and while my hack(?) appears to work, I'd like to do it the proper way. Thanks. Matt Philmon
-
I have an MFC Dialog based application. Using other code samples I added a toolbar to my dialog and added support for the tooltips, etc. It works great. I have a couple instances where I need to disable some of the buttons on the toolbar. I figured out a way to do this with using CToolBar::GetToolBarCtrl function and using the SetState function with the indeterminate flag. However, all my reading suggests that the proper way to do this is to use ON_COMMAND_UI for the button I want to disable. Well, ON_COMMAND_UI needs a CFrame to work correctly. For a dialog, the ON_COMMAND_UI handlers you set up for each button on the toolbar is never even called so I can't call the pCmdUI->Enable(false) to disable the item. If you are writing a dialog based app (as I am) your best bet currently appears to be to use WM_KICKIDLE instead. However, that doesn't give me the ON_COMMAND_UI handler I need (the CCmdUI pointer). I could use OnKickIdle and call the OnCommandIUI handlers myself creating and passing a pointer to a CCmdUI object I populate myself but I can't seem to get this to work. Could someone tell me the proper way and demonstrate fully? I've tried so many different things without success and while my hack(?) appears to work, I'd like to do it the proper way. Thanks. Matt Philmon
Your OnKickIdle() handler should call UpdateDialogControls(this, FALSE); which will call the UPDATE_COMMAND_UI handlers for you. --Mike-- http://home.inreach.com/mdunn/ The preferred snack of 4 out of 5 Lounge readers.
-
Your OnKickIdle() handler should call UpdateDialogControls(this, FALSE); which will call the UPDATE_COMMAND_UI handlers for you. --Mike-- http://home.inreach.com/mdunn/ The preferred snack of 4 out of 5 Lounge readers.
True enough... but not for Toolbar buttons. UpdateDialogControls will get UPDATE_COMMAND_UI working for standard controls(buttons, text boxes, whatever) but not for a toolbar button. I'm not EXACTLY sure for the reason. Maybe it's because toolbars aren't exactly intended to Dialog base apps.