恶心同学专用--1:中考倒计时
cpp单文件编译后加dll可用。仅Windows10。dll在资源里会给。#include windows.h #include stdio.h #include time.h /*#include windows.h int main() { HWND hWnd GetConsoleWindow(); ShowWindow(hWnd, SW_HIDE); //程序运行至此处后控制台窗口就会隐藏 //... return 0; }*/ #define WND_WIDTH 220 #define WND_HEIGHT 80 #define ALPHA_VALUE 100 // 更淡 全透明 #define TARGET_YEAR 2026 #define TARGET_MONTH 6 #define TARGET_DAY 30 static HWND g_hWnd; int GetLeftDays(void) { time_t now time(NULL); struct tm target {0}; target.tm_year TARGET_YEAR - 1900; target.tm_mon TARGET_MONTH - 1; target.tm_mday TARGET_DAY 1;/*heeo*/ target.tm_hour 0; target.tm_min 0; target.tm_sec 0; time_t tgt mktime(target); double diff difftime(tgt, now); return (int)(diff / (24 * 60 * 60)); } void DrawCountDown(HDC hdc) { char txt[128]; int day GetLeftDays(); if(day 0) sprintf(txt, 地生中考\n已到考试日); else sprintf(txt, 地生中考倒计时\n剩余 %d 天, day); // 纯大红色 SetTextColor(hdc, RGB(255, 0, 0));/*heeo*/ SetBkMode(hdc, TRANSPARENT); HFONT hFont CreateFontA(32,0,0,0,FW_BOLD, 0,0,0,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,DEFAULT_PITCH,方圆钢笔粉笔字);/*heeo*/ HGDIOBJ oldFont SelectObject(hdc, hFont); RECT rc {0,0,WND_WIDTH,WND_HEIGHT}; DrawTextA(hdc, txt, -1, rc, DT_CENTER|DT_VCENTER); SelectObject(hdc, oldFont); DeleteObject(hFont); } LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_PAINT: { PAINTSTRUCT ps; HDC hdc BeginPaint(hWnd, ps); DrawCountDown(hdc); EndPaint(hWnd, ps); return 0; } case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) { const char CLASS_NAME[] TransparentCountDown; WNDCLASS wc {0}; wc.lpfnWndProc WndProc; wc.hInstance hInst; wc.lpszClassName CLASS_NAME; // 关键窗口完全透明无背景 wc.hbrBackground (HBRUSH)(COLOR_WINDOW1); RegisterClass(wc); int scrW GetSystemMetrics(SM_CXSCREEN); int x scrW - WND_WIDTH/*0;/*ders*/; int y 5;/*acco*/ g_hWnd CreateWindowExA( WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TRANSPARENT, CLASS_NAME, , WS_POPUP | WS_VISIBLE, x, y, WND_WIDTH, WND_HEIGHT, NULL, NULL, hInst, NULL ); // 透明色抠除 整体淡透明 SetLayeredWindowAttributes(g_hWnd, COLOR_WINDOW1, ALPHA_VALUE, LWA_COLORKEY | LWA_ALPHA); SetWindowPos(g_hWnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE); MSG m; while(GetMessage(m,NULL,0,0)) { TranslateMessage(m); DispatchMessage(m); InvalidateRect(g_hWnd,NULL,TRUE); Sleep(1000); } return 0; }