checking and unchecking menu items
-
Hi all, I posted yesterday morning to try and get my menu item to be checked and unchecked as one of my dialogs is displayed via the menu item. I kinda need this to be accomplished soon, so i figured i could post it again because the original post is 5 or 6 pages into the message board. Beer26 was kind enough to help me with this solution.
in the new dialog class add this function. Now the new dialogs will control that menu item in it's parent.
void MyClass::checkmymenuitem(int checked)
{
CMenu* pMainMenu = GetParent()->GetMenu();
CMenu *submenu = pMainMenu->GetSubMenu(1); // replace 1 by the horizontal menu position
UINT g = submenu->GetMenuItemID(3); // replace 3 by the actual vertical item position
CString mnustr;
submenu->GetMenuString(3, mnustr, MF_BYPOSITION); // replace 3 by the actual vertical item position
// you can optionally change mnustr to a text here
if (checked) submenu->ModifyMenu(3, MF_BYPOSITION | MF_STRING | MF_CHECKED, g, mnustr);
else submenu->ModifyMenu(3, MF_BYPOSITION | MF_STRING | MF_UNCHECKED, g, mnustr);
}in initdialog
checkmymenuitem(true);
then in onclose
checkmymenuitem(false);
It works fine the first time the app is started(menu item unchecked), when the menu item is selected the first time (checked), and when the dialog is closed the first time(unchecked). BUT it doesn't update the menu at all after the first time it is selected and the dialog is closed. Can anyone help me figure this out PLEASE. I was originally trying to use a pointer to the dialog being displayed, but that led to the same result.
-
Hi all, I posted yesterday morning to try and get my menu item to be checked and unchecked as one of my dialogs is displayed via the menu item. I kinda need this to be accomplished soon, so i figured i could post it again because the original post is 5 or 6 pages into the message board. Beer26 was kind enough to help me with this solution.
in the new dialog class add this function. Now the new dialogs will control that menu item in it's parent.
void MyClass::checkmymenuitem(int checked)
{
CMenu* pMainMenu = GetParent()->GetMenu();
CMenu *submenu = pMainMenu->GetSubMenu(1); // replace 1 by the horizontal menu position
UINT g = submenu->GetMenuItemID(3); // replace 3 by the actual vertical item position
CString mnustr;
submenu->GetMenuString(3, mnustr, MF_BYPOSITION); // replace 3 by the actual vertical item position
// you can optionally change mnustr to a text here
if (checked) submenu->ModifyMenu(3, MF_BYPOSITION | MF_STRING | MF_CHECKED, g, mnustr);
else submenu->ModifyMenu(3, MF_BYPOSITION | MF_STRING | MF_UNCHECKED, g, mnustr);
}in initdialog
checkmymenuitem(true);
then in onclose
checkmymenuitem(false);
It works fine the first time the app is started(menu item unchecked), when the menu item is selected the first time (checked), and when the dialog is closed the first time(unchecked). BUT it doesn't update the menu at all after the first time it is selected and the dialog is closed. Can anyone help me figure this out PLEASE. I was originally trying to use a pointer to the dialog being displayed, but that led to the same result.
(haven't looked at the original question) can't you simply add a ON_UPDATE_COMMAND_UI command handler for the menu item ? and use :
void MyClass::OnUpdateYourMenuItem( CCmdUI* pCmdUI )
{
pCmdUI ->SetCheck( IsYourDialogVisible() );
}
Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
-
(haven't looked at the original question) can't you simply add a ON_UPDATE_COMMAND_UI command handler for the menu item ? and use :
void MyClass::OnUpdateYourMenuItem( CCmdUI* pCmdUI )
{
pCmdUI ->SetCheck( IsYourDialogVisible() );
}
Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
I think he said his main app was dialog based, and as we all know the VC++6 generator has that bug that makes updating UI on menu items not work on dialog based apps. I forgot what the fix was for that but you can look it up on codeguru.com
-
I think he said his main app was dialog based, and as we all know the VC++6 generator has that bug that makes updating UI on menu items not work on dialog based apps. I forgot what the fix was for that but you can look it up on codeguru.com