Jump to content
  • Advertisement
Sign in to follow this  
Noods

LoadBitmap() returning null...

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

Here is my code for loading a bitmap. This function is called when I open a file via the dialog box via the file menu. The program runs properly. However, when I attempt to open a file, LoadBitmap() returns NULL. I am able to see this as the two error reporting dialog boxes pop. Also, the first dialog box shows I have the correct path. Any ideas why LoadBitmap is returning NULL? VOID DIALOG_FileOpen(HWND hWnd) { OPENFILENAME ofn; //common dialog box structure char szFile[260]; //buffer for file name //initialize OPENFILENAME ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hWnd; ofn.lpstrFile = szFile; ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0"; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; //display the open dialog box if(GetOpenFileName(&ofn)==TRUE) { g_hbmBall = LoadBitmap(GetModuleHandle(NULL), ofn.lpstrFile);/////////FIX MessageBox(hWnd, ofn.lpstrFile, "Error", MB_OK | MB_ICONEXCLAMATION); if(g_hbmBall == NULL) { MessageBox(hWnd, "Could not load image!", "Error", MB_OK | MB_ICONEXCLAMATION); } g_hbmMask = CreateBitmapMask(g_hbmBall, RGB(0, 0, 0)); if(g_hbmMask == NULL) { MessageBox(hWnd, "Could not create mask!", "Error", MB_OK | MB_ICONEXCLAMATION); } } }

Share this post


Link to post
Share on other sites
Advertisement
The LoadBitmap() function doesn't load a bitmap from a file. As the MSDN reference page says "The LoadBitmap function loads the specified bitmap resource from a module's executable file."

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!