/*---------------------------------------
TUNNEL.C -- Palette Animation Demo
(c) Charles Petzold, 1998
---------------------------------------*/
#include <windows.h>
#define ID_TIMER 1
TCHAR szAppName [] = TEXT ("Tunnel") ;
TCHAR szTitle [] = TEXT ("Tunnel: Palette Animation Demo") ;
static LOGPALETTE * plp ;
HPALETTE CreateRoutine (HWND hwnd)
{
BYTE byGrayLevel ;
HPALETTE hPalette ;
int i ;
plp = malloc (sizeof (LOGPALETTE) + 255 * sizeof (PALETTEENTRY)) ;
// Initialize the fields of the LOGPALETTE structure
plp->palVersion = 0x0300 ;
plp->palNumEntries = 128 ;
for (i = 0 ; i < 128 ; i++)
{
if (i < 64)
byGrayLevel = (BYTE) (4 * i) ;
else
byGrayLevel = (BYTE) min (255, 4 * (128 - i)) ;
plp->palPalEntry[i].peRed = byGrayLevel ;
plp->palPalEntry[i].peGreen = byGrayLevel ;
plp->palPalEntry[i].peBlue = byGrayLevel ;
plp->palPalEntry[i].peFlags = PC_RESERVED ;
plp->palPalEntry[i + 128].peRed = byGrayLevel ;
plp->palPalEntry[i + 128].peGreen = byGrayLevel ;
plp->palPalEntry[i + 128].peBlue = byGrayLevel ;
plp->palPalEntry[i + 128].peFlags = PC_RESERVED ;
}
hPalette = CreatePalette (plp) ;
SetTimer (hwnd, ID_TIMER, 50, NULL) ;
return hPalette ;
}
void PaintRoutine (HDC hdc, int cxClient, int cyClient)
{
HBRUSH hBrush ;
int i ;
RECT rect ;
for (i = 0 ; i < 127 ; i++)
{
// Use a RECT structure for each of 128 rectangles
rect.left = i * cxClient / 255 ;
rect.top = i * cyClient / 255 ;
rect.right = cxClient - i * cxClient / 255 ;
rect.bottom = cyClient - i * cyClient / 255 ;
hBrush = CreateSolidBrush (PALETTEINDEX (i)) ;
// Fill the rectangle and delete the brush
FillRect (hdc, &rect, hBrush) ;
DeleteObject (hBrush) ;
}
return ;
}
void TimerRoutine (HDC hdc, HPALETTE hPalette)
{
static int iLevel ;
iLevel = (iLevel + 1) % 128 ;
AnimatePalette (hPalette, 0, 128, plp->palPalEntry + iLevel) ;
return ;
}
void DestroyRoutine (HWND hwnd, HPALETTE hPalette)
{
KillTimer (hwnd, ID_TIMER) ;
DeleteObject (hPalette) ;
free (plp) ;
return ;
}
Windows程序设计 Tunnel(源代码).rar
版权申诉
168 浏览量
2023-02-17
13:52:08
上传
评论
收藏 56KB RAR 举报
金枝玉叶9
- 粉丝: 125
- 资源: 7640
最新资源
- matlab的车牌识别系统源码毕业设计.zip
- 1990-2024年公司是否退市、上市公司退市名单、退市上市公司、退市公司(stata计算)
- matlab答题卡识别带界面GUI框架源码课程设计.zip
- 限流框架,使用固定时间滑动窗口+路径前缀匹配来完成对请求路径的限流 .zip
- 双指针 滑动窗口 二分查找 前缀和 位运算 模拟 分治 归并 链表 哈希表 字符串 栈 队列 优先级队列 BFS.zip
- MATLAB车牌计时计费系统源码课程设计.zip
- 全国31个省份2022-1990每万人拥有公共交通车辆人均城市道路绿地面积GDP常住人口无缺失
- 毕业设计基于matlab教室人数统计系统源码.zip
- 相对价格法计算市场分割指数或者一体化指数
- 基于滑动窗口的船舶避碰转向点数据挖掘模型.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈