How would i load a resource bitmap into a CStatic? Thanks.
Printable View
How would i load a resource bitmap into a CStatic? Thanks.
1. Lay a static control to a dialog box.
2. At property setting, change the Type attribute to "Bitmap".
3. Assign resource ID to Image attribute.
and if I want to do it dynamically?
Sally
You can SetBitmap function of CStatic class.
You can associate your static control to a member veriable of CStatic class at "Member Variables"
section of Class Wizard.
search help for ::LoadImage(). This function does what you want.
I have just tried using your suggestion for a modal dialog box, but get an ASSERTion failure (NULL hWnd) from SetBitmap(). My code is:
HBITMAP hBitmap = ::GetTrackSymbol( tempBitmap, PPLI_AIR, tempStr );
d_Filters->m_Page1.m_ppli_air.SetBitmap( hBitmap );
if(d_Filters->DoModal()==IDOK) {
This is in the event handler for the menu item to open the dialog. GetTrackSymbol() returns a handle to either the built-in resource or a bitmap in a file in the folder named in tempStr.
what i would like 2 know is how do i change the image in a CStatic (bitmap) as a result of some event in the dialog box (eg: different radio buttons). i have tried everything. somebody help me
Try this on your event procedure :
[CBitmap bitmap;
bitmap.LoadBitmap(IDB_YOUR_SPECIAL_BITMAP);
m_static.SetBitmap((HBITMAP)bitmap);]
Please let me know if it works
Regards,
Fabi
fabi's code really hit the spot. it got the job done PRONTO. excellent advice chum.
thanx
irfan
If you want to load the bitmap from a file use:
hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), iconPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
then use SetBitmap(hBitmap)
The problem I'm having is that I am unable to free the resources when the dialog containing the CStatics are destroyed. Calling DeleteObject()
also deletes the bitmap of which hBitmap is the handle. This is not what I want as that bitmap is used in the main part of the app.
Does anyone know how to free resources after a SetBitmap call?
I used your code for changing the bitmap in the static control and the static control changes to the new image size, but the control is blank. Help!
Send me your e-mail adress to : [email protected]. I'll sent you a source code.
P.S. Sorry for my late answer. Diferent country, Diferent time zones.
Best regards,
Fabi