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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to UPDATE_COMMAND_UI in Dialog App?

How to UPDATE_COMMAND_UI in Dialog App?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionannouncement
9 Posts 4 Posters 0 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.
  • W Offline
    W Offline
    work_to_live
    wrote on last edited by
    #1

    I added a menu to a dialog application, and can't seem to get the UPDATE_COMMAND_UI behavior to work. If I break on my OnUpdate... handler, it's called after the menu item has been selected, not before. I've been poking around on Code Project, and I'm starting to get the "impression" that it might not be possible. Is that true, or is there a way to update a menu item in a dialog app?

    V M B 3 Replies Last reply
    0
    • W work_to_live

      I added a menu to a dialog application, and can't seem to get the UPDATE_COMMAND_UI behavior to work. If I break on my OnUpdate... handler, it's called after the menu item has been selected, not before. I've been poking around on Code Project, and I'm starting to get the "impression" that it might not be possible. Is that true, or is there a way to update a menu item in a dialog app?

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      One solution is to implement OnInitMenuPopup(). ----- void CDlgApp::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) { // Enables this dialog based app to handle ON_UPDATE_COMMAND_UI messages. // For updating items in menu. CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); CCmdUI cmdUI; cmdUI.m_pMenu = pPopupMenu; cmdUI.m_nIndexMax = pPopupMenu->GetMenuItemCount(); for (cmdUI.m_nIndex = 0; cmdUI.m_nIndex < cmdUI.m_nIndexMax; cmdUI.m_nIndex++) { cmdUI.m_nID = pPopupMenu->GetMenuItemID(cmdUI.m_nIndex); if (cmdUI.m_nID == 0) continue; cmdUI.DoUpdate(this, FALSE); } } ----- Kuphryn

      W 2 Replies Last reply
      0
      • V valikac

        One solution is to implement OnInitMenuPopup(). ----- void CDlgApp::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) { // Enables this dialog based app to handle ON_UPDATE_COMMAND_UI messages. // For updating items in menu. CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); CCmdUI cmdUI; cmdUI.m_pMenu = pPopupMenu; cmdUI.m_nIndexMax = pPopupMenu->GetMenuItemCount(); for (cmdUI.m_nIndex = 0; cmdUI.m_nIndex < cmdUI.m_nIndexMax; cmdUI.m_nIndex++) { cmdUI.m_nID = pPopupMenu->GetMenuItemID(cmdUI.m_nIndex); if (cmdUI.m_nID == 0) continue; cmdUI.DoUpdate(this, FALSE); } } ----- Kuphryn

        W Offline
        W Offline
        work_to_live
        wrote on last edited by
        #3

        Thanks, I'll give it a try.

        1 Reply Last reply
        0
        • V valikac

          One solution is to implement OnInitMenuPopup(). ----- void CDlgApp::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) { // Enables this dialog based app to handle ON_UPDATE_COMMAND_UI messages. // For updating items in menu. CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); CCmdUI cmdUI; cmdUI.m_pMenu = pPopupMenu; cmdUI.m_nIndexMax = pPopupMenu->GetMenuItemCount(); for (cmdUI.m_nIndex = 0; cmdUI.m_nIndex < cmdUI.m_nIndexMax; cmdUI.m_nIndex++) { cmdUI.m_nID = pPopupMenu->GetMenuItemID(cmdUI.m_nIndex); if (cmdUI.m_nID == 0) continue; cmdUI.DoUpdate(this, FALSE); } } ----- Kuphryn

          W Offline
          W Offline
          work_to_live
          wrote on last edited by
          #4

          I get an Access Violation when executing pPopupMenu->GetMenuItemCount() in your example. Here's where it occurs... _AFXWIN_INLINE UINT CMenu::GetMenuItemCount() const { ASSERT(::IsMenu(m_hMenu)); return ::GetMenuItemCount(m_hMenu); }

          W 1 Reply Last reply
          0
          • W work_to_live

            I get an Access Violation when executing pPopupMenu->GetMenuItemCount() in your example. Here's where it occurs... _AFXWIN_INLINE UINT CMenu::GetMenuItemCount() const { ASSERT(::IsMenu(m_hMenu)); return ::GetMenuItemCount(m_hMenu); }

            W Offline
            W Offline
            work_to_live
            wrote on last edited by
            #5

            It looks like pPopupMenu is not setup properly prior to the call to OnInitMenuPopup. I tried executing the following command... pPopupMenu->GetMenuState(0,MF_BYPOSITION); and it also results in an access violation. Oh Well. An Ideas?

            1 Reply Last reply
            0
            • W work_to_live

              I added a menu to a dialog application, and can't seem to get the UPDATE_COMMAND_UI behavior to work. If I break on my OnUpdate... handler, it's called after the menu item has been selected, not before. I've been poking around on Code Project, and I'm starting to get the "impression" that it might not be possible. Is that true, or is there a way to update a menu item in a dialog app?

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #6

              Add a handler for WM_KICKIDLE. In the handler, call UpdateDialogControls(this, false); You'll need to #include <afxpriv.h> for the definition of WM_KICKIDLE --Mike-- Yeah, payin' the bills with my mad programming skillz. Defraggin' my hard drive for thrills. Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me

              W 1 Reply Last reply
              0
              • M Michael Dunn

                Add a handler for WM_KICKIDLE. In the handler, call UpdateDialogControls(this, false); You'll need to #include <afxpriv.h> for the definition of WM_KICKIDLE --Mike-- Yeah, payin' the bills with my mad programming skillz. Defraggin' my hard drive for thrills. Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me

                W Offline
                W Offline
                work_to_live
                wrote on last edited by
                #7

                Seems like a losing battle... The ON_UPDATE_COMMAND_UI message handler is still never called. Oh well.

                1 Reply Last reply
                0
                • W work_to_live

                  I added a menu to a dialog application, and can't seem to get the UPDATE_COMMAND_UI behavior to work. If I break on my OnUpdate... handler, it's called after the menu item has been selected, not before. I've been poking around on Code Project, and I'm starting to get the "impression" that it might not be possible. Is that true, or is there a way to update a menu item in a dialog app?

                  B Offline
                  B Offline
                  Baris Kurtlutepe
                  wrote on last edited by
                  #8

                  Look for 'Q242577' in MSDN, there is an example 80 lines of code overriding the OnInitMenuPopup function and it worked for me.

                  W 1 Reply Last reply
                  0
                  • B Baris Kurtlutepe

                    Look for 'Q242577' in MSDN, there is an example 80 lines of code overriding the OnInitMenuPopup function and it worked for me.

                    W Offline
                    W Offline
                    work_to_live
                    wrote on last edited by
                    #9

                    Hey! That did the trick, thanks.

                    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