Supporting the Configuration Dialog Box

Most screen savers provide a configuration dialog box to let the user specify customization data such as unique colors, drawing speeds, line thicknesses, fonts, and so on. To support the configuration dialog box, the application must provide a dialog box template and must also support the ScreenSaverConfigureDialog function. Following is the dialog box template for the sample application.

DLG_SCRNSAVECONFIGURE DIALOG 6, 18, 160, 63
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION |
WS_SYSMENU
CAPTION "Sample Screen-Saver Setup"
FONT 8, "MS Shell Dlg"
BEGIN
GROUPBOX "Redraw Speed", 101, 0, 6, 98, 40
SCROLLBAR ID_SPEED, 5, 31, 89, 10
LTEXT "Fast", 103, 6, 21, 20, 8
LTEXT "Slow", 104, 75, 21, 20, 8
PUSHBUTTON "OK", ID_OK, 117, 10, 40, 14
PUSHBUTTON "Cancel", ID_CANCEL, 117, 32, 40, 14
END

You must define the constant used to identify the dialog box template by using the decimal value 2003, as in the following example.

#define DLG_SCRNSAVECONFIGURE 2003

The following example shows the ScreenSaverConfigureDialog function found in the sample application.

#define MINVEL 1 /* minimum redraw-speed value */

#define MAXVEL 10 /* maximum redraw-speed value */

#define DEFVEL 5 /* default redraw-speed value */

LONG lSpeed = DEFVEL; /* redraw-speed variable */

extern HINSTANCE hMainInstance; /* screen saver instance handle */

CHAR szAppName[80]; /* .INI section name */

CHAR szTemp[20]; /* temporary array of characters */

CHAR szRedrawSpeed[] = "Redraw Speed"; /* .INI speed entry */

BOOL WINAPI ScreenSaverConfigureDialog(hDlg, message, wParam, lParam)

HWND hDlg;

UINT message;

DWORD wParam;

LONG lParam;

{

static HWND hSpeed; /* handle of speed scroll bar */

static HWND hOK; /* handle of OK push button */

switch(message)

{

case WM_INITDIALOG:

/* 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);

/*

* If the initialization file does not contain an entry

* for this screen saver, use the default value.

*/

if(lSpeed > MAXVEL || lSpeed < MINVEL)

lSpeed = DEFVEL;

/* Initialize the redraw-speed scroll bar control. */

hSpeed = GetDlgItem(hDlg, ID_SPEED);

SetScrollRange(hSpeed, SB_CTL, MINVEL, MAXVEL, FALSE);

SetScrollPos(hSpeed, SB_CTL, lSpeed, TRUE);

/* Retrieve a handle of the OK push button control. */

hOK = GetDlgItem(hDlg, ID_OK);

return TRUE;

case WM_HSCROLL:

/*

* Process scroll bar input, adjusting the lSpeed

* value as appropriate.

*/

switch (LOWORD(wParam))

{

case SB_PAGEUP:

--lSpeed;

break;

case SB_LINEUP:

--lSpeed;

break;

case SB_PAGEDOWN:

++lSpeed;

break;

case SB_LINEDOWN:

++lSpeed;

break;

case SB_THUMBPOSITION:

lSpeed = HIWORD(wParam);

break;

case SB_BOTTOM:

lSpeed = MINVEL;

break;

case SB_TOP:

lSpeed = MAXVEL;

break;

case SB_THUMBTRACK:

case SB_ENDSCROLL:

return TRUE;

break;

}

if ((int) lSpeed <= MINVEL)

lSpeed = MINVEL;

if ((int) lSpeed >= MAXVEL)

lSpeed = MAXVEL;

SetScrollPos((HWND) lParam, SB_CTL, lSpeed, TRUE);

break;

case WM_COMMAND:

switch(LOWORD(wParam))

{

case ID_OK:

/*

* Write the current redraw-speed variable to

* the .INI file.

*/

wsprintf(szTemp, "%ld", lSpeed);

WritePrivateProfileString(szAppName, szRedrawSpeed,

szTemp, szIniFile);

case ID_CANCEL:

EndDialog(hDlg, LOWORD(wParam) == ID_OK);

return TRUE;

}

}

return FALSE;

}

In addition to providing the dialog box template and supporting the ScreenSaverConfigureDialog function, an application must also support the RegisterDialogClasses function. This function registers any nonstandard window classes required by the screen saver. Because the sample application used only standard window classes in its dialog box procedure, this function simply returns TRUE, as in the following example.

BOOL WINAPI RegisterDialogClasses(hInst)

HANDLE hInst;

{

return TRUE;

}