|
-
July 27th, 2010, 04:12 AM
#1
SetmenuItemBitmap
I have a menu, I use this function to set a bitmap for my item
in the constructor
bmp.LoadBitmap(IDB_BITMAPX); // without error
and in the create menu section
menu.setmenuitembitmap(1,MF_BYPOSITION,&bmp,&bmp);
When I execute, I see nothing in the menu
-
July 27th, 2010, 05:03 AM
#2
Re: SetmenuItemBitmap
 Originally Posted by Turingmachine
I have a menu, I use this function to set a bitmap for my item
in the constructor
bmp.LoadBitmap(IDB_BITMAPX); // without error
Sounds like your bmp is a local variable and goes out of scope together with the loaded HBITMAP (which is then destroyed) just after your ctor returns.
You should declare it so it could live as long as your menu item is living.
Victor Nijegorodov
-
July 27th, 2010, 05:13 AM
#3
Re: SetmenuItemBitmap
 Originally Posted by Turingmachine
I have a menu, I use this function to set a bitmap for my item
in the constructor
bmp.LoadBitmap(IDB_BITMAPX); // without error
and in the create menu section
menu.setmenuitembitmap(1,MF_BYPOSITION,&bmp,&bmp);
When I execute, I see nothing in the menu 
The way you do it looks correct, I don't know why it doesn't shows up
An "offside" note I would like add is to delete the loaded bitmap after you are done with it, that can be done in the destructor, like
if(bmp.m_hGdiobj){bmp.DestroyObject();}
-
July 27th, 2010, 05:18 AM
#4
Re: SetmenuItemBitmap
 Originally Posted by Ledidas
The way you do it looks correct, I don't know why it doesn't shows up
An "offside" note I would like add is to delete the loaded bitmap after you are done with it, that can be done in the destructor, like
if(bmp.m_hGdiobj){bmp.DestroyObject();}
FYI: CBitmap destructor calls this DestroyObject()
So there is no need to do it explicitly at all (except in the case you want to reuse the same CBitmap instance for another HBITMAP).
Victor Nijegorodov
-
July 27th, 2010, 05:31 AM
#5
Re: SetmenuItemBitmap
 Originally Posted by VictorN
FYI: CBitmap destructor calls this DestroyObject()
So there is no need to do it explicitly at all (except in the case you want to reuse the same CBitmap instance for another HBITMAP).
Yes, you are right,
I only mean it as the most practical useful approach to programming in general, anything Initialised/Loaded will need its pair - Uninitialised/Unloaded - to be performed,
If I am not mistaken, CBitmap destructor will check for its instance's nullablity before calling that function, so such an explicit call only results in the same effect
-
July 27th, 2010, 05:47 AM
#6
Re: SetmenuItemBitmap
Thank you VictorN and Ledidas for your replies
I was wrong about the string passed in to set up the bitmap for menuitem
Problem resolved!
Thanks
-
July 27th, 2010, 06:19 AM
#7
Re: SetmenuItemBitmap
Your final solution would make me feel stupid if I were VictorN or Ledidas, next time please double check your problem with as many methods as possible to resolve it at first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|