How to add icons to menu items in c++ win32 API
11,902
Solution 1
SetMenuItemInfo http://msdn.microsoft.com/en-us/library/windows/desktop/ms648001(v=vs.85).aspx
Solution 2
First you shall load the bitmap from resource. You can use LoadImage or LoadBitmap Win32 API functions to load bitmap.
It will return a new image handle. Then you can use this handle to assign bitmap to menu item via SetMenuItemInfo function.
See also MSDN topic about using bitmaps with menus that describes it step by step.
Author by
Arturs Lapins
Updated on June 05, 2022Comments
-
Arturs Lapins almost 2 years
Possible Duplicate:
InsertMenu/AppendMenu - How to add Icons to menu and submenus using C++ and win32Hello I have a menu in c++ here is the code of it
HMENU hMenu = CreateMenu(); HMENU hFileMenu = CreatePopupMenu; HMENU HFileOpen = CreateMenu; AppendMenu(hFileMenu, MF_STRING, (UINT)hFileOpen, "Open"); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hFileMenu, "File"); SetMenu(hwnd,hMenu);
I have been looking all over the internet and I can't seen to find a tutorial on how to make bitmaps for the menu item. I want to add a bitmap for hFileOpen. How would I do it?
-
Arturs Lapins over 11 yearsIm not exactly sure how to use that function maybe you can help me out
-
Arturs Lapins over 11 yearsCan you help me, I'm not sure how to use it Microsoft dosen't explain well.
-
Connor Hollis over 11 yearsWell the function will look something like this:
// create a bitmap
HBITMAP bitmap;
// Load the bitmap resource
bitmap = (HBITMAP)LoadImage( HINSTANCE, "file.type", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
After that create a MENUITEMINFO and send it by pointer to the SetMenuItemInfo function. -
Arturs Lapins over 11 yearssorry im a little confuzed is HINSTANCE, IMAGE_BITMAP, 0,0 and LR_LOADFROMFILE supposto stay the same or i have to change them, if i do which one and to what
-
Connor Hollis over 11 yearsThe hinstance has to change to whatever your HINSTANCE is. You get that value from winmain. The other values stay the same. IMAGE_BITMAP is used to specify that this is a bitmap file. the two 0's implies that we will load the image using whatever the actual image size is. And LR_LOADFROMFILE tells windows to actually load this resource from the file on disk.
-
Rost over 11 years@ArtursLapins See MSDN docs: msdn.microsoft.com/en-us/library/windows/desktop/…
-
Arturs Lapins over 11 yearsokay this is what i have: 'HBITMAP bitmap;' 'bitmap = (HBITMAP)LoadImage(hInstance, "menuicons/fileopen.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);' now how do i tell my AppendMenu to add that bitmap?
-
Connor Hollis over 11 yearsRost modified my post to include a link to a tutorial on MSDN that carefully elaborates every step of the process. Here it is again. link