gpt4 book ai didi

c++ - c2447错误学习创建Win32窗口

转载 作者:行者123 更新时间:2023-12-02 11:15:49 25 4
gpt4 key购买 nike

我已经尝试了很多次,并从视频中复制了这段代码,但几乎有些不同,因为我无所事事,没有出现新的错误,但是我已经尝试了好几天了。和关闭。无论如何,c2447缺少{(旧样式格式?)在谷歌搜索后似乎很容易解决,但我被困住了并且感到沮丧。也应该是一个Win32窗口

#include <windows.h>

LRESULT CALLBACK
MainWindowCallback(HWND Window
UINT Message,
WPARAM WParam,
LPARAM LParam);
{
LRESULT Result = 0;

switch(Message)
{
case WM_SIZE:
{
OutputDebugStringA("WM_SIZE\n")
} break;

case WM_DESTROY:
{
OutputDebugStringA("WM_DESTROY\n")
} break;

case WM_ClOSE:
{
OutputDebugStringA("WM_CLOSE\n")
} break;

case WM_ACTIVATEAPP:
{
OutputDebugStringA("WM_ACTIVATEAPP\n")
} break;

default:
{
Result = ;
} break;
}
return(Result);
}

int CALLBACK
WinMain(HINSTANCE Instance,
HINSTANCE PrevInstance,
LPSTR CommandLine,
int ShowCode)



{
WNDCLASS WindowClass = {};

WindowClass.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
WindowClass.lpfnWndProc = MainWindowCallback;
WindowClass.hInstance = Instance ;
// WindowClass.hIcon;
WindowClass.lpszClassName = "RavelWindowClass";

if(RegisterClass(&WindowClass));
{
HWND WindowHandle =
CreateWindowEx(0,
WindowClass.lpszClassName,
"Ravel",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
Instance,
0);

if(WindowHandle)
{
for(;;)
{
MSG Message;
BOOL MessageResult = GetMessage(&Message, 0, 0, 0);
if(MessageResult > 0)
{
TranslateMessage(&Message);
DispatchMessage(&Message);

}
else
{
break;
}
}
}
}

return(0);
}

ps在我写这个网站的麻烦中并不那么草率。
谢谢

最佳答案

您的代码有几个错误。首先,编译器错误c2447告诉我们:

The compiler encountered an unexpected open brace at global scope. In most cases, this is caused by a badly-formed function header, a misplaced declaration, or a stray semi-colon. To resolve this issue, verify that the open brace follows a correctly-formed function header, and is not preceded by a declaration or a stray semi-colon.



因为分号结束了函数头,所以出现此错误,请注意,您还缺少两个第一个参数之间的 ,:
LRESULT CALLBACK
MainWindowCallback(HWND Window <-- missing comma
UINT Message,
WPARAM WParam,
LPARAM LParam); <-- terminates the function header

请注意,c++区分大小写,因此 WM_ClOSE与您应使用的 WM_CLOSE不同。换句话说,您正在尝试使用未定义的常量,并且需要更改常量名称:
case WM_ClOSE: <-- this is an undefined constant, should be WM_CLOSE
{
OutputDebugStringA("WM_CLOSE\n")
} break;

关于c++ - c2447错误学习创建Win32窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28393017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com