WinAPI: SetTimer、KillTimer - 创建与移除高性能定时器

WinAPI:创建与移除高性能定时器
本文介绍了 WinAPI 中 SetTimer 和 KillTimer 函数,前者用于创建定时器,后者用于移除定时器。详细说明了函数的参数含义,如 SetTimer 的 hWnd、nIDEvent、uElapse 和 lpTimerFunc 等。还给出了创建和删除定时器的示例代码,包括回调函数的定义。
//创建定时器函数的声明:
SetTimer(
  hWnd: HWND;               {与定时器相关联的窗口句柄}
  nIDEvent: UINT;           {指定一个非 0 的定时器标识符}
  uElapse: UINT;            {指定间隔时间, 单位是毫秒}
  lpTimerFunc: TFNTimerProc {每到时间后, 要调用的函数的指针}
): UINT;                    {返回定时器标识符; 失败返回 0}

//移除定时器函数的声明:
KillTimer(
  hWnd: HWND;    {与定时器相关联的窗口句柄}
  uIDEvent: UINT {定时器标识符}
): BOOL;

//处理 WM_TIMER 消息的回调函数的格式:
TimerProc(
  hWnd: HWND;    {与定时器相关联的窗口句柄}
  uMsg: UINT;    {WM_TIMER 消息}
  idEvent: UINT; {定时器的标识符}
  Time: DWORD    {以世界时间公约格式(UTC)指定的系统时间}
);               {这是个过程, 无返回值}
应该先理解一下再举例:

SetTimer 的参数1: hWnd, 一般指定 Self.Handle 就可以了;

SetTimer 的参数2: nIDEvent 是某个定时器的标识符, 说明可以创建若干个定时器, 随便给个正整数即可;

SetTimer 的参数3: uElapse, 这相当于 VCL 中 Timer 类的 Interval 属性;

看来参数 1-3 还是非常简单, 不好理解的就是参数4: lpTimerFunc, 这是一个过程的地址.

任意一个过程的地址吗? 当然不是; 这个过程的参数结构是 Windows 系统规定的, 我们必须按规定去定义这个过程; 即使你用不到其中的参数也必须如此.
//举例:
var
  i: Integer;

//先定义回调函数
procedure MyTimerProc(hWnd: HWND; uMsg: UINT; idEvent: UINT; Time: DWORD);
begin
  Form1.Text := IntToStr(i);
  Inc(i);
end;

//创建定时器
procedure TForm1.Button1Click(Sender: TObject);
begin
  SetTimer(Handle, 1, 10, @MyTimerProc); {每 1/100 秒调用一次 MyTimerProc}
end;

//删除定时器
procedure TForm1.Button2Click(Sender: TObject);
begin
  KillTimer(Handle, 1); {创建时指定的定时器标识是 1, 这里必须要一致}
end;
//如果回调过程是窗体类的一个方法, 需要这样:
var
  i: Integer;

//先定义回调函数
procedure TForm1.MyTimerProc(hWnd: HWND; uMsg: UINT; idEvent: UINT; Time: DWORD);
begin
  Text := IntToStr(i);
  Inc(i);
end;

//创建定时器
procedure TForm1.Button1Click(Sender: TObject);
begin
  SetTimer(Handle, 1, 10, @TForm1.MyTimerProc); {每 1/100 秒调用一次 MyTimerProc}
end;

//删除定时器
procedure TForm1.Button2Click(Sender: TObject);
begin
  KillTimer(Handle, 1); {创建时指定的定时器标识是 1, 这里必须要一致}
end;

转载于:https://www.cnblogs.com/kevinGao/archive/2012/06/21/2605594.html

#define UNICODE #define _UNICODE #include <windows.h> #include <math.h> #include <wchar.h> // 宽字符支持 #define WIN_WIDTH 600 #define WIN_HEIGHT 500 #define BALL_RADIUS 10 #define GRAVITY 0.0008 #define REBOUND_FACTOR 0.5 #define GROUND_Y (WIN_HEIGHT - 150) // 地面高度 // 控件 ID #define IDC_HEIGHT_INPUT 201 // 高度输入框 #define IDC_BOUNCES_INPUT 202 // 次数输入框 #define IDC_SUBMIT_BUTTON 203 // 提交按钮 #define TIMER_ID 101 // 定时器 ID // 小球结构体 typedef struct { double x, y; // 小球位置 (像素) double vy; // 垂直速度 double maxHeight; // 当前反弹的最高高度 (像素) int bounces; // 当前反弹次数 int maxBounces; // 最大反弹次数 BOOL isActive; // 小球是否在运动状态 BOOL isFalling; // 小球是否处于下落状态、 double holdTime; // 停留时间(毫秒) } Ball; Ball ball; // 小球全局变量 double totalDistance = 0.0; // 小球累计总运动距离 double reboundHeights[100]; // 每次反弹高度记录 HWND heightInput; // 高度输入框句柄 HWND bouncesInput; // 次数输入框句柄 HWND submitButton; // 提交按钮句柄 HWND mainHwnd; // 主窗口句柄 HWND outputHwnd = NULL; // 结果窗口句柄 int scrollOffset = 0; // 当前滚动条的偏移量 int lineHeight = 20; // 每行内容的高度 int totalOutputHeight = 0; // 全部内容高度 SCROLLINFO scrollInfo; // 滚动条的状态 void InitializeBall(double initialHeightMeters, int maxBounces) { if (initialHeightMeters <= 0 || maxBounces <= 0) { return; // 防止异常参数导致错误初始化 } double initialHeightPixels = initialHeightMeters * 2.0; // 假设 1 米 = 2 像素 ball.x = WIN_WIDTH / 2.0; // 小球水平居中 ball.y = GROUND_Y - initialHeightPixels; // 小球从用户设置的高度开始下落 ball.vy = 0; // 初始速度为 0 ball.maxHeight = initialHeightPixels; // 最大位置为初始输入高度 ball.bounces = 0; // 当前反弹次数设为 0 ball.maxBounces = maxBounces; // 设置最大反弹次数 ball.isActive = TRUE; // 激活运动 ball.isFalling = TRUE; // 初始状态设为下落(不运动) ball.holdTime = 2000.0; // 在初始高度停留 2 秒 totalDistance = 0.0; // 总路程初始化为 0 memset(reboundHeights, 0, sizeof(reboundHeights)); // 清空反弹高度记录 } // 小球的物理逻辑更新 void UpdateBall(DWORD deltaTime) { if (!ball.isActive) return; // 如果小球处于非活动状态,直接返回 // 如果当前还有 "停留时间",则不更新下落状态 if (ball.holdTime > 0) { ball.holdTime -= deltaTime; // 减小停留时间 if (ball.holdTime <= 0) { ball.holdTime = 0; // 停留时间结束,开始正常运动 } return; // 返回,不执行后续更新运动逻辑 } if (ball.isFalling) { // 小球下落状态 ball.vy += GRAVITY * deltaTime; // 更新速度(v = v0 + gt) ball.y += ball.vy * deltaTime; // 更新位置(y = y0 + vt) if (ball.y >= GROUND_Y - BALL_RADIUS) { // 碰到底部地面 ball.y = GROUND_Y - BALL_RADIUS; // 确保小球停在地面 ball.isFalling = FALSE; // 切换为上升状态 totalDistance += ball.maxHeight; // 累加下落距离 ball.bounces++; if (ball.bounces <= ball.maxBounces) { // 如果反弹次数未达到上限 reboundHeights[ball.bounces - 1] = ball.maxHeight * REBOUND_FACTOR; // 记录反弹高度 totalDistance += reboundHeights[ball.bounces - 1]; // 累加反弹的上升距离 ball.maxHeight *= REBOUND_FACTOR; // 新的反弹高度是之前高度的一半 ball.vy = -sqrt(2 * GRAVITY * ball.maxHeight); // 更新为反向(向上)的初速度 } if (ball.bounces >= ball.maxBounces) { // 达到最大反弹次数,停止运动 ball.isActive = FALSE; } } } else { // 小球处于上升状态 ball.y += ball.vy * deltaTime; // 更新上升时的位置 ball.vy += GRAVITY * deltaTime; // 受到重力减速(逐渐变慢) if (ball.vy >= 0) { // 当速度大于等于零时(达到了最高点) ball.isFalling = TRUE; // 切换为下落状态 } } } // 绘制小球 void RenderBall(HDC hdc) { HBRUSH hBrush = CreateSolidBrush(RGB(139, 69, 19)); // 棕色小球 HBRUSH oldBrush = SelectObject(hdc, hBrush); Ellipse(hdc, (int)(ball.x - BALL_RADIUS), (int)(ball.y - BALL_RADIUS), (int)(ball.x + BALL_RADIUS), (int)(ball.y + BALL_RADIUS)); SelectObject(hdc, oldBrush); DeleteObject(hBrush); } // 绘制地面 void RenderGround(HDC hdc) { HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 128, 0)); // 绿色 HPEN oldPen = SelectObject(hdc, hPen); MoveToEx(hdc, 0, GROUND_Y, NULL); LineTo(hdc, WIN_WIDTH, GROUND_Y); SelectObject(hdc, oldPen); DeleteObject(hPen); } // 渲染整体场景 void RenderScene(HDC hdc) { RenderGround(hdc); // 绘制地面 RenderBall(hdc); // 绘制小球 } LRESULT CALLBACK OutputWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_SIZE: { // 在窗口大小调整时,设置滚动条范围 RECT clientRect; GetClientRect(hwnd, &clientRect); // 设置滚动条属性 totalOutputHeight = ball.bounces * lineHeight + 100; // 高度=反弹数量+顶部信息 int windowHeight = clientRect.bottom; scrollInfo.cbSize = sizeof(SCROLLINFO); scrollInfo.fMask = SIF_RANGE | SIF_PAGE; scrollInfo.nMin = 0; // 滚动条最小位置 0 scrollInfo.nMax = totalOutputHeight; // 滚动条最大位置=总高度 scrollInfo.nPage = windowHeight; // 可视区域高度=窗口高度 SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE); break; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); wchar_t buffer[256]; int offset = -scrollOffset; // 根据滚动偏移调整绘制位置 HFONT hFont = CreateFontW(18, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"SimSun"); // 使用宋体 HFONT oldFont = SelectObject(hdc, hFont); // 显示运动结束提示 swprintf(buffer, 256, L"小球运动结束"); TextOutW(hdc, 10, offset + 10, buffer, wcslen(buffer)); offset += lineHeight; // 显示总路程 swprintf(buffer, 256, L"小球总路程:%.2f 米", totalDistance / 2.0); TextOutW(hdc, 10, offset + 10, buffer, wcslen(buffer)); offset += lineHeight; // 显示每次反弹高度 for (int i = 0; i < ball.bounces; i++) { swprintf(buffer, 256, L"第 %d 次反弹高度:%.2f 米", i + 1, reboundHeights[i] / 2.0); TextOutW(hdc, 10, offset + 10, buffer, wcslen(buffer)); offset += lineHeight; } SelectObject(hdc, oldFont); DeleteObject(hFont); EndPaint(hwnd, &ps); break; } case WM_VSCROLL: { // 滚动条消息 int scrollDelta = 0; switch (LOWORD(wParam)) { case SB_LINEDOWN: // 用户点击向下箭头 scrollDelta = lineHeight; break; case SB_LINEUP: // 用户点击向上箭头 scrollDelta = -lineHeight; break; case SB_THUMBPOSITION: // 用户点击滚动条滑块 case SB_THUMBTRACK: // 用户拖动滚动条滑块 scrollDelta = HIWORD(wParam) - scrollOffset; break; } // 更新滚动偏移量 scrollOffset += scrollDelta; if (scrollOffset < 0) scrollOffset = 0; // 限制最小偏移 if (scrollOffset > totalOutputHeight - scrollInfo.nPage) // 限制最大偏移 scrollOffset = totalOutputHeight - scrollInfo.nPage; // 更新滚动条位置 scrollInfo.fMask = SIF_POS; scrollInfo.nPos = scrollOffset; SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE); // 触发窗口重绘 InvalidateRect(hwnd, NULL, TRUE); break; } case WM_DESTROY: outputHwnd = NULL; return 0; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } } void ShowOutputWindow(HINSTANCE hInstance) { if (outputHwnd != NULL) { // 如果结果窗口已经存在 InvalidateRect(outputHwnd, NULL, TRUE); // 强制刷新窗口内容 return; } // 定义结果窗口类名 const wchar_t OUTPUT_CLASS_NAME[] = L"OutputWindow"; WNDCLASSW wc = {0}; wc.lpfnWndProc = OutputWindowProc; // 设置结果窗口过程 wc.hInstance = hInstance; wc.lpszClassName = OUTPUT_CLASS_NAME; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // 注册窗口类 RegisterClassW(&wc); // 创建新结果窗口 outputHwnd = CreateWindowW( OUTPUT_CLASS_NAME, L"运动结果", WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, NULL, NULL, hInstance, NULL ); ShowWindow(outputHwnd, SW_SHOW); // 显示结果窗口 } // 主窗口过程函数 LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static DWORD lastTime = 0; switch (uMsg) { case WM_CREATE: // 添加输入控件 CreateWindow(L"STATIC", L"初始高度 (米):", WS_VISIBLE | WS_CHILD, 20, WIN_HEIGHT - 140, 110, 30, hwnd, NULL, NULL, NULL); heightInput = CreateWindow(L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_NUMBER, 130, WIN_HEIGHT - 140, 100, 30, hwnd, (HMENU)IDC_HEIGHT_INPUT, NULL, NULL); CreateWindow(L"STATIC", L"落地次数:", WS_VISIBLE | WS_CHILD, 20, WIN_HEIGHT - 100, 110, 30, hwnd, NULL, NULL, NULL); bouncesInput = CreateWindow(L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_NUMBER, 130, WIN_HEIGHT - 100, 100, 30, hwnd, (HMENU)IDC_BOUNCES_INPUT, NULL, NULL); submitButton = CreateWindow(L"BUTTON", L"提交", WS_VISIBLE | WS_CHILD, 250, WIN_HEIGHT - 120, 100, 40, hwnd, (HMENU)IDC_SUBMIT_BUTTON, NULL, NULL); SetTimer(hwnd, TIMER_ID, 10, NULL); // 设置定时器,每 10ms 刷新 return 0; case WM_COMMAND: if (LOWORD(wParam) == IDC_SUBMIT_BUTTON) { // 提交按钮处理 wchar_t heightBuffer[256], bouncesBuffer[256]; GetWindowText(heightInput, heightBuffer, 256); // 获取输入高度 GetWindowText(bouncesInput, bouncesBuffer, 256); // 获取反弹次数 // 转换用户输入 double height = _wtof(heightBuffer); // 输入高度转换为浮点数 int bounces = _wtoi(bouncesBuffer); // 输入反弹次数转换为整数 // 验证输入合法性 if (height <= 0 || height > 150) { // 限制高度范围为 0 ~ 150 MessageBox(hwnd, L"高度超出范围!请输入 0 到 150 之间的数值。", L"输入无效", MB_ICONERROR); return 0; } if (bounces < 1) { // 限制反弹次数为大于等于 1 的正整数 MessageBox(hwnd, L"落地次数无效!请输入大于等于 1 的正整数。", L"输入无效", MB_ICONERROR); return 0; } // 如果小球当前正在运动,则重置运动 if (ball.isActive) { KillTimer(hwnd, TIMER_ID); // 停止原来的定时器,避免重复更新 } // 初始化小球参数,重新开始模拟 InitializeBall(height, bounces); // 初始化小球参数 SetTimer(hwnd, TIMER_ID, 10, NULL); // 启动定时器,进行物理更新 InvalidateRect(hwnd, NULL, TRUE); // 强制刷新主窗口 } break; case WM_TIMER: if (wParam == TIMER_ID) { // 定时器触发响应 DWORD currentTime = GetTickCount(); // 当前时间戳 DWORD deltaTime = currentTime - lastTime; // 时间差计算 lastTime = currentTime; if (ball.isActive) { // 如果小球处于活动状态 UpdateBall(deltaTime); // 更新物理状态 RECT groundAbove = { 0, 0, WIN_WIDTH, GROUND_Y }; InvalidateRect(hwnd, &groundAbove, TRUE); // 刷新窗口地面以上部分 } else { KillTimer(hwnd, TIMER_ID); // 停止定时器 ShowOutputWindow((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE)); // 显示结果窗口 } } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); RenderScene(hdc); // 渲染当前场景(包括小球和地面) EndPaint(hwnd, &ps); break; } case WM_DESTROY: KillTimer(hwnd, TIMER_ID); PostQuitMessage(0); return 0; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { const wchar_t CLASS_NAME[] = L"BouncingBallWindow"; WNDCLASS wc = {0}; wc.lpfnWndProc = MainWindowProc; wc.hInstance = hInstance; wc.lpszClassName = CLASS_NAME; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); if (!RegisterClass(&wc)) return 0; mainHwnd = CreateWindow( CLASS_NAME, L"小球反弹模拟", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, WIN_WIDTH, WIN_HEIGHT, NULL, NULL, hInstance, NULL); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }改一下代码规范
最新发布
08-08
#include <windows.h> #define TIMER_ID 1 // 颜色序列常量定义 COLORREF colors[] = { RGB(255, 0, 0), // 红 RGB(255, 165, 0), // 橙 RGB(255, 255, 0), // 黄 RGB(0, 255, 0), // 绿 RGB(0, 255, 255), // 青 RGB(0, 0, 255), // 蓝 RGB(148, 0, 211) // 紫 }; int colorIndex = -1; // 当前使用的颜色索引初始化为无效值(-1) LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = "HelloWin"; HWND hwnd; MSG msg; WNDCLASS wndclass; // 设置WNDCLASS结构体... wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = (WNDPROC)WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = GetStockBrush(WHITE_BRUSH); // 初始白色背景刷子 wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; if (!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT("The Windows Program"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); SetTimer(hwnd, TIMER_ID, 500, NULL); // 启动周期性事件(每隔半秒钟) while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } KillTimer(hwnd, TIMER_ID); // 停止定时器 return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch(message){ case WM_CREATE: break; case WM_PAINT: { hdc = BeginPaint(hwnd,&ps); // 获取客户区矩形区域信息. GetClientRect(hwnd,&rect); ++colorIndex %= sizeof(colors)/sizeof(COLORREF); // 自增当前颜色索引 FillRect(hdc,&rect,(HBRUSH)CreateSolidBrush(colors[colorIndex])); DeleteObject((HGDIOBJ)(HPEN)SelectObject(hdc,GetStockPen(DC_PEN))); EndPaint(hwnd,&ps); }break; case WM_DESTROY: PostQuitMessage(0); break; default : return DefWindowProc(hwnd,message,wParam,lParam); } return 0; }
03-12
``` #include <windows.h> #include <bits/stdc++.h> #define UNICODE #define _UNICODE // 双缓冲绘图 HDC hdcBuffer; HBITMAP hbmBuffer; HBITMAP hOldBmp; RECT rect; // 颜色转换函数 COLORREF HSLtoRGB(float h, float s, float l) { float c = (1 - fabs(2 * l - 1)) * s; float x = c * (1 - fabs(fmod(h / 60.0f, 2) - 1)); float m = l - c / 2.0f; float r, g, b; if (h < 60) { r = c; g = x; b = 0; } else if (h < 120){ r = x; g = c; b = 0; } else if (h < 180){ r = 0; g = c; b = x; } else if (h < 240){ r = 0; g = x; b = c; } else if (h < 300){ r = x; g = 0; b = c; } else { r = c; g = 0; b = x; } return RGB((r + m) * 255, (g + m) * 255, (b + m) * 255); } // 窗口过程 LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); static float t = 0.0f; t += 0.01f; hdcBuffer = CreateCompatibleDC(hdc); GetClientRect(hwnd, &rect); hbmBuffer = CreateCompatibleBitmap(hdc, rect.right, rect.bottom); hOldBmp = (HBITMAP)SelectObject(hdcBuffer, hbmBuffer); FillRect(hdcBuffer, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH)); const float a = 50.0f; for(float ii = 0; ii < 6.283f; ii += 0.001f) { float r = a * (1 - sin(ii)); float scale = 1.0f + 0.1f * sin(t * 5.0f); float phase = t * 50.0f; int x = (int)(scale * r * cos(ii) + rect.right/2); int y = (int)(-scale * r * sin(ii) + rect.bottom/2); SetPixel(hdcBuffer, x, y, HSLtoRGB(fmod(ii*30 + phase, 360), 1.0f, 0.5f)); } BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcBuffer, 0, 0, SRCCOPY); SelectObject(hdcBuffer, hOldBmp); DeleteDC(hdcBuffer); DeleteObject(hbmBuffer); EndPaint(hwnd, &ps); InvalidateRect(hwnd, NULL, FALSE); break; } case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } // 主函数 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEXW wc = {0}; wc.cbSize = sizeof(WNDCLASSEXW); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.hInstance = hInst; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszClassName = L"HeartWindow"; if(!RegisterClassExW(&wc)) return 0; HWND hwnd = CreateWindowExW( 0, L"HeartWindow", L"Animated Heart", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInst, NULL ); if(!hwnd) return 0; ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; }```源文件未编译 请出此题修改后的完整代码
03-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值