MFC How do you determine if ON_UPDATE_COMMAND_UI is for the menubar or toolbar?

293 Views Asked by At

I have a case where I want the menus to set the check on items using ON_UPDATE_COMMAND_UI; however, on the toolbar I'm going to use a dropdown toolbar, so I only want to select the correct toolbar item and not change its checked state.

How do I determine if the ON_UPDATE_COMMAND_UI call is for the menu-bar or the toolbar?

1

There are 1 best solutions below

0
Adrian Mole On

You can check the m_pMenu member of the handler's given CCmdUI parameter; if the routine was invoked for a menu item, that will be a valid CMenu* pointer; if not, it will be NULL:

void CMyClass::OnUpdateHandler(CCmdUI *pCmdUI)
{
   if (!pCmdUI->m_pMenu) {
       // NOT for a menu
   }
   else {
       // For a menu
   }
}