鱼C论坛

 找回密码
 立即注册
查看: 2148|回复: 1

学习小甲鱼winapi编程时遇到Run-Time Check Failure #0

[复制链接]
发表于 2020-6-15 08:51:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
学习winapi过程中遇到Run-Time Check Failure #0的报错
报错在
  1. while (GetMessage(&msg, NULL , 0, 0))
  2.         {
  3.                 TranslateMessage(&msg);
  4.                 DispatchMessage(&msg);
  5.         }
复制代码

这一段

下面为全部代码,基本上对着敲的

  1. #include <windows.h>
  2. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

  3. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, PSTR szCmdLine, int iCmdShow)
  4. {
  5.         static TCHAR szAPP[] = TEXT("Window_one");
  6.         HWND hwnd;
  7.         MSG msg;
  8.         WNDCLASS wndclass;

  9.         wndclass.style = CS_HREDRAW;
  10.         wndclass.lpfnWndProc = WndProc;
  11.         wndclass.cbClsExtra = 0;
  12.         wndclass.cbWndExtra = 0;
  13.         wndclass.hInstance = hInstance;
  14.         wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  15.         wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  16.         wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  17.         wndclass.lpszMenuName = NULL;
  18.         wndclass.lpszClassName = szAPP;

  19.         if (!RegisterClass(&wndclass))
  20.         {
  21.                 MessageBox(NULL, TEXT("程序执行环境出错"), szAPP, MB_ICONERROR);
  22.                 return 0;
  23.         }

  24.         hwnd = CreateWindow(szAPP,
  25.                 TEXT("????"),
  26.                 WS_OVERLAPPEDWINDOW,
  27.                 CW_USEDEFAULT,
  28.                 CW_USEDEFAULT,
  29.             CW_USEDEFAULT,
  30.                 CW_USEDEFAULT,
  31.                 NULL,
  32.                 NULL,
  33.             hInstance,
  34.                 NULL);

  35.         ShowWindow(hwnd, iCmdShow);
  36.         UpdateWindow(hwnd, iCmdShow);

  37.         while (GetMessage(&msg, NULL , 0, 0))
  38.         {
  39.                 TranslateMessage(&msg);
  40.                 DispatchMessage(&msg);
  41.         }

  42.         return msg.wParam;
  43. }

  44. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  45. {
  46.         HDC hdc;
  47.         PAINTSTRUCT ps;
  48.         RECT rect;

  49.         switch (message)
  50.         {
  51.         case WM_PAINT:
  52.                 hdc = BeginPaint(hwnd, &ps);
  53.                 GetClientRect(hwnd, &rect);
  54.                 DrawText(hdc, TEXT("HELLOWROLD"), -1, &rect,
  55.                         DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  56.                 EndPaint(hwnd, &ps);
  57.                 return 0;
  58.        
  59.         case WM_DESTROY:
  60.                 PostQuitMessage(0);
  61.                 return 0;
  62.         }
  63.         return DefWindowProc(hwnd, message, wParam, lParam);
  64. }
复制代码


用的编译器是VS2019,求大佬告知哪里出错了,百度,谷歌无果
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-6-15 08:54:06 | 显示全部楼层
懂了,没事了,我心急了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-7 13:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表