这里写目录标题
需求
- 需求
- 准备
- 程序
- huawei.h
- huawei.c
- 运行图
- 后续
有智能手表的人都知道,前段时间的“太空人表盘”非常火热。那么我们也可以自己动手来制作一款太空人表盘。
准备- Visual Studio 2019
- EasyX Graphics Library :Visual C++ 的免费绘图库
#ifndef _HUAWEI_H_
#define _HUAWEI_H_
#include
void SetWindowNewStyle(int w, int h)
{
// 去掉标题
SetWindowLong(GetHWnd(), GWL_STYLE, GetWindowLong(GetHWnd(), GWL_STYLE) & ~WS_CAPTION);
// 初始化界面为圆形
SetWindowRgn(GetHWnd(), CreateEllipticRgn(0, 0, w, h), true);
}
//png透明贴图
void drawImg(IMAGE* pimg, int x, int y)
{
// 变量初始化
DWORD* dst = GetImageBuffer();
DWORD* src = GetImageBuffer(pimg);
int dst_width = ::getwidth(); //窗口宽高
int dst_height = ::getheight();
int _w = pimg->getwidth();
int _h = pimg->getheight();
// 计算贴图的实际长宽
int iwidth = (x + _w > dst_width) ? dst_width - x : _w; // 处理超出右边界
int iheight = (y + _h > dst_height) ? dst_height - y : _h; // 处理超出下边界
if (x tm_wday], p->tm_mon + 1, p->tm_mday);
outtextxy(WIN_HALF + 110, WIN_HALF + 10, fileName);
// 获取字体
setTextStyle(100, 40, "Arial");
char szBuf[40] = { 0 };
sprintf_s(szBuf, "%d:%02d", p->tm_hour, p->tm_min);
outtextxy(105, 120, szBuf);
// 秒
setTextStyle(55, 23, "Arial");
sprintf(szBuf, "%02d", p->tm_sec);
outtextxy(335, 160, szBuf);
}
int main()
{
initgraph(WIN_SIZE, WIN_SIZE/*,EW_SHOWCONSOLE*/);
SetWindowNewStyle(WIN_SIZE, WIN_SIZE);
loadImg();
BeginBatchDraw();//双缓冲 防止闪屏
while (true)
{
gameDraw();
animation();
mouseEvent();
FlushBatchDraw();
}
EndBatchDraw();
return 0;
}
我将工程文件放在这里,可以自行下载。
运行图如果想了解更多物联网、智能家居项目知识,可以关注我的程序设计专栏。 或者关注公众号。
编写不易,感谢支持。