CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2010
    Posts
    72

    Question 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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: SetmenuItemBitmap

    Quote Originally Posted by Turingmachine View Post
    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

  3. #3
    Join Date
    Dec 2009
    Posts
    145

    Re: SetmenuItemBitmap

    Quote Originally Posted by Turingmachine View Post
    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();}

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: SetmenuItemBitmap

    Quote Originally Posted by Ledidas View Post
    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

  5. #5
    Join Date
    Dec 2009
    Posts
    145

    Re: SetmenuItemBitmap

    Quote Originally Posted by VictorN View Post
    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

  6. #6
    Join Date
    Jun 2010
    Posts
    72

    Resolved 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

  7. #7
    Join Date
    Jun 2010
    Posts
    50

    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
  •  





Click Here to Expand Forum to Full Width

Featured