Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. help:update_command_ui

help:update_command_ui

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++designannouncement
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    happycpp
    wrote on last edited by
    #1

    hi everyone.. i have a little problem with UPDATE_COMMAND_UI...it seems to work perfectly in non-dialog based programs but when it comes to dialog-based ones the following are noticed: 1-the OnUpdateFileNew function(which is called by the ON_UPDATE_COMMAND_UI) is not called until my menu item is pressed...it should be called before the item is displayed.. 2-the CCmdUI* in the previous function belongs to a weird class called CTestCmdUI which is in wincore.cpp...it should be a pointer to a CCmdUI class in cmdtarg.cpp.... actually i'm new in this update command ui thing so it will be very appreciated to explain more about it to me... thanx..

    J 1 Reply Last reply
    0
    • H happycpp

      hi everyone.. i have a little problem with UPDATE_COMMAND_UI...it seems to work perfectly in non-dialog based programs but when it comes to dialog-based ones the following are noticed: 1-the OnUpdateFileNew function(which is called by the ON_UPDATE_COMMAND_UI) is not called until my menu item is pressed...it should be called before the item is displayed.. 2-the CCmdUI* in the previous function belongs to a weird class called CTestCmdUI which is in wincore.cpp...it should be a pointer to a CCmdUI class in cmdtarg.cpp.... actually i'm new in this update command ui thing so it will be very appreciated to explain more about it to me... thanx..

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      MFC doesn't implement the automatic update of UI elements for dialog based apps. If you want to have this functionality for a menu in a dialog based application you could do something like the following (it wasn't thoroughly tested and makes use of undocumented functions so, as always, use it at your own risk): In you dialog class declaration, add the following member: afx_msg void OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu); In your dialog's cpp file, make the following changes (change "YourDialog" to the actual class name of your dialog too):

      BEGIN_MESSAGE_MAP(YourDialog, CDialog)
         // what you already have
         // [...]
       
         // Add this:
         ON_WM_INITMENUPOPUP()
      END_MESSAGE_MAP()
       
      void AFXAPI AfxCancelModes(HWND hWndRcvr);
       
      void YourDialog::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)
      {
         AfxCancelModes(m_hWnd);
       
         if (bSysMenu)
            return; // don't support system menu
       
         ENSURE_VALID(pMenu);
       
         // check the enabled state of various menu items
       
         CCmdUI state;
         state.m_pMenu = pMenu;
         ASSERT(state.m_pOther == NULL);
         ASSERT(state.m_pParentMenu == NULL);
       
         // determine if menu is popup in top-level menu and set m_pOther to
         // it if so (m_pParentMenu == NULL indicates that it is secondary popup)
         HMENU hParentMenu;
         if (AfxGetThreadState()->m_hTrackingMenu == pMenu->m_hMenu)
            state.m_pParentMenu = pMenu; // parent == child for tracking popup
         else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
         {
            CWnd* pParent = GetTopLevelParent();
               // child windows don't have menus -- need to go to the top!
            if (pParent != NULL &&
               (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
            {
               int nIndexMax = ::GetMenuItemCount(hParentMenu);
               for (int nItemIndex = 0; nItemIndex < nIndexMax; nItemIndex++)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups