i can disable menu item but cannot gray it!!!!!!!!
-
Hi, I have a dialog based app, want to disable and gray a sub menu item and I cannot gray it. I tried to find a solution to this problem but could not. Neither of the following work. :mad: What happens is I see Item 3 in black, press it, and nothing happens. I could have done it by modifying the code that is called when Item 3 is pressed. Why would I bother with OnUpdate? What's the use of it? I got no idea! :confused: I will be very happy if someone can help me. Thanks...
// The menu looks like: // File Settings // Item1 Item2 // Item3
void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
{
if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
{
UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;
if(pCmdUI->m_pMenu!=NULL)
pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex /*ID_SETTINGS_ITEM3*/, MF_BYPOSITION|fGray);
}
pCmdUI->Enable(Item3Enable);
}void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
{
if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
{
UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;CMenu \*hMenu; hMenu = AfxGetMainWnd()->GetMenu(); CMenu \*sub; sub = hMenu->GetSubMenu(1); sub->EnableMenuItem(ID\_SETTINGS\_ITEM3, MF\_BYPOSITION|fGray); }
}
pCmdUI->Enable(Item3Enable);
} -
Hi, I have a dialog based app, want to disable and gray a sub menu item and I cannot gray it. I tried to find a solution to this problem but could not. Neither of the following work. :mad: What happens is I see Item 3 in black, press it, and nothing happens. I could have done it by modifying the code that is called when Item 3 is pressed. Why would I bother with OnUpdate? What's the use of it? I got no idea! :confused: I will be very happy if someone can help me. Thanks...
// The menu looks like: // File Settings // Item1 Item2 // Item3
void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
{
if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
{
UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;
if(pCmdUI->m_pMenu!=NULL)
pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex /*ID_SETTINGS_ITEM3*/, MF_BYPOSITION|fGray);
}
pCmdUI->Enable(Item3Enable);
}void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
{
if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
{
UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;CMenu \*hMenu; hMenu = AfxGetMainWnd()->GetMenu(); CMenu \*sub; sub = hMenu->GetSubMenu(1); sub->EnableMenuItem(ID\_SETTINGS\_ITEM3, MF\_BYPOSITION|fGray); }
}
pCmdUI->Enable(Item3Enable);
}what is
Item3Enable
??? I presume it's a bool that you've set somewhere else in the program.... and you're passing that intopCmdUI->Enable()
at the end of each handler but you are not changing the true/false value ofItem3Enable
so you seem to be enabling the menu item at the end of each handler. Regards, Brian Dela :-) http://www.briandela.com IE 6 required.
http://www.briandela.com/pictures Now with a pictures section :-D
http://www.briandela.com/rss/newsrss.xml RSS Feed -
what is
Item3Enable
??? I presume it's a bool that you've set somewhere else in the program.... and you're passing that intopCmdUI->Enable()
at the end of each handler but you are not changing the true/false value ofItem3Enable
so you seem to be enabling the menu item at the end of each handler. Regards, Brian Dela :-) http://www.briandela.com IE 6 required.
http://www.briandela.com/pictures Now with a pictures section :-D
http://www.briandela.com/rss/newsrss.xml RSS Feed -
Hi, I have a dialog based app, want to disable and gray a sub menu item and I cannot gray it. I tried to find a solution to this problem but could not. Neither of the following work. :mad: What happens is I see Item 3 in black, press it, and nothing happens. I could have done it by modifying the code that is called when Item 3 is pressed. Why would I bother with OnUpdate? What's the use of it? I got no idea! :confused: I will be very happy if someone can help me. Thanks...
// The menu looks like: // File Settings // Item1 Item2 // Item3
void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
{
if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
{
UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;
if(pCmdUI->m_pMenu!=NULL)
pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex /*ID_SETTINGS_ITEM3*/, MF_BYPOSITION|fGray);
}
pCmdUI->Enable(Item3Enable);
}void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
{
if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
{
UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;CMenu \*hMenu; hMenu = AfxGetMainWnd()->GetMenu(); CMenu \*sub; sub = hMenu->GetSubMenu(1); sub->EnableMenuItem(ID\_SETTINGS\_ITEM3, MF\_BYPOSITION|fGray); }
}
pCmdUI->Enable(Item3Enable);
}Just do: pCmdUI->Enable(FALSE); when pCmdUI->m_nID is ID_SETTINGS_ITEM3 that is, simply you can do: pCmdUI->Enable(pCmdUI->m_nID != ID_SETTINGS_ITEM3); Jaime
-
Just do: pCmdUI->Enable(FALSE); when pCmdUI->m_nID is ID_SETTINGS_ITEM3 that is, simply you can do: pCmdUI->Enable(pCmdUI->m_nID != ID_SETTINGS_ITEM3); Jaime
I have already set it to false, item 3 becomes disabled, but not gray!! besides I do not want to have it always disabled, therefore I have put the variable Item3Enable, which I set to true or false in another function outside. I must be able to point to item 3 somehow and disable it but pCmdUI->m_pMenu is always NULL. I cannot manage to disable item 3 with GetMenu() and GetSubMenu() either, although I know it is possible to check and uncheck a menu item on a COMMAND message mapped to it using GetMenu() and GetsubMenu(). Does not anyone know why this doesn't work?
-
I have already set it to false, item 3 becomes disabled, but not gray!! besides I do not want to have it always disabled, therefore I have put the variable Item3Enable, which I set to true or false in another function outside. I must be able to point to item 3 somehow and disable it but pCmdUI->m_pMenu is always NULL. I cannot manage to disable item 3 with GetMenu() and GetSubMenu() either, although I know it is possible to check and uncheck a menu item on a COMMAND message mapped to it using GetMenu() and GetsubMenu(). Does not anyone know why this doesn't work?
Have you tried to put pCmdUI->Enable(FALSE) as the only instruction in the update handler? If that way the menu option is grayed, the problem is the condition you have. By the way, if that update handler is called only for item 3, you don't need that verification. Finally, I tell you that I use my own application to place pCmdUI->Enable(FALSE) for a specific menu item and it worked (disabled and grayed) so the problem may be in your condition. Jaime
-
Have you tried to put pCmdUI->Enable(FALSE) as the only instruction in the update handler? If that way the menu option is grayed, the problem is the condition you have. By the way, if that update handler is called only for item 3, you don't need that verification. Finally, I tell you that I use my own application to place pCmdUI->Enable(FALSE) for a specific menu item and it worked (disabled and grayed) so the problem may be in your condition. Jaime
Yes, it was only one line pCmdUI->Enable(true/false) before I encluntered the problem of non-grayed disabling. I put the other code to be able to gray it. actually I found it in some documents on internet, but none of the examples I saw directly match the situation I have. You're right about the verification being unncessary, i did that to be sure.
-
Yes, it was only one line pCmdUI->Enable(true/false) before I encluntered the problem of non-grayed disabling. I put the other code to be able to gray it. actually I found it in some documents on internet, but none of the examples I saw directly match the situation I have. You're right about the verification being unncessary, i did that to be sure.
I can guess that you have in other part of your program a code to "ungray" the item. Check that. Other fact to check. Are other menu items grayed that you see grayed? maybe is only a display problem. Jaime
-
Hi, I have a dialog based app, want to disable and gray a sub menu item and I cannot gray it. I tried to find a solution to this problem but could not. Neither of the following work. :mad: What happens is I see Item 3 in black, press it, and nothing happens. I could have done it by modifying the code that is called when Item 3 is pressed. Why would I bother with OnUpdate? What's the use of it? I got no idea! :confused: I will be very happy if someone can help me. Thanks...
// The menu looks like: // File Settings // Item1 Item2 // Item3
void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
{
if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
{
UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;
if(pCmdUI->m_pMenu!=NULL)
pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex /*ID_SETTINGS_ITEM3*/, MF_BYPOSITION|fGray);
}
pCmdUI->Enable(Item3Enable);
}void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
{
if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
{
UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;CMenu \*hMenu; hMenu = AfxGetMainWnd()->GetMenu(); CMenu \*sub; sub = hMenu->GetSubMenu(1); sub->EnableMenuItem(ID\_SETTINGS\_ITEM3, MF\_BYPOSITION|fGray); }
}
pCmdUI->Enable(Item3Enable);
}I solved the problem and I'm very happy for that!! :-D ok.. forget the function mapped to UPDATE_COMMAND_UI - delete it! Somewhere outside do this to switch between enabled and disabled menu items - nothing else
//enable-disable switch // Item3Enable is the bool value to decide if it will be enabled or disabled Item3Enable = !Item3Enable; UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED; CMenu *hMenu; hMenu = GetMenu(); CMenu *sub; sub = hMenu->GetSubMenu(1); sub->EnableMenuItem(ID_SETTINGS_ITEM3, MF_BYCOMMAND|fGray);