對,最近我一直在學習C++,因爲我想製作一款遊戲。所以我做了什麼,我是通過製作一個C++窗口開始的,但是最終導致了一個我無法修復的問題。在它說wc.lpszClassName = L「ZakariyaTV's Class」的行上;我在等號下面出現一條紅線。我花了很多時間試圖弄清楚,但我不能。如果你知道如何解決它,它會非常感激。謝謝。我得到一個錯誤,我的C++窗口
這裏是我的代碼:
#include<Windows.h>
HWND windowHandle;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE preInstance, PSTR cmdLine, int showCmd)
{
// Step 1
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIconSm = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpszClassName = L"ZakariyaTV's Class";
wc.lpszMenuName = 0;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
// Step 2
RegisterClassEx(&wc);
// Step 3
windowHandle = CreateWindowEx(WS_EX_ACCEPTFILES, L"ZakariyaTV's Class", L"Game!",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 800, 600, 0, 0, hInstance, 0);
// Step 4
if (windowHandle == 0)
MessageBoxA(0, "Create window failed", "Error Message", 0);
// Step 5
ShowWindow(windowHandle, showCmd);
// Step 6
UpdateWindow(windowHandle);
MSG msg;
SecureZeroMemory(&msg, sizeof(MSG));
int returnValue = 0;
while ((returnValue = GetMessage(&msg, 0, 0, 0)) != 0)
{
if (returnValue == -1)
{
MessageBoxA(windowHandle, "GetMessage Failed!", "Error Message", 0);
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
IDE強調它很好,但是當您嘗試編譯代碼時,編譯器爲此行生成的錯誤消息*是什麼?另外,請正確格式化您的代碼示例。 –
我的猜測是?你不是用'UNICODE'集合構建的。 –
它說:https://gyazo.com/071258b37abe17a3c5e996c9d163846b – ZOulhadj