好吧,所以我在这里坐了 30 多分钟试图解决这个问题,在“创建窗口”中它给了我一个 NULL 值,除非我的类名是“LoginClassName”,如果我使用“RegisterClassName”它会返回一个 NULL . 我正在尝试创建一个弹出窗口,到目前为止它在踢我的屁股。我创建的类与 LoginClass 相同,所以我没有真正看到问题。
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) {
MSG msg;
WNDCLASSW LoginClass = { 0 };
wchar_t LoginClassName[] = L"LoginWindow";
LoginClass.cbClsExtra = 0;
LoginClass.cbWndExtra = 0;
LoginClass.hbrBackground = HBRUSH(GetStockObject(WHITE_BRUSH));
LoginClass.hCursor = LoadCursor(hInstance, IDC_ARROW);
LoginClass.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
LoginClass.lpfnWndProc = LoginWndProc;
LoginClass.hInstance = hInstance;
LoginClass.lpszClassName = LoginClassName;
LoginClass.lpszMenuName = NULL;
LoginClass.style = CS_VREDRAW | CS_HREDRAW;
if (!RegisterClass(&LoginClass))
{
MessageBox(NULL, L"Error", L"Error", MB_OK | MB_ICONERROR);
return 0;
}
WNDCLASSW RegisterWindowClass = { 0 };
wchar_t RegisterClassName[] = L"Test";
RegisterWindowClass.cbClsExtra = 0;
RegisterWindowClass.cbWndExtra = 0;
RegisterWindowClass.hbrBackground = HBRUSH(GetStockObject(WHITE_BRUSH));
RegisterWindowClass.hCursor = LoadCursor(hInstance, IDC_ARROW);
RegisterWindowClass.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
RegisterWindowClass.lpfnWndProc = RegisterWndProc;
RegisterWindowClass.hInstance = hInstance;
RegisterWindowClass.lpszClassName = RegisterClassName;
RegisterWindowClass.lpszMenuName = NULL;
RegisterWindowClass.style = CS_VREDRAW | CS_HREDRAW;
if (!RegisterClass(&RegisterWindowClass))
{
MessageBox(NULL, L"Error", L"Error", MB_OK | MB_ICONERROR);
return 0;
}
hLoginWindow = CreateWindow(LoginClassName, L"GameLauncher Login", WS_SYSMENU | WS_CAPTION | WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, 350, 200, NULL, NULL, hInstance, NULL);
hRegisterWindow = CreateWindowEx(NULL, RegisterClassName, L"Register Account", WS_SYSMENU | WS_CAPTION | WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, 350, 200, NULL, NULL, hInstance, NULL);
ShowWindow(hLoginWindow, iCmdShow);
UpdateWindow(hLoginWindow);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
这WndProc
是RegisterClassWindow
:
LRESULT CALLBACK RegisterWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) {
switch (uMessage)
{
case WM_CREATE: {
break;
}
case WM_DESTROY:{
PostQuitMessage(0);
break;
}
default:{
DefWindowProc(hWnd, uMessage, wParam, lParam);
}
}
return 0;
}