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