Bitmap loads OK, but not from resource

This is a discussion on Bitmap loads OK, but not from resource within the Windows Programming forums, part of the Platform Specific Boards category; I can't load the bitmap from my resource script...When i replace the path in the LoadImage() function with MAKEINTRESOURCE(), the ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Bitmap loads OK, but not from resource

    I can't load the bitmap from my resource script...When i replace the path in the LoadImage() function with MAKEINTRESOURCE(), the image don't load..
    Code:
    hBmp = (HBITMAP)LoadImage(*pInst, MAKEINTRESOURCE(IMG_SPLASH), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE)
    Calling Getlasterror returns 1814, but the image is in the resource script.. Any suggestions to what's wrong??
    The code below works, but it means i have to load the image from a file...

    Code:
    BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
    	static HBRUSH hBrLg;//Dark gray/Light gray brush
    	static HBITMAP hBmp;
    	HDC hDC, hDcMem;
    	PAINTSTRUCT ps;
    
    	switch(uMsg){
    	case WM_INITDIALOG:
    		hwThis=hWnd;
    		hBrLg = CreateSolidBrush(GetSysColor(COLOR_MENU));
    		hBmp = (HBITMAP)LoadImage(0, "C:\\_Src\\CPP\\Setup.bmp", IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE);
    		ShowWindow(hwThis, SW_SHOW);
    		break;
    	case WM_LBUTTONDOWN:
    		EndDialog(hwThis, 0); break;
    	case WM_COMMAND:
    		switch(LOWORD(wParam)){
    		case IDCANCEL:
    		case IDOK:
    			EndDialog(hwThis, 0);
    			break;
    		}
    		break;
    	case WM_PAINT:
    		ZeroMemory(&ps, sizeof(PAINTSTRUCT));
    		BeginPaint(hwThis, &ps);
    		hDC = GetDC(hwThis);
    		hDcMem = CreateCompatibleDC(hDC);
    		SelectObject(hDcMem, hBmp);
    		BitBlt(hDC, 5, 5, 300, 200, hDcMem, 0, 0, SRCCOPY);
    		DeleteDC(hDcMem);
    		EndPaint(hwThis, &ps);
    		break;
    	case WM_CTLCOLORSTATIC:
    		SetTextColor((HDC)wParam, 0x880000);
    		SetBkColor((HDC)wParam, GetSysColor(COLOR_MENU));
    		return((int)hBrLg);
    	case WM_DESTROY:
    		DeleteObject(hBrLg);
    		DeleteObject(hBmp);
    		break;
    	}
    	return(0);
    }

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    It's traditional to post the code that doesn't work rather than the code that does.

    Anyway, since the first parameter of LoadImage is the application instance, replace that with 'GetModuleHandle(0)'. I'm suggesting this because 'pInst' as a dereferenced pointer looks a bit suspect there but it would have been helpful to see what 'pInst' actually is ie how it's declared etc in order to clarify this. If it still fails then try adjusting the flags for the last parameter of LoadImage.

    BTW, please use FormatMessage to get some kind of meaningful text information from GetLastError error codes (but still quote the numerical error code, together with the text error message produced from it).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Same result with GetModuleHandle(0)...
    pInst is the application instance handle. I pass it to every windowFunc in my prog:
    Code:
    HINSTANCE *pInst;
    
    int frmAbout(HINSTANCE *hInst, HWND hWnd){
    	pInst = hInst;
    I use FormatMessage, and it says something like this:
    "Can't find the specified resourcename in the picturefile"

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Have you included the image as a resource (in resource script with BITMAP resource definition statement) in your project?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Talking

    The image was named IMG_ABOUT...
    I've been working with thjis for quite some time, and somewhere along the way i referenced the image with the wrong name...
    Thank you for helping me, Ken..

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    The pInst parameter is invalid. Seems i have to use GetModuleHandle() to achieve the instance handle..

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>somewhere along the way i referenced the image with the wrong name<<

    It's easily done.

    >>The pInst parameter is invalid. <<

    Don't declare it as "HINSTANCE *pInst;" but as:
    Code:
    HINSTANCE pInst;
    but only if you prefer to use a variable rather than GetModuleHandle(0).

    Good to know you worked it out and fixed it.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading a bitmap (Without using glaux)
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 03-16-2006, 08:43 AM
  2. Loading BITMAP Resource
    By FWGaming in forum C++ Programming
    Replies: 1
    Last Post: 07-19-2005, 12:07 PM
  3. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  4. Loading a Bitmap resource for OpenGL Texture[x]
    By the dead tree in forum Game Programming
    Replies: 4
    Last Post: 08-26-2004, 01:12 PM
  5. Adding bitmap as a resource for texture mapping in OpenGL
    By Unregistered in forum Game Programming
    Replies: 2
    Last Post: 03-03-2002, 01:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21