Jump to content
  • Advertisement
Sign in to follow this  
KieranW

[C++/MFC] Problem Loading Bitmap

This topic is 3055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. -_-

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!