home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
swCHIP 1991 January
/
swCHIP_95-1.bin
/
desktop
/
noblank
/
noblank.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-09
|
9KB
|
298 lines
/* NOBLANK.C - ScreenSaverProc(), RegisterDialogClasses(),
* ScreenSaverConfigureDialog() and other support code for
* noblank.
*
* NOBLANK is a sample screen saver application.
*
* (C) Copyright Microsoft Corp. 1991. All rights reserved.
*
* You have a royalty-free right to use, modify, reproduce and
* distribute the Sample Files (and/or any modified version) in
* any way you find useful, provided that you agree that
* Microsoft has no warranty obligations or liability for any
* Sample Application Files which are modified.
*/
#include <windows.h>
#include <mmsystem.h>
#include "noblank.h"
/* Global used by SCRNSAVE.LIB. Required for all screen savers.
*/
char szAppName[40];
/* Globals specific to noblank.
*/
char szName[]="No Blank Screen Saver";
/* Externals defined in SCRNSAVE.LIB. Required for all screen savers.
*/
HINSTANCE _cdecl hMainInstance;
HWND _cdecl hMainWindow;
char _cdecl szName[TITLEBARNAMELEN];
char _cdecl szIsPassword[22];
char _cdecl szIniFile[MAXFILELEN];
char _cdecl szScreenSaver[22];
char _cdecl szPassword[16];
char _cdecl szDifferentPW[BUFFLEN];
char _cdecl szChangePW[30];
char _cdecl szBadOldPW[BUFFLEN];
char _cdecl szHelpFile[MAXFILELEN];
char _cdecl szNoHelpMemory[BUFFLEN];
UINT _cdecl MyHelpMessage;
HOOKPROC _cdecl fpMessageFilter;
HBITMAP hbmImage; // image handle
BOOL bPassword; // password protected?
WORD wTimer; // timer id
int cntDlgUp; // count of time dialog box is active
int DlgIsUp; // flag to indicate dialog box is active
HWND DlgHandle; // save dialog handle
HWND mainWnd; // main window handle
long DlgTimeOut; // count for removing password dlgbox
/* ScreenSaverProc - Main entry point for screen saver messages.
* This function is required for all screen savers.
*
* Params: Standard window message handler parameters.
*
* Return: The return value depends on the message.
*
* Note that all messages go to the DefScreenSaverProc(), except
* for ones we process.
*/
LONG FAR PASCAL ScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE: // noblank-specific
{
DlgIsUp = 0;
cntDlgUp = 0;
mainWnd = hWnd;
wTimer = 0;
/* Load the strings from the STRINGTABLE
*/
GetIniEntries();
/* Load the initial bounce settings.
*/
GetIniSettings();
/* set the timeout for the password dialog box - password dialog
box will be cancelled after 30 seconds
*/
DlgTimeOut = 3;
break;
}
case WM_ACTIVATE:
case WM_ACTIVATEAPP:
case WM_NCACTIVATE:
case WM_SETCURSOR:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_KEYDOWN:
case WM_KEYUP:
DlgIsUp = 1;
cntDlgUp = 0;
DefScreenSaverProc(hWnd, msg, wParam, lParam);
DlgHandle = FindWindow (NULL, szName);
SetCapture (hWnd);
/* Create a timer
*/
wTimer = SetTimer(hWnd, ID_TIMER, 30000, NULL);
break;
case WM_TIMER: // noblank-specific
if (DlgIsUp) {
// if (++cntDlgUp > DlgTimeOut) {
EndDialog(DlgHandle, FALSE);
DlgIsUp = 0;
cntDlgUp = 0;
SetCapture (hWnd);
if (wTimer) {
KillTimer(hWnd, ID_TIMER);
wTimer = 0;
}
// }
}
break;
case WM_DESTROY: // noblank-specific
/* Destroy any objects we created
*/
if (wTimer) {
KillTimer(hWnd, ID_TIMER);
wTimer = 0;
}
ReleaseCapture ();
break;
case WM_ERASEBKGND:
SetWindowPos (hWnd, HWND_BOTTOM, 0, 0, 50, 50, SWP_HIDEWINDOW);
SetCapture (hWnd);
return 0L;
default:
break;
}
return DefScreenSaverProc(hWnd, msg, wParam, lParam);
}
/* RegisterDialogClasses -- Entry point for registering window
* classes required by configuration dialog box.
*
* Params: hWnd -- Handle to window
*
* Return: None
*/
BOOL RegisterDialogClasses(HINSTANCE hInst)
{
return TRUE;
}
/* ScreenSaverConfigureDialog -- Dialog box function for configuration
* dialog.
*
* Params: hWnd -- Handle to window
*
* Return: None
*/
BOOL FAR PASCAL ScreenSaverConfigureDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HWND hIDOK;
static HWND hSetPassword;
switch (msg)
{
case WM_INITDIALOG: // noblank-specific
GetIniEntries();
GetIniSettings();
SendDlgItemMessage(hDlg, ID_PASSWORDPROTECTED, BM_SETCHECK,
bPassword, NULL);
hSetPassword=GetDlgItem(hDlg, ID_SETPASSWORD);
EnableWindow(hSetPassword, bPassword);
hIDOK=GetDlgItem(hDlg, IDOK);
return TRUE;
case WM_COMMAND: // noblank-specific
switch (wParam)
{
case IDOK:
bPassword = IsDlgButtonChecked(hDlg, ID_PASSWORDPROTECTED);
WriteProfileInt(szAppName, szIsPassword, bPassword);
EndDialog(hDlg, TRUE);
return TRUE;
case IDCANCEL:
EndDialog(hDlg, FALSE);
return TRUE;
case ID_SETPASSWORD:
{
FARPROC fpDialog;
if((fpDialog = MakeProcInstance(DlgChangePassword,hMainInstance)) == NULL)
return FALSE;
DialogBox(hMainInstance, MAKEINTRESOURCE(DLG_CHANGEPASSWORD),
hDlg, fpDialog);
FreeProcInstance(fpDialog);
SendMessage(hDlg, WM_NEXTDLGCTL, hIDOK, 1l);
break;
}
case ID_PASSWORDPROTECTED:
bPassword ^= 1;
CheckDlgButton(hDlg, wParam, bPassword);
EnableWindow(hSetPassword, bPassword);
break;
case ID_HELP:
DoHelp:
#if 0
bHelpActive=WinHelp(hDlg, szHelpFile, HELP_CONTEXT, IDH_DLG_noblank);
if (!bHelpActive)
MessageBox(hDlg, szNoHelpMemory, szName, MB_OK);
#else
/* MessageBox(hDlg, "Insert your call to WinHelp() here.",
szName, MB_OK);*/
#endif
break;
}
break;
default:
if (msg==MyHelpMessage) // Context sensitive help msg.
goto DoHelp;
}
return FALSE;
}
/* THE REST OF THIS FILE IS SPECIFIC TO noblank.
*
* Replace it with your own screen saver code.
*/
/* GetIniSettings -- Get initial settings from WIN.INI
*
* Params: hWnd -- Handle to window
*
* Return: None
*/
static void GetIniSettings()
{
bPassword = GetPrivateProfileInt(szAppName, szIsPassword, FALSE, szIniFile);
}
/* WriteProfileInt - Write an unsigned integer value to CONTROL.INI.
*
* Params: name - szSection - [section] name in .INI file
* szKey - key= in .INI file
* i - value for key above
*
* Return: None
*/
static void WriteProfileInt(LPSTR szSection, LPSTR szKey, int i)
{
char achBuf[40];
/* write out as unsigned because GetPrivateProfileInt() can't
* cope with signed values!
*/
wsprintf(achBuf, "%u", i);
WritePrivateProfileString(szSection, szKey, achBuf, szIniFile);
}
void GetIniEntries(void)
{
//Load Common Strings from stringtable...
LoadString(hMainInstance, idsIsPassword, szIsPassword, 22);
LoadString(hMainInstance, idsIniFile, szIniFile, MAXFILELEN);
LoadString(hMainInstance, idsScreenSaver, szScreenSaver, 22);
LoadString(hMainInstance, idsPassword, szPassword, 16);
LoadString(hMainInstance, idsDifferentPW, szDifferentPW, BUFFLEN);
LoadString(hMainInstance, idsChangePW, szChangePW, 30);
LoadString(hMainInstance, idsBadOldPW, szBadOldPW, 255);
LoadString(hMainInstance, idsHelpFile, szHelpFile, MAXFILELEN);
LoadString(hMainInstance, idsNoHelpMemory, szNoHelpMemory, BUFFLEN);
}