check and uncheck menu items in a pop-up window
James Shao -- jshao@pluto.dspt.com Friday, October 11, 1996 Environment: Visual C++ 4.2, Win95 In my project, in addition to the main frame window, we also need to have several pop-up windows with their own menu. For this purpose, I created a new class CMsgWnd which is derived from CWnd class. To have the window displayed, I first Create a new CMsgWnd object and attach a menu to it (I used CreateEx(...LoadMenu()) command) and them use ShowWindow to display it. I can click any menu item to perform the corresponding task. The problem is that I cannot set check and uncheck to the menu items and I cannot enable or disable the menu items on calling the ON_UPDATE_COMMAND_UI command as I did for the mainframe window menu items. The following is the sample code to try to set the check or uncheck a menu item: in the message map (in CMsgWnd class), I have ON_UPDATE_COMMAND_UI(ID_QUIET, OnUpdateQuiet) The code is: void CMsgWnd::OnUpdateQuiet(CCmdUI* pCmdUI) { if (!quiet) pCmdUI->SetCheck(0); else pCmdUI->SetCheck(1); } where quiet is a BOOl variable. No matter what the quiet value is, the menu item always keep the same initial check/uncheck status. If the menu item is in the MainFrame window, the same code works fine. What is the problem? James Shao DSP Technology
ganeshs@nationwide.com Monday, October 14, 1996 [Mini-digest: 2 responses] Environment: Visual C++ 4.2, Win95 > In my project, in addition to the main frame window, we also need to have > several pop-up windows with their own menu. > > For this purpose, I created a new class CMsgWnd which is derived from > CWnd class. > > To have the window displayed, I first Create a new CMsgWnd object and > attach a menu to it (I used CreateEx(...LoadMenu()) command) and them use > ShowWindow to display it. I can click any menu item to perform the > corresponding task. The problem is that I cannot set check and uncheck to > the menu items and I cannot enable or disable the menu items on calling the > ON_UPDATE_COMMAND_UI command as I did for the mainframe window menu items. > > The following is the sample code to try to set the check or uncheck a > menu item: > > in the message map (in CMsgWnd class), I have > > ON_UPDATE_COMMAND_UI(ID_QUIET, OnUpdateQuiet) > > The code is: > > void CMsgWnd::OnUpdateQuiet(CCmdUI* pCmdUI) > { > |if (!quiet) > ||pCmdUI->SetCheck(0); > |else > ||pCmdUI->SetCheck(1); > } > > where quiet is a BOOl variable. > > No matter what the quiet value is, the menu item always keep the same > initial check/uncheck status. > > If the menu item is in the MainFrame window, the same code works fine. > >What is the problem? CFrameWnd's (and hence, it's derivatives) handler for WM_INITMENUPOPUP makes the calls to update handlers. Derive your class from CFrameWnd instead of CWnd, and things will work as expected. If you _have_ to derive from CWnd (for whatever reason) on the other hand, you would need the logic for calling the update handlers duplicated in your CWnd-derived class... / ___| / ___| __ _ _ __ ___ ___| | I do not speak for \___ \ | | _ / _` | '_ \ / _ \/ __| '_ \ Tata Unisys or ___) | | |_| | (_| | | | | __/\__ \ | | |Nationwide Ins. |____(_) \____|\__,_|_| |_|\___||___/_| |_|------------------ -----From: Joseph JonesAre you sure that the menu messages for the menu comamnds are going to your CMsgWnd dervied class and not tou your MainFrame Window first? joe
| Вернуться в корень Архива |