//////////////////////////////////////////////////
// 1. 软件说明
// 七彩泡泡屏保 Vertion 1.0 Bate
// 2. 作成者
// 2010.04.08 臧義昌 QQ:545380311
//////////////////////////////////////////////////
#include <windows.h>
#include <math.h>
#include <time.h>
#include <scrnsave.h>
#include "resource.h"
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#endif
#include ".\\gdiplus\\Include\\gdiplus.h"
#pragma comment(lib, ".\\gdiplus\\lib\\gdiplus.lib")
#define BALL_MAX (12)
#define MIN_DISTN (6)
#define BALL_DIMTR (220)
#define NEXT_DISTN (100)
typedef struct
{
int posx, posy;
int verx, very;
int clrIndex;
}BALL;
using namespace Gdiplus;
static BOOL ImageFromIDResource(UINT nID,LPCTSTR sTR,Image * &pImg);
static HBITMAP CopyScreenToBitmap(LPRECT lpRect);
static void UpdateScreen(HWND hWnd, int Transparent=255);
static void BallActPro();
////////////////////////////////////////////
char szIniFileName[]="control.ini";
char szSection[32];
char szEntry[]="Slide Text:";
char SlideText[256];
////////////////////////////////////////////
HDC m_hdc;
HDC m_hdcMemory;
HDC m_hdcScrBmp;
RECT m_ScreenRect;//22屏幕尺寸范围
RECT m_BallPosRect;//22球中心的尺寸范围
int m_ImageWidth, m_ImageHeight;
int m_limt_max, m_limt_min;
ColorMatrix m_colorMatrix =
{
1.0f, 0.0f, 0.0f, 0.15f, 0.0f,
0.0f, 1.0f, 0.0f, 0.15f, 0.0f,
0.0f, 0.0f, 1.0f, 0.15f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};
float m_clrTable[BALL_MAX][3] =
{
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f,
0.0f, 0.0f, 0.5f,
0.5f, 0.5f, 0.0f,
0.5f, 0.0f, 0.5f,
0.0f, 0.5f, 0.5f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f,
0.0f, 0.0f, 0.5f,
0.5f, 0.5f, 0.0f,
0.5f, 0.0f, 0.5f,
0.0f, 0.5f, 0.5f,
};
BALL m_balls[BALL_MAX];
Image *m_pImageball[BALL_MAX];
int m_ball_cnt = 0;
LRESULT WINAPI ScreenSaverProc(HWND hWnd,UINT message, WPARAM wParam,LPARAM lParam)
{
static UINT timerID;
static ULONG_PTR gdiplusToken;
static HBITMAP hScreenBmp;
static HBITMAP hBitMap;
int i;
Color blank(0, 0, 0, 0);
Image *pImageBallBk = NULL;
//Image *pImageBallFt = NULL;
Image * pImageBallFt[BALL_MAX]={NULL} ;
//pImageBallFt=new (Image*)[BALL_MAX ];
Image *pImageLogo = NULL;
Image *pImageBlank = NULL;
Graphics *graph = NULL;
GdiplusStartupInput gdiplusStartupInput;
switch (message)
{
case WM_CREATE:
memset(m_balls, 0x00, sizeof(m_balls));
memset(m_pImageball, 0x00, sizeof(m_pImageball));
m_hdc = GetDC(hWnd);
m_hdcMemory = CreateCompatibleDC(m_hdc);
m_hdcScrBmp = CreateCompatibleDC(NULL);
//初始化gdiplus的环境
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
ImageFromIDResource(IDR_BALL_BK,"PNG",pImageBallBk);//22导入背景图片
ImageFromIDResource(IDR_BALL_FT1,"PNG",pImageBallFt[0]);//22导入图片
ImageFromIDResource(IDR_BALL_FT2,"PNG",pImageBallFt[1]);//22导入图片
ImageFromIDResource(IDR_BALL_FT3,"PNG",pImageBallFt[2]);//22导入图片
ImageFromIDResource(IDR_BALL_FT4,"PNG",pImageBallFt[3]);//22导入图片
ImageFromIDResource(IDR_BALL_FT5,"PNG",pImageBallFt[4]);//22导入图片
ImageFromIDResource(IDR_BALL_FT6,"PNG",pImageBallFt[5]);//22导入图片
ImageFromIDResource(IDR_BALL_FT7,"PNG",pImageBallFt[6]);//22导入图片
ImageFromIDResource(IDR_BALL_FT8,"PNG",pImageBallFt[7]);//22导入图片
ImageFromIDResource(IDR_BALL_FT9,"PNG",pImageBallFt[8]);//22导入图片
ImageFromIDResource(IDR_BALL_FT10,"PNG",pImageBallFt[9]);//22导入图片
ImageFromIDResource(IDR_BALL_FT11,"PNG",pImageBallFt[10]);//22导入图片
ImageFromIDResource(IDR_BALL_FT12,"PNG",pImageBallFt[11]);//22导入图片
ImageFromIDResource(IDR_LOGO,"PNG",pImageLogo);
m_ImageWidth = pImageBallBk->GetWidth();
m_ImageHeight = pImageBallBk->GetHeight();
ImageFromIDResource(IDR_BALL_BK,"PNG",pImageBlank);
graph = Graphics::FromImage(pImageBlank);
graph->Clear(blank);
delete graph;
graph = NULL;
//22创建屏幕矩形和Ball所在矩形范围
SetRect(&m_ScreenRect,
0, 0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN));
SetRect(&m_BallPosRect,
m_ScreenRect.left ,
m_ScreenRect.top ,
m_ScreenRect.right,
m_ScreenRect.bottom);
m_limt_max = (BALL_DIMTR + MIN_DISTN / 3) * (BALL_DIMTR + MIN_DISTN / 3);//22 ?
m_limt_min = (BALL_DIMTR - 2 * MIN_DISTN / 3) * (BALL_DIMTR - 2 * MIN_DISTN / 3);
hScreenBmp = CopyScreenToBitmap(&m_ScreenRect);
//22在界面绘制自己的logo
SelectObject(m_hdcScrBmp,hScreenBmp);
graph = Graphics::FromHDC(m_hdcScrBmp);
graph->DrawImage(
pImageLogo,
Rect(m_ScreenRect.right - pImageLogo->GetWidth() -100,
m_ScreenRect.bottom - pImageLogo->GetHeight() - 80,
pImageLogo->GetWidth(), pImageLogo->GetHeight()));
delete graph;
graph = NULL;
hBitMap = CreateCompatibleBitmap(
m_hdc,
m_ScreenRect.right -m_ScreenRect.left,
m_ScreenRect.bottom -m_ScreenRect.top);
SelectObject(m_hdcMemory, hBitMap);
srand(time(NULL));
for(i = 0; i < BALL_MAX; i++)
{
ImageAttributes imageAttributes;
m_balls[i].posx = m_ScreenRect.left - m_ImageWidth / 2;
m_balls[i].posy = m_ScreenRect.bottom + m_ImageHeight / 2;
m_balls[i].verx = rand()%3 + 1;
m_balls[i].very = -(rand()%3 + 1);
m_balls[i].clrIndex = i;
m_pImageball[i] = pImageBlank->Clone();
graph = Graphics::FromImage(m_pImageball[i]);
m_colorMatrix.m[4][0] = m_clrTable[m_balls[i].clrIndex][0];
m_colorMatrix.m[4][1] = m_clrTable[m_balls[i].clrIndex][1];
m_colorMatrix.m[4][2] = m_clrTable[m_balls[i].clrIndex][2];
//imageAttributes.SetColorMatrix(
// &m_colorMatrix,
// ColorMatrixFlagsDefault,
// ColorAdjustTypeBitmap);
graph->DrawImage(
pImageBallBk,
Rect(0, 0, m_ImageWidth, m_ImageHeight), // destination rectangle
0, 0, // upper-left corner of source rectangle
m_ImageWidth, // width of source rectangle
m_ImageHeight, // height of source rectangle
UnitPixel,
&imageAttributes);
graph->DrawImage(
pImageBallFt[i],
Rect(0, 0, m_ImageWidth, m_ImageHeight), // destination rectangle
0, 0, // upper-left corner of source rectangle
m_ImageWidth, // width of source rectangle
m_ImageHeight, // height of source rectangle
UnitPixel,
&imageAttributes);
//graph->DrawImage(
// pImageBallFt,
// Rect(0, 0, m_ImageWidth, m_ImageHeight), // destination rectangle
// 0, 0, // upper-left corner of source rectangle
// m_ImageWidth, // width of source rectangle
// m_ImageHeight, // height of source rectangle
// UnitPixel,
// &imageAttributes);
delete graph;
graph = NULL;
}
delete pImageBlank;
pImageBlank = NULL;
delete pImageBallBk;
pImageBallBk = NULL;
//delete pImageBallFt;
//pImageBallFt = NULL;
delete (pImageBallFt);
//pImageBallFt[BALL_MAX] ={ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
timerID=SetTimer(hWnd, 1, 20, NULL);
break;
case WM_ERASEBKGND:
OutputDebugString("/////////////////////////////////////////\n");
OutputDebugString("WM_ERASEBKGND\n");
OutputDebugString("/////////////////////////////////////////\n");
UpdateScreen(hWnd);
return 1;
case WM_TIMER:
UpdateScreen(hWnd);
break;
case WM_DESTROY:
KillTimer(hWnd,timerID);
for(i = 0; i < BALL_MAX; i++)
{
delete m_pImageball[i];
m_pImageball[i] = NULL;
}
GdiplusShutdown(gdiplusToken);
DeleteObject(hScreenBmp);
DeleteObject(hBitMap);
::ReleaseDC(hWnd,m_hdc);
m_hdc=NULL;
DeleteDC(m_hdcMemory);
m_hdcMemory=NULL;
DeleteDC(m_hdcScrBmp);
m_hdcScrBmp=NULL;
PostQuitMessage (0);
return 0;
}