home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of Select: Windows 95 Special 2
/
CD_1.iso
/
scrnsavr
/
bouncer
/
bouncer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-17
|
15KB
|
511 lines
/* BOUNCER.C - ScreenSaverProc(), RegisterDialogClasses(),
* ScreenSaverConfigureDialog() and other support code for
* BOUNCER.
*
* BOUNCER is a sample screen saver application. It bounces a
* bitmap across the display and produces a sound when the
* bitmap image is at the bottom of the screen.
*
* (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.
*/
// COPYRIGHT:
//
// (C) Copyright Microsoft Corp. 1992. 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 "bouncer.h"
/* Global used by SCRNSAVE.LIB. Required for all screen savers.
*/
char szAppName[40];
/* Globals specific to BOUNCER.
*/
char szDIBName[] = "BounceDIB";
char szSpeedName[] = "Speed";
char szXPosName[] = "xPosition";
char szYPosName[] = "yPosition";
char szXVelocityName[] = "xVelocity";
char szGravityName[] = "Gravity";
char szSoundName[] = "Sound";
char szDIBNumName[] = "DIBNum";
char szPauseName[] = "Pause at bottom";
char szName[] = "Bounce a bitmap";
/* 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
WORD wElapse; // speed parameter
WORD wTimer; // timer id
BOOL bBottom; // TRUE if frog is at bottom of screen
int xPos; // current x position
int yPos; // current y position
int xPosInit; // initial x position
int yPosInit; // initial y position
int xVelocInit; // x initial velocity
int nGravity; // acceleration factor
BOOL bSound; // sound on/off flag
BOOL bPause; // stick at bottom of screen?
BOOL bPassword; // password protected?
HANDLE hresWave; // handle to sound resource
LPSTR lpWave; // pointer to wave resource
/* 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)
{
RECT rc;
static WORD wBottomCount;
switch (msg)
{
case WM_CREATE: // BOUNCER-specific
{
HANDLE hResInfo;
/* Load the strings from the STRINGTABLE
*/
GetIniEntries();
/* Load the initial bounce settings.
*/
GetIniSettings();
/* Load the DIB image we want to use.
*/
hbmImage = LoadBitmap(hMainInstance, szDIBName);
/* Load and lock the sound resource
*/
if (hResInfo = FindResource(hMainInstance, "Sound", "WAVE"))
{
if (hresWave = LoadResource(hMainInstance, hResInfo))
{
lpWave = LockResource(hresWave);
}
}
/* Create a timer to move the image
*/
wTimer = SetTimer(hWnd, ID_TIMER, wElapse, NULL);
xPos = xPosInit;
yPos = yPosInit;
break;
}
case WM_TIMER: // BOUNCER-specific
if (bPause && bBottom)
{
if (++wBottomCount == 10)
{
wBottomCount = 0;
bBottom = FALSE;
}
break;
}
/* Move the image around a bit
*/
MoveImage(hWnd);
break;
case WM_DESTROY: // BOUNCER-specific
/* Destroy any objects we created
*/
if (hbmImage)
DeleteObject(hbmImage);
if (wTimer)
KillTimer(hWnd, ID_TIMER);
sndPlaySound(NULL, 0);
/*s-*/ if( lpWave ) UnlockResource(hresWave); /*s+*/
if (hresWave)
FreeResource(hresWave);
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);
}
/* 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: // BOUNCER-specific
GetIniEntries();
GetIniSettings();
SetDlgItemInt(hDlg, ID_SPEED, wElapse, FALSE);
SetDlgItemInt(hDlg, ID_XPOS, xPosInit, TRUE);
SetDlgItemInt(hDlg, ID_YPOS, yPosInit, TRUE);
SetDlgItemInt(hDlg, ID_VELOCITY, xVelocInit, TRUE);
SetDlgItemInt(hDlg, ID_GRAVITY, nGravity, TRUE);
SendDlgItemMessage(hDlg, ID_SOUND, BM_SETCHECK, bSound, NULL);
SendDlgItemMessage(hDlg, ID_PAUSE, BM_SETCHECK, bPause, NULL);
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: // BOUNCER-specific
switch (wParam)
{
case IDOK:
wElapse = GetDlgItemInt(hDlg, ID_SPEED, NULL, FALSE);
xPosInit = GetDlgItemInt(hDlg, ID_XPOS, NULL, TRUE);
yPosInit = GetDlgItemInt(hDlg, ID_YPOS, NULL, TRUE);
xVelocInit = GetDlgItemInt(hDlg, ID_VELOCITY, NULL, TRUE);
nGravity = GetDlgItemInt(hDlg, ID_GRAVITY, NULL, TRUE);
bSound = IsDlgButtonChecked(hDlg, ID_SOUND);
bPause = IsDlgButtonChecked(hDlg, ID_PAUSE);
bPassword = IsDlgButtonChecked(hDlg, ID_PASSWORDPROTECTED);
WriteProfileInt(szAppName, szSpeedName, wElapse);
WriteProfileInt(szAppName, szXPosName, xPosInit);
WriteProfileInt(szAppName, szYPosName, yPosInit);
WriteProfileInt(szAppName, szXVelocityName, xVelocInit);
WriteProfileInt(szAppName, szGravityName, nGravity);
WriteProfileInt(szAppName, szSoundName, bSound);
WriteProfileInt(szAppName, szPauseName, bPause);
WriteProfileInt(szAppName, szIsPassword, bPassword);
EndDialog(hDlg, TRUE);
return TRUE;
case IDCANCEL: