Sign in to follow this  

[C++/MFC] Problem Loading Bitmap

This topic is 2859 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
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

This topic is 2859 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this