//////////////////////////////////////////////////
// 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;
RECT m_BallPosRect;
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 *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);
ImageFromIDResource(IDR_BALL_FT,"PNG",pImageBallFt);
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;
SetRect(&m_ScreenRect,
0, 0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN));
SetRect(&m_BallPosRect,
m_ScreenRect.left + BALL_DIMTR / 2,
m_ScreenRect.top + BALL_DIMTR / 2,
m_ScreenRect.right - BALL_DIMTR / 2,
m_ScreenRect.bottom - BALL_DIMTR / 2);
m_limt_max = (BALL_DIMTR + MIN_DISTN / 3) * (BALL_DIMTR + MIN_DISTN / 3);
m_limt_min = (BALL_DIMTR - 2 * MIN_DISTN / 3) * (BALL_DIMTR - 2 * MIN_DISTN / 3);
hScreenBmp = CopyScreenToBitmap(&m_ScreenRect);
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,
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;
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;
}
return DefScreenSaverProc(hWnd,message,wParam,lParam);
}
BOOL WINAPI ScreenSaverConfigureDialog(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
return FALSE;
}
BOOL WINAPI RegisterDialogClasses(HANDLE hInstance)
{
return TRUE;
}
static void UpdateScreen(HWND hWnd, int Transparent)
{
static int count = 0;
if(m_ball_cnt < BALL_MAX)
{
if(count % NEXT_DISTN == 0)
m_ball_cnt++;
count++;
}
BallActPro();
BitBlt(
m_hdcMemory,
0, 0,
m_ScreenRect.right -m_ScreenRect.left,
m_ScreenRect.bottom -m_ScreenRect.top,
m_hdcScrBmp,
0,0,
SRCCOPY);
Graphics graph(m_hdcMemory);
for(int i = 0; i < m_ball_cnt && i < BALL_MAX; i++){
graph.DrawImage(
m_pImageball[i],
Rect((int)(m_balls[i].posx - m_ImageWidth / 2),
(int)(m_balls[i].posy - m_ImageHeight / 2),
m_ImageWidth, m_ImageHeight));
}
BitBlt(m_hdc,
0,0,
m_ScreenRect.right -m_ScreenRect.left,
m_ScreenRect.bottom -m_ScreenRect.top,
m_hdcMemory,
0,0,
SRCCOPY);
return;
}
static BOOL ImageFromIDResource(UINT nID, LPCTSTR sTR,Image * &pImg)
{
HRSRC hRsrc = ::FindResource (hMainInstance,MAKEINTRESOURCE(nID),sTR); // type
if (!hRsrc)
return FALSE;
// load resource into memory
DWORD len = SizeofResource(hMainInstance, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hMainInstance, hRsrc);
if (!lpRsrc)
return FALSE;
// Allocate global memory on which to create strea
评论14
最新资源