Sign in to follow this  
Noods

LoadBitmap() returning null...

Recommended Posts

Noods    205
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
SiCrane    11839
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

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