[C++/MFC] Problem Loading Bitmap

Started by
4 comments, last by KieranW 14 years, 2 months ago
I am in a dialog based MFC application. I am trying to load an image into a static image control. Here is the code.
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.
Advertisement
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.
I see, however, the image is not loaded into the control anyway.
Did you check the return value of LoadBitmap() to see if that's working properly?
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.
OMG lol, could I be more stupid.

I realised the static control was set to type: frame instead of type: bitmap.

It works now.

Sorry about that. -_-

This topic is closed to new replies.

Advertisement