[C/C++ 11 - win32] - how add a bitmap to menu?

Nov 18, 2014 at 7:18pm
i did these function for add a bitmap to menu:
1
2
3
4
5
6
7
8
9
10
void bitmap(string filename)
    {
        HBITMAP bitimage = (HBITMAP)LoadImage( NULL, filename.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

        if(primeiromenu==true)
            SetMenuItemBitmaps(GetMenu(WindowMain),menuposition,MF_BYCOMMAND ,(HBITMAP) bitimage,(HBITMAP) bitimage);
        else
            SetMenuItemBitmaps(MenuHandle,menuposition,MF_BYCOMMAND ,(HBITMAP)bitimage,(HBITMAP) bitimage);

    }

i belive the position is ok. but the image isn't showed :(
menu3.bitmap("C:\\hammer.bmp");
menu3 it's an Menu object that have the bitmap() funtion.
the file exist. so what isn't right?
Nov 19, 2014 at 1:16pm
when using win32 always check return value (see what each function return on msdn).

See if bitimage is NULL, and it it is, use GetLastError.

Same with SetMenuItemBitmaps. Compare result with 0 then get last error to see what you do wrong.
Nov 20, 2014 at 12:08am
resolved:
1
2
3
4
5
6
7
8
9
void bitmap(string filename)
    {
        HBITMAP bitimage = (HBITMAP)LoadImage( NULL, filename.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

        if(primeiromenu==true)
            SetMenuItemBitmaps(GetMenu(WindowMain),menuposition,MF_BYPOSITION ,(HBITMAP)bitimage,(HBITMAP)bitimage);
        else
            SetMenuItemBitmaps(MenuHandle,menuposition,MF_BYPOSITION ,(HBITMAP)bitimage ,(HBITMAP)bitimage);
    }

thanks for all
PS: is there any option for, when create the new thread, the mail notification been selected by defauld?
Last edited on Nov 20, 2014 at 12:11am
Topic archived. No new replies allowed.