Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I add a menu item that has both a bitmap and a string?

312 views
Skip to first unread message

bohanson

unread,
Apr 15, 2009, 5:46:36 PM4/15/09
to
Hi there,

I was wondering how one can add a bitmap and string together in a menu. I
have seen examples
where the bitmap is used for the menu instead of the string, but how can I
add a
menu item that has both a bitmap, and a string? The AppendMenu() only allows
one
or the other as far as I can see. An example would be C++ Visual Studio,
when you click the menu,
look on the left hand side and there is a bitmap on the left handside of the
string.
Any suggestions would be much appreciated.

Kind regards


Christian ASTOR

unread,
Apr 15, 2009, 6:05:12 PM4/15/09
to
bohanson wrote:

> I was wondering how one can add a bitmap and string together in a menu. I
> have seen examples
> where the bitmap is used for the menu instead of the string, but how can I
> add a menu item that has both a bitmap, and a string? The AppendMenu() only allows
> one or the other as far as I can see. An example would be C++ Visual Studio,
> when you click the menu, look on the left hand side and there is a bitmap on the left handside of the
> string.

With owner-draw menus like you did (or SetMenuItemBitmaps() for
checked/unchecked)

bohanson

unread,
Apr 15, 2009, 11:27:13 PM4/15/09
to
With owner-draw menus like you did (or SetMenuItemBitmaps() for
checked/unchecked)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Hello again,

You mentioned about the checked/unchecked like the MSDN example.
Do I need that code? or is there away I could set the bitmap like this?
I get the feeling I am missing alot of code somewhere.

What I have currently. . . .


LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch(iMsg)
{
case WM_CREATE:

hBmp1 = LoadBitmap(g_hInst, (LPSTR)IDB_BITMAP1);
SetMenuItemBitmaps(hMenu, ID_FILE_EXIT, MF_BYCOMMAND, hBmp1, hBmp1);

return 0;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostQuitMessage(0);
}
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;
}

return DefWindowProc(hwnd,iMsg,wParam,lParam);
}


jeff

unread,
Apr 16, 2009, 10:44:19 AM4/16/09
to
"bohanson" <justins...@msn.com> a écrit dans le message de news:
gs68h4$93d$1...@aioe.org...

> case WM_CREATE:
>
> hBmp1 = LoadBitmap(g_hInst, (LPSTR)IDB_BITMAP1);
> SetMenuItemBitmaps(hMenu, ID_FILE_EXIT, MF_BYCOMMAND, hBmp1, hBmp1);

What is hMenu?
Owner drawing is the usual method (any color, size, ..)


bohanson

unread,
Apr 16, 2009, 5:09:07 PM4/16/09
to

"jeff" <je...@ghi.com> wrote in message news:gs7g6g$ihq$1...@aioe.org...

//------------------------------------------------------------------------------------------------------

I have found out what my problem was, that is the reason why my menu was not
displaying the bitmap next to my menu string.
I loaded the menu in winMain using the loadMenu() & SetMenu(). Well, there
was a scope problem in the callback function.
I have now loaded the menu in the window properties and used the function
GetMenu() in WM_CERATE:
Oh yes, hMenu is a global varible in my example.

// NOT WORKING // Menu loaded in winMain using LoadMenu() & SetMenu().

case WM_CREATE:

hBmp1 = LoadBitmap(g_hInst, (LPSTR)IDB_BITMAP1);
SetMenuItemBitmaps(hMenu, ID_FILE_EXIT, MF_BYCOMMAND, hBmp1, hBmp1);

**********************************************************************************************

// WORKING // Menu loaded in winMain with using. . . ."wnclass.lpszMenuName
= (LPSTR)ID_MENU;"

case WM_CREATE:

hMenu = GetMenu(hwnd);


hBmp1 = LoadBitmap(g_hInst, (LPSTR)IDB_BITMAP1);
SetMenuItemBitmaps(hMenu, ID_FILE_EXIT, MF_BYCOMMAND, hBmp1, hBmp1);

Kind regards


0 new messages