locked
Can change the bitmap in a bitmap control RRS feed

  • Question

  • I don't get it!

    Why can't I change the bitmap in a bitmap control on the fly?

    ((CStatic*)GetDlgItem(IDC_STATIC_A1))->SetBitmap(m_bmpWhite);
    GetDlgItem(IDC_STATIC_A1)->Invalidate(true);

    The above does not cause any ASSERTS or anything but the old bitmap remains stubbornly in the control and wont change to the new one above.

    • Moved by lake Xiao Monday, February 15, 2016 5:43 AM
    Saturday, February 13, 2016 6:56 PM

Answers

  • Hello GregaryB

    Your code should work, but you must be sure the Bitmap handle m_bmpWhit exists over the complete application lifesycle. If m_bmpWhite is a local variable in a function you will not see your bitmap. If the variable is a member of your i.e. CDialog class than everything should be fine.


    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

    • Proposed as answer by Shu 2017 Tuesday, February 16, 2016 5:29 AM
    • Marked as answer by Hart Wang Monday, February 22, 2016 9:37 AM
    Monday, February 15, 2016 6:25 AM
  • Check SS_BITMAP property, please.

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    • Proposed as answer by Shu 2017 Tuesday, February 16, 2016 5:29 AM
    • Marked as answer by Hart Wang Monday, February 22, 2016 9:37 AM
    Monday, February 15, 2016 9:34 AM

All replies

  • Hi GregaryB,

    Since Our forum is discussing about VS general question like how to set/configure Visual Studio and Visual Studio tools.

    And your problem is more related to the C++. I moved it to the C++ forum for better support.

    Thanks for your understanding.

    Best Regards,

    Lake Xiao

    Monday, February 15, 2016 5:42 AM
  • Hello GregaryB

    Your code should work, but you must be sure the Bitmap handle m_bmpWhit exists over the complete application lifesycle. If m_bmpWhite is a local variable in a function you will not see your bitmap. If the variable is a member of your i.e. CDialog class than everything should be fine.


    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

    • Proposed as answer by Shu 2017 Tuesday, February 16, 2016 5:29 AM
    • Marked as answer by Hart Wang Monday, February 22, 2016 9:37 AM
    Monday, February 15, 2016 6:25 AM
  • Hi,

    I think you can try to use specified image list to obtain images. If you create a coolbar that will contain static images. You need to use the image list functions to change those images.

    For more information you can refer to the link: https://msdn.microsoft.com/en-us/library/ms997549.aspx?f=255&MSPPError=-2147217396

    Best Regards,

    Hart

    Monday, February 15, 2016 6:30 AM
  • Check SS_BITMAP property, please.

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    • Proposed as answer by Shu 2017 Tuesday, February 16, 2016 5:29 AM
    • Marked as answer by Hart Wang Monday, February 22, 2016 9:37 AM
    Monday, February 15, 2016 9:34 AM