Click to See Complete Forum and Search --> : SetmenuItemBitmap
Turingmachine
July 27th, 2010, 04:12 AM
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 :(
VictorN
July 27th, 2010, 05:03 AM
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.
Ledidas
July 27th, 2010, 05:13 AM
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();}
VictorN
July 27th, 2010, 05:18 AM
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).
Ledidas
July 27th, 2010, 05:31 AM
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
Turingmachine
July 27th, 2010, 05:47 AM
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
TheComputer
July 27th, 2010, 06:19 AM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.