del
asked on
Screen Saver Problems
I'm new to windows programming.
I used the example screen saver code with the SDK. The screen saver worked when I would preview it, but when I hit the settings button nothing would happen. I defined the following three funtions and linked with the scrnsave.lib. I also passed any unprocessed messages to
DefScreenSaverProc(hwnd, message, wParam, lParam).
BOOL WINAPI ScreenSaverConfigureDialog (HWND hDlg, UINT message, WPARAM
wParam, LONG lParam)
BOOL WINAPI RegisterDialogClasses(HAND LE hInst)
LONG WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LONG
lParam)
Can anyone answer these questions or have other source code that I could look at that does not use MFC?
/*------------------------ ---------- ---------- ---------- ---------- -------
sstest.c
Dale Lepine
7/14/97
Screen Saver Program
-------------------------- ---------- ---------- ---------- ---------- -----*/
#include <windows.h>
#include <scrnsave.h>
#include "sstest.h"
#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 1 /* default redraw-speed value */
LONG lSpeed = DEFVEL; /* redraw-speed variable */
extern HINSTANCE hMainInstance; /* screen saver instance handle */
CHAR szTemp[20]; /* temporary array of characters */
CHAR szRedrawSpeed[] = "Redraw Speed"; /* .INI speed entry */
BOOL WINAPI ScreenSaverConfigureDialog (HWND hDlg, UINT message, WPARAM 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(szApp Name, 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;
}
BOOL WINAPI RegisterDialogClasses(HAND LE hInst)
{
return TRUE;
}
LONG WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LONG lParam)
{
static HDC hdc; /* device-context handle */
static RECT rc; /* RECT structure */
static UINT uTimer; /* timer identifier */
static int i = 0;
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(szApp Name, 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(WHITE_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));
DrawText(hdc, "Hello, Windows95!", -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
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);
}
sstest.rc
#include <winnt.h>
#include <winuser.h>
#include "sstest.h"
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 Sans Serif"
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
sstest.h:
#define ID_SPEED 109
#define ID_OK 108
#define ID_CANCEL 107
sstest.def:
DESCRIPTION 'SCRNSAVE : Test'
CODE MOVEABLE
DATA MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 4096
EXPORTS
ScreenSaverConfigureDialog
ScreenSaverProc
Dale Lepine
UNH
del@hopper.unh.edu
I used the example screen saver code with the SDK. The screen saver worked when I would preview it, but when I hit the settings button nothing would happen. I defined the following three funtions and linked with the scrnsave.lib. I also passed any unprocessed messages to
DefScreenSaverProc(hwnd, message, wParam, lParam).
BOOL WINAPI ScreenSaverConfigureDialog
wParam, LONG lParam)
BOOL WINAPI RegisterDialogClasses(HAND
LONG WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LONG
lParam)
Can anyone answer these questions or have other source code that I could look at that does not use MFC?
/*------------------------
sstest.c
Dale Lepine
7/14/97
Screen Saver Program
--------------------------
#include <windows.h>
#include <scrnsave.h>
#include "sstest.h"
#define DLG_SCRNSAVECONFIGURE 2003
//The following example shows the ScreenSaverConfigureDialog
#define MINVEL 1 /* minimum redraw-speed value */
#define MAXVEL 10 /* maximum redraw-speed value */
#define DEFVEL 1 /* default redraw-speed value */
LONG lSpeed = DEFVEL; /* redraw-speed variable */
extern HINSTANCE hMainInstance; /* screen saver instance handle */
CHAR szTemp[20]; /* temporary array of characters */
CHAR szRedrawSpeed[] = "Redraw Speed"; /* .INI speed entry */
BOOL WINAPI ScreenSaverConfigureDialog
{
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(szApp
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(
szTemp, szIniFile);
case ID_CANCEL:
EndDialog(hDlg, LOWORD(wParam) == ID_OK);
return TRUE;
}
}
return FALSE;
}
BOOL WINAPI RegisterDialogClasses(HAND
{
return TRUE;
}
LONG WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LONG lParam)
{
static HDC hdc; /* device-context handle */
static RECT rc; /* RECT structure */
static UINT uTimer; /* timer identifier */
static int i = 0;
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(szApp
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(WHITE_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));
DrawText(hdc, "Hello, Windows95!", -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
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);
}
sstest.rc
#include <winnt.h>
#include <winuser.h>
#include "sstest.h"
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 Sans Serif"
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
sstest.h:
#define ID_SPEED 109
#define ID_OK 108
#define ID_CANCEL 107
sstest.def:
DESCRIPTION 'SCRNSAVE : Test'
CODE MOVEABLE
DATA MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 4096
EXPORTS
ScreenSaverConfigureDialog
ScreenSaverProc
Dale Lepine
UNH
del@hopper.unh.edu
Post more code. It could be anything.
ASKER
/*------------------------ ---------- ---------- ---------- ---------- -------
sstest.c
Dale Lepine
7/14/97
Screen Saver Program
-------------------------- ---------- ---------- ---------- ---------- -----*/
#include <windows.h>
#include <scrnsave.h>
#include "sstest.h"
#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 1 /* default redraw-speed value */
LONG lSpeed = DEFVEL; /* redraw-speed variable */
extern HINSTANCE hMainInstance; /* screen saver instance handle */
CHAR szTemp[20]; /* temporary array of characters */
CHAR szRedrawSpeed[] = "Redraw Speed"; /* .INI speed entry */
BOOL WINAPI ScreenSaverConfigureDialog (HWND hDlg, UINT message, WPARAM 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(szApp Name, 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;
}
BOOL WINAPI RegisterDialogClasses(HAND LE hInst)
{
return TRUE;
}
LONG WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LONG lParam)
{
static HDC hdc; /* device-context handle */
static RECT rc; /* RECT structure */
static UINT uTimer; /* timer identifier */
static int i = 0;
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(szApp Name, 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(WHITE_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));
DrawText(hdc, "Hello, Windows95!", -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
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);
}
sstest.h
#define ID_SPEED 109
#define ID_OK 108
#define ID_CANCEL 107
sstest.def
DESCRIPTION 'SCRNSAVE : Test'
CODE MOVEABLE
DATA MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 4096
EXPORTS
ScreenSaverConfigureDialog
ScreenSaverProc
sstest.rc
#include <winnt.h>
#include <winuser.h>
#include "sstest.h"
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 Sans Serif"
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
sstest.c
Dale Lepine
7/14/97
Screen Saver Program
--------------------------
#include <windows.h>
#include <scrnsave.h>
#include "sstest.h"
#define DLG_SCRNSAVECONFIGURE 2003
//The following example shows the ScreenSaverConfigureDialog
#define MINVEL 1 /* minimum redraw-speed value */
#define MAXVEL 10 /* maximum redraw-speed value */
#define DEFVEL 1 /* default redraw-speed value */
LONG lSpeed = DEFVEL; /* redraw-speed variable */
extern HINSTANCE hMainInstance; /* screen saver instance handle */
CHAR szTemp[20]; /* temporary array of characters */
CHAR szRedrawSpeed[] = "Redraw Speed"; /* .INI speed entry */
BOOL WINAPI ScreenSaverConfigureDialog
{
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(szApp
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(
szTemp, szIniFile);
case ID_CANCEL:
EndDialog(hDlg, LOWORD(wParam) == ID_OK);
return TRUE;
}
}
return FALSE;
}
BOOL WINAPI RegisterDialogClasses(HAND
{
return TRUE;
}
LONG WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LONG lParam)
{
static HDC hdc; /* device-context handle */
static RECT rc; /* RECT structure */
static UINT uTimer; /* timer identifier */
static int i = 0;
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(szApp
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(WHITE_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));
DrawText(hdc, "Hello, Windows95!", -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
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);
}
sstest.h
#define ID_SPEED 109
#define ID_OK 108
#define ID_CANCEL 107
sstest.def
DESCRIPTION 'SCRNSAVE : Test'
CODE MOVEABLE
DATA MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 4096
EXPORTS
ScreenSaverConfigureDialog
ScreenSaverProc
sstest.rc
#include <winnt.h>
#include <winuser.h>
#include "sstest.h"
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 Sans Serif"
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
ASKER
Edited text of question
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.