The following ScreenSaverProc function processes the WM_CREATE, WM_TIMER, WM_DESTROY, and WM_ERASEBKGND messages before calling the DefScreenSaverProc function:
LONG FAR PASCAL ScreenSaverProc(hWnd, msg, wParam, lParam)
HWND hWnd;
WORD msg;
WORD wParam;
LONG lParam;
{
RECT rc;
static WORD wBottomCount;
switch (msg)
{
case WM_CREATE: {
HANDLE hResInfo;
GetIniEntries(); /* load strings from STRINGTABLE */
GetIniSettings(); /* load initialization settings */
/* Load DIB image. */
hbmImage = LoadBitmap(hMainInstance, szDIBName);
/* Create a timer to move the image. */
wTimer = SetTimer(hWnd, ID_TIMER, wElapse, NULL);
xPos = xPosInit;
yPos = yPosInit;
break;
}
case WM_TIMER:
if (bPause && bBottom) {
if (++wBottomCount == 10) {
wBottomCount = 0;
bBottom = FALSE;
}
break;
}
MoveImage(hWnd); /* move the image slightly */
break;
case WM_DESTROY:
if (hbmImage)
DeleteObject(hbmImage);
if (wTimer)
KillTimer(hWnd, ID_TIMER);
break;
case WM_ERASEBKGND:
GetClientRect(hWnd, &rc);
FillRect((HDC) wParam, &rc,
(HBRUSH) GetStockObject(BLACK_BRUSH));
return 0L;
default:
break;
}
return DefScreenSaverProc(hWnd, msg, wParam, lParam);
}
If your window procedure traps the WM_DESTROY message, it must use one of the following methods to properly end the screen saver:
After processing the message, pass it to the DefScreenSaverProc function.
In the WM_DESTROY case of the message handler, call the PostQuitMessage function.