How to use CheckMenuItem()????????
-
Hi I would like to palce a check mark for menu item, if user clicks a menu item. I would like to do this from CMainFrm class.Can u please give me an idea? Thanks JP ;P
You have to have a function that would execute the code when the users selects the menu item. Let's say it's ON_COMMAND(ID_YOURMENUITEM, TestFn) Maybe you want to use a global variable that will tell you the state of that item. bool testVar; void TestFn() { CMenu *m_MainMenu; // let's say you have your menu in m_MainMenu if (testVar) { testVar = false; m_MainMenu->GetSubMenu(1)->GetSubMenu(x)->CheckMenuItem(n, MF_BYPOSITION | MF_UNCHECKED); } else { testVar = true; m_MainMenu->GetSubMenu(1)->GetSubMenu(x)->CheckMenuItem(n, MF_BYPOSITION | MF_CHECKED); } } where n is the position of your item in the menu ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.
-
You have to have a function that would execute the code when the users selects the menu item. Let's say it's ON_COMMAND(ID_YOURMENUITEM, TestFn) Maybe you want to use a global variable that will tell you the state of that item. bool testVar; void TestFn() { CMenu *m_MainMenu; // let's say you have your menu in m_MainMenu if (testVar) { testVar = false; m_MainMenu->GetSubMenu(1)->GetSubMenu(x)->CheckMenuItem(n, MF_BYPOSITION | MF_UNCHECKED); } else { testVar = true; m_MainMenu->GetSubMenu(1)->GetSubMenu(x)->CheckMenuItem(n, MF_BYPOSITION | MF_CHECKED); } } where n is the position of your item in the menu ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.
-
Hey In above example, m_MainMenu is unreferenced..so that code is not working. How to attach my Mainmeu to this? Thanks JP
I told you that m_MainMenu is your menu. You will have to replace it with your variable. If it's the apps menu then you have to do something like this m_MainMenu = GetMenu(); ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.
-
Hi I would like to palce a check mark for menu item, if user clicks a menu item. I would like to do this from CMainFrm class.Can u please give me an idea? Thanks JP ;P
Use the ON_UPDATE_COMMAND_UI message if possible.
...
ON_UPDATE_COMMAND_UI(IDM_YOUR_MENU_ITEM, OnUpdateYourMenuItem)
...void CMainFrm::OnUpdateYourMenuItem(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck( IsMenuItemCheck() );
}
Maximilien Lincourt Your Head A Splode - Strong Bad
-
I told you that m_MainMenu is your menu. You will have to replace it with your variable. If it's the apps menu then you have to do something like this m_MainMenu = GetMenu(); ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.