dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Icons in pulldown menus

  1. #1
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Icons in pulldown menus

    Hi,

    Does anyone know how to add bmps or icons to a pulldown menu?
    Both normal menu items and (most important) menu items with sub menues should be able to have a small picture beside it

    Ex

    Pulldown menu
    | MenuItem1 | ________________
    | MenuItem2 > | | SubItem 1 |
    | MenuItem 3 | | SubItem 2 |

    Pls. forgive my crappy graphichs, but I hope you get the idea.

    /Lars VJ

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Icons in pulldown menus

    check out menu articles on Codeguru.

  3. #3
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Re: Icons in pulldown menus

    Hi again.

    Interresting articles!

    But I'm not sure if I can use it. I have to generate af menu dynamicly (so I can't make any menu resources and stuff).

    I hoped, that I could use something like the stuff below.

    Code:
    void CDynaMenu::DrawMenus()
    {
    	if (!m_bEnabled) return;
    
    	static CMenu tmpmenu[200];
    
    	std::vector<Menuitem>::iterator i;
    	std::vector<SubMenuItem>::iterator j;
        CMenu* pMainMenu = pMainWnd->GetMenu();
    
    	CMenu *pMenu = pMainMenu->GetSubMenu(4);
    
    	static CBitmap bmp;
    	bmp.LoadBitmap(".\\RES\\test.bmp");
    	CBitmap *pbmp=&bmp;
    	
    
    	i = Menu.begin();
    	int x=0;
    	while (i!=Menu.end())
    	{
    		CMenu *subsub;// = i->Menu;
    		subsub = &tmpmenu[x];
    		subsub->m_hMenu=NULL;
    		subsub->CreatePopupMenu();
    		
    		j = i->SubMenu.begin();
    		while (j!=i->SubMenu.end())
    		{
    			subsub->AppendMenu(MF_BYPOSITION|MF_STRING,j->MenuId,j->Caption.GetBuffer(0));
    			j++;
    		}
    		pMenu->InsertMenu(i->MenuOffset,MF_POPUP,(UINT)subsub->m_hMenu,i->Caption.GetBuffer(0));
    		pMenu->ModifyMenu(i->MenuOffset,MF_BYCOMMAND,(UINT)subsub->m_hMenu,pbmp);
    
    		i++;
    		x++;
    	}
    }

  4. #4
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: Icons in pulldown menus

    I just osted a new article on Owner drawn menus over on CodeProject.

    It allows the user to handle all menus internally as CMenu. In fact you dont have to worry about any owner drawn stuff as it handles it all for you. As long as you dont call TrackPopupMenu(Ex) with the TPM_NONOTIFY style all menus will be made auto owner-drawn.

    See http://www.codeproject.com/useritems/QuickODmenu.asp
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  5. #5
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Re: Icons in pulldown menus

    Thanks, but I'm afraid it's still no good for me.
    The thing is, I made the menu items dynamicly. I haven't got a menu ressource (IDR_something). I only know how many menues and submenues I have at runtime - not at compile time.

    /Lars VJ

  6. #6
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: Icons in pulldown menus

    The article code doesn't care where your menu comes from. When you display it, it makes it owner drawn at that point. You could have pulled it out of a hat for all the code cares. As long as you do not display the menu using the TPM_NONOTIFY flag it will be owner drawn. And if any toolbar button IDs match any of the menu IDs then that image will be used when the menu is displayed.

    Take another look at the article and give it a try. From what you say it should do exactly what you need.
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  7. #7
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Re: Icons in pulldown menus

    Thank you for your quick response.

    Well, I've looked a bit at it again, and at my own code. I think my largest problem right now is, that menu items with sub menues under them don't have an id. I *can* change (add) icons for "normal" menu items. But the ones with sub menues still give me trouble.

    I hope you won't loose patience with me ;-) but these "magic menues" are a bit tough...

    /Lars VJ

  8. #8
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Icons in pulldown menus

    For submenus , GetMenuItemID always returns -1. Now, what is the problem ?

    Is it that , given a menu item that infact is a submenu, you have trouble knowing which of the submenus it is , so that you can use the proper icon ?

  9. #9
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Re: Icons in pulldown menus

    Excactly. When I haven't got a "proper" ID, I can't (or at least I don't know how to) put an icon on that menu item which have submenues attached, and are thus not a "real" menu item (which would *have* an ID so I could tamper with them).

    /Lars VJ

  10. #10
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Icons in pulldown menus

    Well, you could always access the menu item using index rather than ID, right ?

  11. #11
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: Icons in pulldown menus

    The issue is that popup menus cannot be selected so do not have a menu ID. The nearest thing you can have to this is the HMENU.

    You would have to find what the HMENU for the popup you want to associate the icon with, then when it came to drawing the menu item, instead of searching by the menu ID, you would search by the HMENU and from that you could find the correct icon to plot next to the menu item.

    I checked through serval common applicaitons, and as far as I can see, no popup menu items have icons beside them. So maybe you rlooking to add non-standard functionality to your app and could safely ignore this an un-needed requirement?
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)