Code   InformationDownload
Information Screen Savers.

Very kindly, when Microsoft give you Visual C++ they don't provide you with a sensible demo of how to create Win32 screen savers in C. I think there's a lame C++ demo, but I don't understand all that business. So, some of the code provided by Silicon Graphics, Inc. (with the OpenGLtm screen savers) has been 're-used' (ahem) to create a proper template for Win32 screen savers. I suggest you read all the legal-eaglery in the 'scrnsave.c' file to stop me getting into trouble.

The download contains the source for the demo screen saver as well as the compiled version, this doesn't really do much, just blanks out the screen. To create your own screen savers make a project (Win32 application) and include the 'scrndemo.c', 'scrndemo.rc' and 'scrnsave.c' files. The 'scrndemo.c' file is the one you change, as well as possibly the resource script. The functions you need to provide are described below (use this demo as a template to modify), and there you go, the world's your lobster.

LRESULT WINAPI ScreenSaverProc(
   HWND hWnd,
   unsigned message,
   UINT wParam,
   LPARAM lParam
);

This is your main message handling procedure, like you would write WndProc for a proper Win32 application. I think as a bare minimum you might get away with just the messages shown here but you'll obviously have to add some code to make it interesting. Top tips; have a look at the 3d screen saver and the fade32 download for code that does this sort of thing, stop the screen saver waking up when the mouse moves by trapping the WM_MOUSEMOVE message and returning 0 instead of passing it on to the DefScreenSaverProc. Happy saving squire.

LRESULT WINAPI ScreenSaverPreviewProc(
   HWND hWnd,
   unsigned message,
   UINT wParam,
   LPARAM lParam
);

Put the code in here to draw whatever you want in the little preview window in the Display Properties dialog. The easiest thing to do here is to just have one line which calls the main screen saver function like in the demo. The code you'll be wanting is "return(ScreenSaverProc(hWnd,message,wParam,lParam));", otherwise you'll have to put in all the usual message handling crap.

BOOL WINAPI ScreenSaverConfigureDialog(
   HWND hWnd,
   UINT message,
   WPARAM wParam,
   LPARAM lParam
);

If you've written Windows 3.1x or Win32 dialog handling functions before then you'll know what to put here. It's one of them. If you've not then you're probably gonna be struggling a bit by now guv'nor. Have a butcher's at some of the other sample code mooching about 'round here, it might give you some pointers.

BOOL WINAPI RegisterDialogClasses(
   HINSTANCE hInst
);

Lord only knows why you'd want to do anything here except "return TRUE;". Keeps it simple mind you.

 




G.E.M