Original Post
I have already posted a similar message in the beginners forum but I wasn't sure if this question belongs in there. I am having trouble loading a bitmap picture for a screensaver program I am making. I have already changed the program from .exe to .scr. Here is the code: The problem is that the MessageBox always pops up when I go to run the program showing that the bitmap didn't load, but yet the code compiles with no problem. Any ideas?
#include "stdafx.h"
#include "windows.h"
#include "resource.h"
#include "scrnsave.h"
#include "commctrl.h"
#pragma comment(lib, "scrnsave.lib")
#pragma comment(lib, "comctl32.lib")
HINSTANCE hInst=NULL;
HBITMAP pic=NULL;
LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE:
pic=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP1));
if(!pic)
{
MessageBox(hWnd,"Cannot start screen saver!","Uh-oh!",MB_OK|MB_ICONEXCLAMATION);
return -1;
}
break;
case WM_PAINT:
BITMAP bm;
HDC memDC;
hdc=BeginPaint(hWnd, &ps);
memDC=CreateCompatibleDC(hdc);
SelectObject(memDC,pic);
GetObject(pic,sizeof(bm),&bm);
BitBlt(hdc,500,400,bm.bmWidth,bm.bmHeight,memDC,0,0,SRCCOPY);
DeleteDC(memDC);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
DeleteObject(pic);
PostQuitMessage(0);
break;
default:
return DefScreenSaverProc(hWnd, message, wParam, lParam);
}
return 0;
}
BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
return FALSE;
}
BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
{
return TRUE;
}