Menu not showing checked symbol 
Author Message
 Menu not showing checked symbol

Hi,

I'm dynamically creating a submenu to an item in the main menu (SDI
application) by using CMenu::ModifyMenu with the MF_POPUP switch. I
want to be able to check and uncheck various items in this submenu.
I've written the ON_UPDATE_COMMAND_UI handler for the items and have
used CCmdUI::SetCheck to check and uncheck the menu items. This all
appears to work fine, the update handler is called when the submenu is
displayed and SetCheck appears to be using CheckMenuItem (in
cmdtarg.cpp) to (un)check the items.

My problem is that the appearance of the menu item DOESN'T change. No
check symbols ever appear next to the items in the submenu.

The same code works fine for when the menu is not created dynamically
i.e. the submenu appears exactly the same as it does in the resource.
The update handler sets the check next to the item and the symbol
appears correctly on the menu. Weird!

I don't understand what I'm doing wrong.

I hope someone can help. Thanks.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 22 Jul 2002 03:00:00 GMT  
 Menu not showing checked symbol
You need to declare the submenu as CMenu member variable of the
CView/CFrameWnd and insert it into the main menu (I was using a local
var). Something like this in OnInitialUpdate():

  //CMenu subMenu; //don't use this
  m_SubMenu.CreatePopupMenu(); //uses member var now
  HMENU hm = m_SubMenu.GetSafeHmenu();
  CMenu* apopup = MainMenu->GetSubMenu(3);

  if (BuildMenu(m_SubMenu)) {
    apopup->InsertMenu(2, MF_BYPOSITION | MF_POPUP | MF_STRING |
MF_ENABLED, reinterpret_cast<UINT>(hm), "&Subby");

This makes no sense whatsoever to me but it seems to work! In the
update handler I can now call SetCheck() and the check symbol appears
next to the menu item. If anyone can enlighten me as to why this is so
I would appreciate it. I hope this prevents someone else from wasting
their time!



Quote:
> Hi,

> I'm dynamically creating a submenu to an item in the main menu (SDI
> application) by using CMenu::ModifyMenu with the MF_POPUP switch. I
> want to be able to check and uncheck various items in this submenu.
> I've written the ON_UPDATE_COMMAND_UI handler for the items and have
> used CCmdUI::SetCheck to check and uncheck the menu items. This all
> appears to work fine, the update handler is called when the submenu is
> displayed and SetCheck appears to be using CheckMenuItem (in
> cmdtarg.cpp) to (un)check the items.

> My problem is that the appearance of the menu item DOESN'T change. No
> check symbols ever appear next to the items in the submenu.

> The same code works fine for when the menu is not created dynamically
> i.e. the submenu appears exactly the same as it does in the resource.
> The update handler sets the check next to the item and the symbol
> appears correctly on the menu. Weird!

> I don't understand what I'm doing wrong.

> I hope someone can help. Thanks.

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Mon, 22 Jul 2002 03:00:00 GMT  
 Menu not showing checked symbol
Dave,

Dynamically created menu do not respond to ON_UPDATE_COMMAND_UI handlers. I
assume you are using AppendMenu, ModifyMenu, or InsertMenu to dynamically
create this menu. Each of these has a flags parameter. You will need to OR
in either MF_CHECKED or MF_UNCHECKED (as the situation dictates) to the
flags parameter of each of these calls.

for example...

       menu.AppendMenu(MF_STRING | MF_CHECKED, ID_DO_THIS, "Do This");

Dave Smith
MCSE, MCT, MVP


Quote:
> Hi,

> I'm dynamically creating a submenu to an item in the main menu (SDI
> application) by using CMenu::ModifyMenu with the MF_POPUP switch. I
> want to be able to check and uncheck various items in this submenu.
> I've written the ON_UPDATE_COMMAND_UI handler for the items and have
> used CCmdUI::SetCheck to check and uncheck the menu items. This all
> appears to work fine, the update handler is called when the submenu is
> displayed and SetCheck appears to be using CheckMenuItem (in
> cmdtarg.cpp) to (un)check the items.

> My problem is that the appearance of the menu item DOESN'T change. No
> check symbols ever appear next to the items in the submenu.

> The same code works fine for when the menu is not created dynamically
> i.e. the submenu appears exactly the same as it does in the resource.
> The update handler sets the check next to the item and the symbol
> appears correctly on the menu. Weird!

> I don't understand what I'm doing wrong.

> I hope someone can help. Thanks.

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Mon, 22 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help - dr watson is not showing my symbols

2. UserControl does not show on running form and properies do not show

3. Newbie: Menu and icons not showing ?

4. Document Menu not showing up in NT 4

5. TrackPopupMenu does not show menu labels

6. Menu not showing up in 98...but it does in Win2k

7. CMultiDocTemplate not showing correct menu?

8. OCX created in VB does not show Menu in CDialog

9. Mnemonic underlines not showing in menu times.

10. Send To Context Menu does not show.

11. shortcut does not show up in start menu right away

12. Window menu not showing all open windows

 

 
Powered by phpBB® Forum Software