//////////////////////////////////////////////////
// 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 stream
zangchang
- 粉丝: 4
- 资源: 23
最新资源
- 带载流子密度的双温模型matlab,电子晶格温度,电子密度,飞秒激光源模拟,有限元法解偏微分方程 德鲁德模型,带载流子密度变化
- GP026-仓库系统.zip
- HttpCanary_3.3.6.apk
- 线控制动系统仿真 Carsim和Simulink联合仿真线控制动系统BBW-EMB系统 包含简单的制动力分配和四个车轮的线控制动机构 四个车轮独立BLDCM三环PID闭环制动控制,最大真实还原线
- Comsol脉冲涡流无损检测仿真 图一:脉冲涡流仿真,检出电压信号 图二:脉冲涡流模型 图三:磁通密度模 图四:磁通密度模
- CC2530无线zigbee裸机代码实现光敏和热敏传感器数值读取.zip
- CC2530无线zigbee裸机代码实现继电器的控制.zip
- CC2530无线zigbee裸机代码实现看门口狗Watch Dog使用.zip
- CC2530无线zigbee裸机代码实现控制步进电机正反转.zip
- CC2530无线zigbee裸机代码实现人体红外传感器数值读取.zip
- CC2530无线zigbee裸机代码实现睡眠定时器唤醒系统.zip
- CC2530无线zigbee裸机代码实现外部中断控制LED开关.zip
- CC2530无线zigbee裸机代码实现外部中断控制流水灯.zip
- 基于51单片机的污水处理厂气体检测报警系统(protues仿真)-毕业设计
- CC2530无线zigbee裸机代码实现温度传感器DS18B20数值读取.zip
- CC2530无线zigbee裸机代码实现温湿度传感器DHT11数值读取.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页