Archived

This topic is now archived and is closed to further replies.

Zeblar Nagrim

Adding a bitmap to a Menu item in win32

Recommended Posts

Zeblar Nagrim    150
Why doesn´t this work?
  

....

AddBitmapToMenuItem(IDR_MENU1, ID_FILE_EXIT, IDB_BITMAP5);

...

bool CWndMain::AddBitmapToMenuItem(int p_iResourceIdMenu, int p_iResourceIdMenuItem, int p_iResourceIdIcon)
{
  HINSTANCE l_hInstance = (HINSTANCE) GetWindowLong(m_hWnd, GWL_HINSTANCE);

  HBITMAP l_hBitmap = LoadBitmap(l_hInstance, MAKEINTRESOURCE(p_iResourceIdIcon));

  HMENU l_hMenu = LoadMenu(l_hInstance, MAKEINTRESOURCE(IDR_MENU1));
  
  if(SetMenuItemBitmaps(l_hMenu,p_iResourceIdMenuItem,MF_BYCOMMAND,l_hBitmap,l_hBitmap) == 0)
    return false;

  return true;
}

  
It works if I replace
  
HMENU l_hMenu = LoadMenu(l_hInstance, MAKEINTRESOURCE(IDR_MENU1));
  
with
  
HMENU l_hMenu = GetMenu(m_hWnd);
  
But why? (IDR_MENU1 is the resource menu item to the main menu)

Share this post


Link to post
Share on other sites
Brannon    122
If you leave the LoadMenu call in, but then also call

SetMenu(m_hWnd, l_hMenu);

after it, does it work? The thing is, calling LoadMenu(), will load it.. but you have to actually do something with it afterwards. GetMenu() gets the active menu for the window, which in this case I think is what you want.. right?


-Brannon

Share this post


Link to post
Share on other sites
Zeblar Nagrim    150
Thanks for your reply Brannon!

I´m in school right now so I can´t test SetMenu right now but I will do that when I come home.

The thing is that I want to use this function for all kinds of menus not just for the main window. For instance I will use it for a popup menu for a toolbar button.

Share this post


Link to post
Share on other sites
Brannon    122
So you basically want to do the following?

If a window has a menu, you want to add a bitmap to that menu.

If that''s the case, then use GetMenu() (not LoadMenu()). If you want to do this to a window that doesn''t already have a menu, then my advice would be to have a seperate call that you make first which loads and menu and sets that menu to be the current menu on the window. You could try to add logic to that function (above) to do both .. but why?

Am I answering your question?

-Brannon

Share this post


Link to post
Share on other sites