代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
屏幕下雪
作者:
严航
/ 发布于
2013/2/17
/
505
#include <windows.h> #include <time.h> const int ScrnWidth=1024; const int ScrnHight=768; const long SnowCol =0xFEFFFE; const long SnowColDown =0xFFFFFF; const long SnowColDuck =0xFFDDDD; const int SnowNum = 500; const int ID_TIMER = 1; const char g_szClassName[] = "myWindowClass"; typedef struct POINTAPI { long x; long y; }a; static HDC hDC1; static struct POINTAPI pData[500]; static long pColor[500]; static int Vx,Vy,PVx,PVy,timecont; long Abs(long num) { if(num>=0)return(num); else return(-num); } int Random(int max) { return(rand()%max); } int InitP(int i) { pData[i].x=Random(ScrnWidth); pData[i].y = Random(5); pColor[i] = GetPixel(hDC1, pData[i].x, pData[i].y); return 0; } long GetContrast(int i) { long ColorCmp; long tempR; long tempG; long tempB; int Slope; if(PVy!=0) Slope = PVx / PVy; else Slope = 2; if(Slope==0) ColorCmp = GetPixel(hDC1, pData[i].x, pData[i].y + 1); else if(Slope > 1) ColorCmp = GetPixel(hDC1, pData[i].x + 1, pData[i].y + 1); else ColorCmp = GetPixel(hDC1, pData[i].x - 1, pData[i].y + 1); if(ColorCmp==SnowCol)return 0; tempB = Abs((ColorCmp>>16)&0xff - (pColor[i]>>16)&0xff); tempG = Abs((ColorCmp>>8)&0xff - (pColor[i]>>8)&0xff); tempR = Abs((ColorCmp)&0xff - (pColor[i])&0xff); //return(tempR * 0.114 + tempG * 0.587 + tempB * 0.299); return((tempR + tempG + tempB) / 3); } void DrawP(void) { int i; // srand(time(0)); for(i=0;i<SnowNum;i++) { if(pColor[i]!=SnowCol&&pColor[i]!=-1)SetPixel(hDC1, pData[i].x, pData[i].y, pColor[i]); PVx = Random(2) - 1 + Vx * (i % 3); PVy = Vy * (i % 3 + 1); pData[i].x = pData[i].x + PVx; pData[i].y = pData[i].y + PVy; pColor[i] = GetPixel(hDC1, pData[i].x, pData[i].y); if(pColor[i] ==-1)InitP(i); else if(pColor[i]!=SnowCol) if (Random(16) > 5 || GetContrast(i) < 50)SetPixel(hDC1, pData[i].x, pData[i].y, SnowCol); else { SetPixel(hDC1, pData[i].x, pData[i].y - 1, SnowColDuck); SetPixel(hDC1, pData[i].x - 1, pData[i].y, SnowColDuck); SetPixel(hDC1, pData[i].x + 1, pData[i].y, SnowColDown); InitP(i); } }} LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_TIMER: { if(timecont>200) { timecont=0; Vx = Random(4) - 2; Vy = Random(2) + 2; } else timecont+=1; DrawP(); } break; case WM_CREATE: { int j; srand(time(0)); Vx = Random(4) - 2; Vy = Random(2) + 2; for(j = 0;j<SnowNum;j++) { pData[j].x = Random(ScrnWidth); pData[j].y = Random(ScrnHight); pColor[j] = GetPixel(hDC1, pData[j].x, pData[j].y); } SetTimer(hwnd, ID_TIMER, 10, NULL); hDC1 = GetDC(0); timecont=0; } break; case WM_CLOSE: ReleaseDC(0, hDC1); DestroyWindow(hwnd); break; case WM_DESTROY: KillTimer(hwnd, ID_TIMER); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG msg; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) { MessageBox(NULL, "窗体注册失败!", "错误!", MB_ICONEXCLAMATION | MB_OK); return 0; } hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, g_szClassName, "desktop snowing...... ", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL); if(hwnd == NULL) { MessageBox(NULL, "窗体创建失败!", "错误!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
试试其它关键字
屏幕下雪程序
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
严航
贡献的其它代码
(
1
)
.
屏幕下雪
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3