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. argh, dialog resource menu enabling/graying

argh, dialog resource menu enabling/graying

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++questionlearning
4 Posts 3 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.
  • K Offline
    K Offline
    Kuniva
    wrote on last edited by
    #1

    Hi, i've posted a message about this before and i got an answer but it wasn't what i needed. You see i need to know how i can enable/gray menuitems in a dialogs menu in MFC. The menu is pure resource, there isn't any code to add the menu to the dialog, i just clicked properties of the dialog and there is an option to select a menu resource for that dialog. Now my last answer was: use OnUpdateCommandUI i did this and then u get a pointer to the menuitem and then u can do something like this: pCmdUI->Enable(0); but thats just not what i need! the menuitem is disabled, i cant click it anymore but its not gray!!!! so u dont know its not working, i've also tried using ->SetText("blablabla") but that doesn't seem to have any effect whatsoever. Can someone please explain this all to me, and show me how to do it right? or give me a tutorial or something i can look at? Cause all the pages about menus on codeguru and the codeproject seem to be dealing with more advanced problems. Many thanks. Kuniva

    C M 2 Replies Last reply
    0
    • K Kuniva

      Hi, i've posted a message about this before and i got an answer but it wasn't what i needed. You see i need to know how i can enable/gray menuitems in a dialogs menu in MFC. The menu is pure resource, there isn't any code to add the menu to the dialog, i just clicked properties of the dialog and there is an option to select a menu resource for that dialog. Now my last answer was: use OnUpdateCommandUI i did this and then u get a pointer to the menuitem and then u can do something like this: pCmdUI->Enable(0); but thats just not what i need! the menuitem is disabled, i cant click it anymore but its not gray!!!! so u dont know its not working, i've also tried using ->SetText("blablabla") but that doesn't seem to have any effect whatsoever. Can someone please explain this all to me, and show me how to do it right? or give me a tutorial or something i can look at? Cause all the pages about menus on codeguru and the codeproject seem to be dealing with more advanced problems. Many thanks. Kuniva

      C Offline
      C Offline
      Crercio O Silva
      wrote on last edited by
      #2
      1. Add a handle to your dialog.h like this: afx_msg LRESULT OnKickIdle(WPARAM, LPARAM); 2) Includes in the dialog.cpp (for WM_KICKIDLE) message 3) Insert this code into the MESSAGE_MAP ON_MESSAGE(WM_KICKIDLE, OnKickIdle) 4) Create the function OnKickIdle like this LRESULT ServerProperties::OnKickIdle(WPARAM, LPARAM) { CMenu* pMainMenu = GetMenu(); CCmdUI cmdUI; UINT n; for (n = 0; n < pMainMenu->GetMenuItemCount(); ++n) { CMenu* pSubMenu = pMainMenu->GetSubMenu(n); cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount(); for (UINT i = 0; i < cmdUI.m_nIndexMax;++i) { cmdUI.m_nIndex = i; cmdUI.m_nID = pSubMenu->GetMenuItemID(i); cmdUI.m_pMenu = pSubMenu; cmdUI.DoUpdate(this, FALSE); } } return TRUE; } 5) Add the handles to OnUpdateCmdUI to menu items. 6) Relax, compile it e enjoy. :cool: PS: That will work only for menus, there is a different way to handle toolbar. []s
      1 Reply Last reply
      0
      • K Kuniva

        Hi, i've posted a message about this before and i got an answer but it wasn't what i needed. You see i need to know how i can enable/gray menuitems in a dialogs menu in MFC. The menu is pure resource, there isn't any code to add the menu to the dialog, i just clicked properties of the dialog and there is an option to select a menu resource for that dialog. Now my last answer was: use OnUpdateCommandUI i did this and then u get a pointer to the menuitem and then u can do something like this: pCmdUI->Enable(0); but thats just not what i need! the menuitem is disabled, i cant click it anymore but its not gray!!!! so u dont know its not working, i've also tried using ->SetText("blablabla") but that doesn't seem to have any effect whatsoever. Can someone please explain this all to me, and show me how to do it right? or give me a tutorial or something i can look at? Cause all the pages about menus on codeguru and the codeproject seem to be dealing with more advanced problems. Many thanks. Kuniva

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

        The problem is that the update command UI system relies on the MFC message WM_KICKIDLE, which is not automatically handled by dialogs (it is handled by frame windows). The previous post has some code, however the OnKickIdle() can be done more simply:

        OnKickIdle(...)
        {
        UpdateDialogControls ( this, FALSE );
        }

        The second parameter controls whether menu items without command handlers will be disabled. Pass TRUE to disable them, or FALSE to leave them alone. --Mike-- http://home.inreach.com/mdunn/ This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use. :love: your :bob: with :vegemite: and :beer:

        K 1 Reply Last reply
        0
        • M Michael Dunn

          The problem is that the update command UI system relies on the MFC message WM_KICKIDLE, which is not automatically handled by dialogs (it is handled by frame windows). The previous post has some code, however the OnKickIdle() can be done more simply:

          OnKickIdle(...)
          {
          UpdateDialogControls ( this, FALSE );
          }

          The second parameter controls whether menu items without command handlers will be disabled. Pass TRUE to disable them, or FALSE to leave them alone. --Mike-- http://home.inreach.com/mdunn/ This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use. :love: your :bob: with :vegemite: and :beer:

          K Offline
          K Offline
          Kuniva
          wrote on last edited by
          #4

          cool thanks alot guys! Both of you! ;) Kuniva

          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