• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VC++: How do I change a bitmap during the programs execution?

Here's an example supposing that you have a dialog with a static bitmap control with the id IDC_STATIC_BITMAP. To load a bitmap with the ID IDB_BITMAP2 into the control, you would use code like this:


CStatic* pStatic = reinterpret_cast<CStatic*>(GetDlgItem(IDC_STATIC_BITMAP));
pStatic->SetBitmap(LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_BITMAP2)));
 
I should have been more specific... I am changing the bitmap of a button, and it does not work when i substitute the control ID for the button in place of the static bitmap control thing..

when the button gets pressed, i will change the bitmap again...


argh... none of my books i have go into depth about bitmaps anyway...

 
Originally posted by: zsouthboy
I should have been more specific... I am changing the bitmap of a button, and it does not work when i substitute the control ID for the button in place of the static bitmap control thing..

when the button gets pressed, i will change the bitmap again...


Try this then (button with ID IDC_MY_BUTTON_ID):

CButton* pButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_MY_BUTTON_ID));
pButton->SetBitmap(LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_MY_BITMAP_ID)));

 
Nope.... simply does nothing when i try that.. the button stays blank...

i guess i should just use pictures instead of buttons, eh? (clicking on pictures instead of buttons to change them)
 
Originally posted by: zsouthboy
Nope.... simply does nothing when i try that.. the button stays blank...

i guess i should just use pictures instead of buttons, eh? (clicking on pictures instead of buttons to change them)


Did you create the button with a 'bitmap' style?
 
Back
Top