Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » change menu item bitmap at runtime Collapse All
Subject Author Date
Chris Anderson Aug 20, 2007 - 8:15 PM

hi there,

We have a legacy app which allows the user to set the text and select a bitmap for a menu item at run time. I tried several "short cuts" but not very lucky so far.

What I did is :
1. use the legacy code to create a menu, and attach it in CExtMenuControlBar later.

// create the menu
AppendMenu(hMenu, MF_String, uMenuID, lpText);
SetMenuItemBitmaps(pMainMenu->m_hMenu, g_uMenuID, MF_BYCOMMAND, hBmp, hBmp);

// later attach the menu
m_wndMenuBar.m_menuFrame.Attach( hMenu );

2. similiar to #1, but update the menu after the attach
CMenu* pSubMenu = pMenu->GetSubMenu(nIndex);
UINT nMenuID = pSubMenu->GetMenuItemID(nIndex);

pSubMenu->SetMenuItemBitmaps(...)

Both works with the text very well, but the image never show up. From another thread, looks like it should be done in CMainFrame::OnExtMenuPrepare(), but this is something I tried to avoid considering the amount of work. could you pls confirm?

Thanks in advance

Chris Anderson Aug 21, 2007 - 11:33 AM

Thanks, this works really well without too many changes

Technical Support Aug 21, 2007 - 6:56 AM

Bitmaps are supported by Windows menu items starting from Windows 2000. Prof-UIS supports Windows versions starting from 95 and NT 4.0. We are using older menu APIs to provide wider compatibility. Of course, we could add a menu bitmap exporting feature for you, but the task of assigning a menu icon can also be easily solved using the command manager which contains command descriptions including icons. The CExtCmdManager::CmdSetIcon() method (g_CmdManager->CmdSetIcon(...) code) assigns an icon to the specified command identifier and this icon will automatically be used for this command both in toolbars and menus. You should only preliminary register all the menu commands in the command manager. This can be done with the CExtCmdManager::UpdateFromMenu() method.