Sign in to follow this  
zebdor

Loading Bitmap Problem

Recommended Posts

zebdor    122
Hello, this is my first post on this site and I had a question on a screensaver program I am working on. I have tried to make a program that loads a 48x48 bitmap image with LoadBitmap but it doesn't work. Here is the code:
#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;
}
I have already changed the file extension from .exe to .scr but the MessageBox always appears because the image couldn't load. Or so I believe. I have tried to learn more about LoadBitmap but I can't find the answer to this problem. Someone please help...

Share this post


Link to post
Share on other sites
AAAP    137
the message box comes if pic returns false?

where does pic come from? I didn't see it anywhere else in the code

EDIT: ok i did, hang on.

Ok, where does IDB_BITMAP1 come from? where is it declared? can ScreenSaverProc see it?

Share this post


Link to post
Share on other sites
zebdor    122
IDB_BITMAP1 is a the id for a bitmap image i made i have it listed under my .rc directory. I have it defined in resource.h. Hope this helps a little. i don't know if ScreenSaverProc can see it but it comiles and everthing and makes the file, but the MessageBox always appears. Help!

[Edited by - zebdor on November 29, 2005 2:40:32 PM]

Share this post


Link to post
Share on other sites
-indirectX-    132
Hi there,
I've never seen Screen Saver code before, but it looks pretty much like normal windows setup code. In RegisterDialogClasses(), do you have to set your global hInst to the hInst parameter sent to this function? It doesn't look like hInst has been set to anything before you run LoadBitmap().

Good luck.

-indirectX-
www.indirectx.co.nr

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