“This is the fourth day of my participation in the Gwen Challenge.
demand
As anyone who owns a smartwatch knows, the “Astronaut dial” was very hot these days. Then we can make an astronaut dial ourselves.
To prepare
- Visual Studio 2019
- EasyX Graphics Library: Visual C++ Graphics Library
The program
huawei.h
#ifndef _HUAWEI_H_ #define _HUAWEI_H_ #include<graphics.h> void SetWindowNewStyle(int w, Int h) {// SetWindowLong(GetHWnd(), GWL_STYLE, GetWindowLong(GetHWnd(), GWL_STYLE) & ~WS_CAPTION); SetWindowRgn(GetHWnd(), CreateEllipticRgn(0, 0, w, h), true); 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 < 0) {SRC += -x; iwidth -= -x; x = 0; } // handle beyond the left boundary if (y < 0) {SRC += (_w * -y); iheight -= -y; y = 0; DST += (dST_width * y + x); For (int iy = 0; iy < iheight; iy++) { for (int ix = 0; ix < iwidth; ix++) { byte a = (byte)(src[ix] >> 24); If (a > 100) {DST [ix] = SRC [ix];}} DST += dST_width; SRC += _w;}} // After removing the window title, Void mouseEvent() {static POINT WndPtSize; static bool isMove = false; if (MouseHit()) {MOUSEMSG MSG = GetMouseMsg(); if (msg.umsg == WM_LBUTTONDOWN) {// Get the coordinates of the window relative to the upper left corner of the screen, RECT wndRect; GetWindowRect(GetHWnd(), Wndptsize.x = curpos.x -; wndptSize.x = curpos.x - Y = curpos.y - wndRect.top; isMove = true;} else if (msg.umsg == WM_LBUTTONUP)// } else if (msg.umsg == WM_MOUSEMOVE) {if (isMove) {POINT CursorPos; GetCursorPos(&cursorpos); * @hwnd: window handle * @hwNdinsertafter: Window z order HWND_TOPMOST {in front, in front of any top window} * @x, y: The new position in the upper left corner of the window (relative to the screen) */ SetWindowPos(GetHWnd(), HWND_TOPMOST, cursorpos.x -wndptsie.x, CursorPos.y - WndPtSize.y, 0, 0, Y //printf("%d %d\n",); // cursorpos.x-wndptsize. x // Get the coordinates of the top left corner of the current window relative to the screen // cursorpos.y-wndptsize. CursorPos.x - WndPtSize.x, Y);}} else if (msg.umsg == WM_RBUTTONDOWN)// Right click {exit(0);}}} #endif //!_TOOLS_H_Copy the code
huawei.c
#include <stdio.h> #include <time.h> #include "huawei.h" #include <mmsystem.h> #pragma comment(lib,"winmm.lib") #pragma Warning (disable:4996) /* 1, text font setting 2, IMAGE animation 3, draw dial */ #define WIN_SIZE 500 #define WIN_HALF (WIN_SIZE/2) // Window half IMAGE spaceMan[59]; IMAGE other[6]; Const char * week [7] = {" day ", "a", "2", "three", "four", "five", "six"}; void setTextStyle(int height, int width, const char *faceName) { LOGFONT f = { 0 }; f.lfHeight = height; f.lfWidth = width; f.lfQuality = ANTIALIASED_QUALITY; strcpy(f.lfFaceName, faceName); settextstyle(&f); Void loadImg() {McISendString ("D:\ VS\ works \images/ wind blowing ", NULL, 0, NULL); void loadImg() {McISendString ("D:\ VS\ works \images/ wind blowing ", NULL, 0, NULL); McISendString ("D:\\VS\\ works \\ intelligent dial \\images/ wind blowing ", NULL, 0, NULL); char fileName[50] = { 0 }; for (int i = 0; i < 30; i++) { sprintf_s(fileName, "./images/guoguoxiaoshidi (%d).jpeg", i + 1); loadimage(spaceMan + i, fileName, 140, 130); } loadimage(&other[0], "./images/xinlv.jpg", 60, 60); / / heart rate loadimage (& other [1], the ". / images/sun. JPG ", 40, 40). / / the sun loadimage (& other [2], ". / images/shoes. JPG ", 40, 40). / / shoes loadimage (& other [3], ". / images/shang. JPG ", 30, 30); / / up-arrow loadimage (& other [4], ". / images/xia. JPG ", 30, 30); // Down arrow loadimage(&other[5], "./images/rocket.jpg", 40, 40); Void animation() {static int index = 0; //[0~59) putimage(175, 210, If (t2-t1 > 20) {index = (index + 1) % 30; spaceMan + index); static DWORD t1; DWORD t2 = clock(); }} void gameDraw() {setBkcolor (RGB(255, 0, 0)); clearDevice (); // Set the border color setlinestyle(PS_SOLID, 30); setFillColor (RGB(255, 255, 255));// Set the circle fillellipse(0, 0, WIN_SIZE, // Draw a circle // Draw a line setlinestyle(PS_SOLID, 4); setlinecolor(BLACK); // Top vertical line(win_half-30, 20, win_half-30, // line x2 (win_half-195, win_half-120, WIN_HALF + 195, win_half-120); line(win_half-195, WIN_HALF + 120, win_half-120); // x3 line(WIN_HALF + 80, WIN_HALF + 120, WIN_HALF + 80, WIN_HALF + 175); line(WIN_HALF + 80, WIN_HALF + 175, WIN_HALF - 60, WIN_HALF + 175); line(WIN_HALF - 60, WIN_HALF + 175, win_half-60, WIN_HALF + 175 + 48); setbkMode (TRANSPARENT); "Arial"); settextcolor(BLACK); outtextxy(WIN_HALF - 155, 75, "90%"); drawImg(other + 5, WIN_HALF - 90, Putimage (win_half-90, 35, other + 5); setTextStyle(25, 15, "boldface "); outtextxy(win_half-25, 35, "Good air "); setTextStyle(25, 13, "宋体"); outtextxy(win_half-25, 65," sunny "); outtextxy(win_half-25, 95, "sunny ") "25 ℃); outtextxy (WIN_HALF + 38, 65," 26 ° "); outtextxy (WIN_HALF + 38, 95, "17 °"); drawImg (other + 4, WIN_HALF + 73, DrawImg (other + 1, WIN_HALF + 105, drawImg(other + 1, WIN_HALF + 105, drawImg(other + 1, WIN_HALF + 105, drawImg); Putimage (WIN_HALF + 73, 60, other + 4); putimage(WIN_HALF + 73, 90, other + 3); Other + 1); // lower part of setTextStyle(37, 17, "宋体"); outtextxy(100, WIN_HALF + 130, "sleep "); outtextxy(WIN_HALF + 90, WIN_HALF) WIN_HALF + 130, "distance "); outTextxy (50, win_half-40," flat hill "); setTextStyle(40, 15, "Arial"); OutTextxy (185, WIN_HALF + 125, "flat hill ") "7h30m"); outtextxy(215, WIN_HALF + 180, "9.88km"); intermediate // heart rate setTextStyle(25, 13, "宋体"); outtextxy(60, WIN_HALF + 30, 60, WIN_HALF + 30) DrawImg (&other[0], 65, WIN_HALF + 50); // Putimage (65, WIN_HALF + 50, other + 0); "Arial"); outtextxy(135, WIN_HALF + 60, "92"); // drawImg(&other[2], WIN_HALF + 65, WIN_HALF + 65); putimage(WIN_HALF + 65, WIN_HALF + 65, &other[2]); outtextxy(WIN_HALF + 125, WIN_HALF + 75, Struct tm* p = localtime(&timep); struct tm* p = localtime(&timep); Char fileName[40] = {0}; sprintf_s(fileName, "% s % d % d - zhou", week [p - > tm_wday], p - > tm_mon + 1, p - > tm_mday); outtextxy (WIN_HALF WIN_HALF + 110, + 10, Char szBuf[40] = {0} sprintf_s(szBuf, "%d:% 02D ", p->tm_hour); // second 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; }Copy the code
running
subsequent
If you want to know more about the Internet of Things, you can follow my project practice column