我遵循了几个教程,并试图从让窗口运行开始制作一个基本的 C++ 游戏。当我尝试运行我的代码时,我收到了一系列关于字符串类型的错误,而且无论我遵循哪个教程,我最终都会遇到类似的错误。我试过包括 UNICODE,基本上弄乱了我能找到的每一种类型的字符串声明,但它仍然不起作用。总的来说,我对 Windows API 如何处理字符串以及字符串类型为何如此重要感到非常困惑。
附件是导致此错误的 Windows 构造函数: window.cpp:25:30: 错误:无法在赋值中将 'const wchar_t*' 转换为 'LPCSTR' {aka 'const char*'} 25 | wndClass.lpszClassName = CLASS_NAME;
`Window::Window()
: m_hInstance(GetModuleHandle(nullptr))
{
const wchar_t* CLASS_NAME = L"Jacob's Window Class";
WNDCLASS wndClass = {};
wndClass.lpszClassName = CLASS_NAME;
wndClass.hInstance = m_hInstance;
wndClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.lpfnWndProc = nullptr; // Will update this later once I write it
RegisterClass(&wndClass);
DWORD style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
int width = 640;
int height = 480;
RECT rect;
rect.left = 250;
rect.top = 250;
rect.right = rect.left + width;
rect.bottom = rect.top + height;
AdjustWindowRect(&rect, style, false);
m_hWnd = CreateWindowEx(
0,
CLASS_NAME,
L"Title",
style,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
m_hInstance,
NULL
);
ShowWindow(m_hWnd, SW_SHOW);
}`
任何帮助表示赞赏!谢谢!