Supporting the Screen Saver Window Procedure

Each screen saver must support a window procedure named ScreenSaverProc. Like most window procedures, ScreenSaverProc processes a set of specific messages and passes any unprocessed messages to a default procedure. However, instead of passing them to the DefWindowProc function, ScreenSaverProc passes unprocessed messages to the DefScreenSaverProc function. Another difference between ScreenSaverProc and a normal window procedure is that the handle passed to ScreenSaverProc identifies the entire desktop rather than a client window. The following example shows the ScreenSaverProc window procedure for the sample screen saver.

LONG WINAPI ScreenSaverProc(hwnd, message, wParam, lParam)

HWND hwnd;

UINT message;

DWORD wParam;

LONG lParam;

{

static HDC hdc; /* device-context handle */

static RECT rc; /* RECT structure */

static UINT uTimer; /* timer identifier */

switch(message)

{

case WM_CREATE:

/* Retrieve the application name from the .RC file. */

LoadString(hMainInstance, idsAppName, szAppName, 40);

/* Retrieve the .INI (or registry) filename. */

LoadString(hMainInstance, idsIniFile, szIniFile,

MAXFILELEN);

/* Retrieve any redraw-speed data from the registry. */

lSpeed = GetPrivateProfileInt(szAppName, szRedrawSpeed,

DEFVEL, szIniFile);

/*

* Set a timer for the screen saver window using the

* redraw-rate stored in REGEDIT.INI.

*/

uTimer = SetTimer(hwnd, 1, lSpeed * 1000, NULL);

break;

case WM_ERASEBKGND:

/*

* The WM_ERASEBKGND message is issued before the

* WM_TIMER message, allowing the screen saver to

* paint the background as appropriate.

*/

hdc = GetDC(hwnd);

GetClientRect (hwnd, &rc);

FillRect (hdc, &rc, GetStockObject(BLACK_BRUSH));

ReleaseDC(hwnd,hdc);

break;

case WM_TIMER:

/*

* The WM_TIMER message is issued at (lSpeed * 1000)

* intervals, where lSpeed == .001 seconds. This

* code repaints the entire desktop with a white,

* light gray, dark gray, or black brush each

* time a WM_TIMER message is issued.

*/

hdc = GetDC(hwnd);

GetClientRect(hwnd, &rc);

if (i++ <= 4)

FillRect(hdc, &rc, GetStockObject(i));

else

(i = 0);

ReleaseDC(hwnd,hdc);

break;

case WM_DESTROY:

/*

* When the WM_DESTROY message is issued, the screen saver

* must destroy any of the timers that were set at WM_CREATE

* time.

*/

if (uTimer)

KillTimer(hwnd, uTimer);

break;

}

/*

* DefScreenSaverProc processes any messages

* ignored by ScreenSaverProc.

*/

return DefScreenSaverProc(hwnd, message, wParam, lParam);

}

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples