if(!m_Image1.SetBitmap(::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_SUNSET))))
{
MessageBox(L"Error Setting Bitmap");
}
m_Image1 is the control variable to the static image control.
IDB_SUNSET is the ID of a bitmap I have.
When I run the program I get a messagebox saying "Error setting bitmap". Does anyone know why this is happening?
Further, is there a way to load other file formats? Or a better way of loading images into a control? Or even a better control to use? Because this method doesn't seem like the best way of achieving this.
[C++/MFC] Problem Loading Bitmap
I am in a dialog based MFC application.
I am trying to load an image into a static image control.
Here is the code.
CStatic::SetBitmap() returns the HBITMAP that was previously set. If there was no previously set HBITMAP it will return NULL. Which means that your function call could actually be succeeding.
if(!(hBmp = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_SUNSET)))) { MessageBox(L"Error Loading Bitmap"); } if(!m_Image1.SetBitmap(hBmp)) { MessageBox(L"Error Setting Bitmap"); }
Only message box that pops up is the second one, which implies it loads the bitmap fine.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement