// 程序需要的头文件
#include "stdafx.h"
#include <strsafe.h>
#include < Mmsystem.h >
#pragma comment(lib,"scrnsave.lib") //使用库文件
#pragma comment(lib,"comctl32.lib")
#pragma comment(lib,"Winmm.lib")
#include "fileNamelist.h"
#include "resource.h"
#include "time.h"
#include "watersurf.h"
#include "stack.h"
extern HINSTANCE hMainInstance; // screen saver instance handle
//CHAR szAppName[80]; // .ini section name
CHAR szTemp[20]; // temporary array of characters
CHAR szWaterScrExculpation[ ] = "Water Scr Exculpation";
CHAR szWaterScrShowSize[ ] = "Water Scr Show Size";
CHAR szWaterScrPullQ[ ] = "Water Scr PullQ";
CHAR szWaterScrDampQ[ ] = "Water Scr DampQ";
CHAR szWaterScrRadius[ ] = "Water Scr Radius";
CHAR szWaterScrStrength[ ] = "Water Scr Strength";
CHAR szWaterScrFrequency[ ] = "Water Scr Frequency";
CHAR szWaterScrHeight[ ] = "Water Scr Height";
CHAR szWaterScrWindow[ ] = "Water Scr Window";
CHAR szWaterScrZoom[ ] = "Water Scr Zoom";
CHAR szWaterScrSlide[ ] = "Water Scr Slide";
CHAR szWaterScrPath[ ] = "Water Scr Path";
CHAR szWaterScrSpeed[ ] = "Water Scr Speed";
CHAR szWaterScrWaveLevel[ ] = "Water Scr Wave";
CHAR szIniFile[MAXFILELEN]; // .ini or registry file name
const LONG MIN_EXCULPATION = 1;
const LONG MAX_EXCULPATION = 128;
const LONG DEF_EXCULPATION = 16;
const LONG MIN_SHOWSIZE = 1;
const LONG MAX_SHOWSIZE = 128;
const LONG DEF_SHOWSIZE = 12;
const LONG MIN_PULLQ = 10;
const LONG MAX_PULLQ = 200;
const LONG DEF_PULLQ = 100;
const LONG MIN_DAMPQ = 0;
const LONG MAX_DAMPQ = 100;
const LONG DEF_DAMPQ = 1;
const LONG MIN_RADIUS = 1;
const LONG MAX_RADIUS = 100;
const LONG DEF_RADIUS = 6;
const LONG MIN_STRENGTH = 10;
const LONG MAX_STRENGTH = 10000;
const LONG DEF_STRENGTH = 600;
const LONG MIN_FREQUENCY = 10;
const LONG MAX_FREQUENCY = 100;
const LONG DEF_FREQUENCY = 50;
const LONG MIN_WAVE_LEVEL = 1;
const LONG MAX_WAVE_LEVEL = 10;
const LONG DEF_WAVE_LEVEL = 1;
const LONG DEF_WINDOW = 0;
const LONG DEF_ZOOM = 1;
const LONG DEF_SLIDE = 1;
const char DEF_PATH[] = "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片";
const LONG MIN_UPDATE_SPEED = 10;
const LONG MAX_UPDATE_SPEED = 1000;
const LONG DEF_UPDATE_SPEED = 32;
LONG lExculpation;
LONG lShowSize;
LONG lPullQ;
LONG lDampQ;
LONG lRadius;
LONG lStrength;
LONG lFrequency;
LONG lWaveLevel;
LONG lWindow;
LONG lZoom;
LONG lSlide;
char szPath[4096];
LONG lSpeed;
CFileNameList fnlList;
int g_iWavNum = 6;
LPSTR g_lpstrWave[] =
{
"IDR_WAVE1"
,"IDR_WAVE2"
,"IDR_WAVE3"
,"IDR_WAVE4"
,"IDR_WAVE5"
,"IDR_WAVE6"
};
BOOL PlayResource(LPSTR lpName)
{
BOOL bRtn;
LPVOID lpRes;
HRSRC hResInfo;
HGLOBAL hRes;
// Find the WAVE resource.
hResInfo = FindResource(hMainInstance, lpName, "WAVE");
if (hResInfo == NULL)
return FALSE;
// Load the WAVE resource.
hRes = LoadResource(hMainInstance, hResInfo);
if (hRes == NULL)
return FALSE;
// Lock the WAVE resource and play it.
lpRes = LockResource(hRes);
if (lpRes != NULL)
{
bRtn = sndPlaySound(LPCSTR(lpRes), SND_MEMORY | SND_ASYNC |
SND_NODEFAULT);
UnlockResource(hRes);
}
else
bRtn = 0;
// Free the WAVE resource and return success or failure.
FreeResource(hRes);
return bRtn;
}
int g_iScreencx;
int g_iScreency;
CWaterSurf g_waterSurf;
void CALLBACK EXPORT TimerProc(
HWND hWnd, // handle of CWnd that called SetTimer
UINT nMsg, // WM_TIMER
UINT nIDEvent, // timer identification
DWORD dwTime // system time
)
{
static cx, cy;
static ecx, ecy;
switch(nIDEvent)
{
case 1:
::InvalidateRect(hWnd, NULL, false);
break;
case 2:
{
int dx = 0, dy = 0;
float zoomRatex = 1.0f;
float zoomRatey = 1.0f;
fnlList.Rand();
CDC DCDesktop;
DCDesktop.Attach(::GetDC(NULL));
if(lShowSize > lExculpation)
{
lShowSize = lExculpation;
}
g_waterSurf.SetGridSize(lShowSize);
if(lSlide && fnlList.Count())
{
CImage img;
if(FAILED(img.Load(fnlList.GetFileName())))
{
if(lZoom)
{
g_waterSurf.SetImage(0
,0
,cx, cy, &DCDesktop, true);
zoomRatex = (ecx - 1) * lShowSize / float(cx);
zoomRatey = (ecy - 1) * lShowSize / float(cy);
}
else
{
dx = (cx - (ecx - 1) * lShowSize) / 2;
dy = (cy - (ecy - 1) * lShowSize) / 2;
g_waterSurf.SetImage(dx
,dy
,(ecx) * lShowSize, (ecy) * lShowSize, &DCDesktop, false);
}
}
CDC tdc;
tdc.CreateCompatibleDC(&DCDesktop);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&DCDesktop, img.GetWidth(), img.GetHeight());
tdc.SelectObject(&bmp);
img.BitBlt(HDC(tdc), 0, 0, SRCCOPY);
if(lZoom)
{
g_waterSurf.SetImage(0
,0
,img.GetWidth(), img.GetHeight(), &tdc, true);
zoomRatex = (ecx - 1) * lShowSize / float(img.GetWidth());
zoomRatey = (ecy - 1) * lShowSize / float(img.GetHeight());
}
else
{
dx = (img.GetWidth() - (ecx - 1) * lShowSize) / 2;
dy = (img.GetHeight() - (ecy - 1) * lShowSize) / 2;
g_waterSurf.SetImage(dx
,dy
,(ecx) * lShowSize, (ecy) * lShowSize, &tdc, false);
}
}
}
break;
default:
break;
}
}
LRESULT CALLBACK ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static cx, cy;
static ecx, ecy;
switch (message)
{
case WM_CREATE:
{
::g_iScreencx = ::GetSystemMetrics(SM_CXSCREEN);
::g_iScreency = ::GetSystemMetrics(SM_CYSCREEN);
// Retrieve the application name from the .rc file.
LoadString(hMainInstance, idsAppName, szAppName,
80 * sizeof(TCHAR));
// Retrieve the .ini (or registry) file name.
LoadString(hMainInstance, idsIniFile, szIniFile,
MAXFILELEN * sizeof(TCHAR));
lExculpation = GetPrivateProfileInt(szAppName, szWaterScrExculpation,
DEF_EXCULPATION, szIniFile);
lShowSize = GetPrivateProfileInt(szAppName, szWaterScrShowSize,
DEF_SHOWSIZE, szIniFile);
lPullQ = GetPrivateProfileInt(szAppName, szWaterScrPullQ,
DEF_PULLQ, szIniFile);
lDampQ = GetPrivateProfileInt(szAppName, szWaterScrDampQ,
DEF_DAMPQ, szIniFile);
lRadius = GetPrivateProfileInt(szAppName, szWaterScrRadius,
DEF_RADIUS, szIniFile);
lStrength = GetPrivateProfileInt(szAppName, szWaterScrStrength,
DEF_STRENGTH, szIniFile);
lFrequency = GetPrivateProfileInt(szAppName, szWaterScrFrequency,
DEF_FREQUENCY, szIniFile);
lWaveLevel = GetPrivateProfileInt(szAppName, szWaterScrWaveLevel,
DEF_WAVE_LEVEL, szIniFile);
lWindow = GetPrivateProfileInt(szAppName, szWaterScrWindow,
DEF_WINDOW, szIniFile);
lZoom = GetPrivateProfileInt(szAppName, szWaterScrZoom,
DEF_ZOOM, szIniFile);
lSlide = GetPrivateProfileInt(szAppName, szWaterScrSlide,
DEF_SLIDE, szIniFile);
GetPrivateProfileString(szAppName, szWaterScrPath,
DEF_PATH, szPath, 4095, szIniFile);
lSpeed = GetPrivateProfileInt(szAppName, szWaterScrSpeed,
DEF_UPDATE_SPEED, szIniFile);
::SetCurrentDirectory(szPath);
fnlList.FromPath(szPath, "*.jpg");
fnlList.FromPath(szPath, "*.jpe");
fnlList.FromPath(szPath, "*.jpeg");
fnlList.FromPath(szPath, "*.jfif");
fnlList.FromPath(szPath, "*.png");
fnlList.FromPath(szPath, "*.bmp");
fnlList.Rand();
#ifdef DEBUG
char ts[1024];
sprintf
- 1
- 2
- 3
- 4
前往页