好吧,所以我已经坐在这里超过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
的{{1}}:
RegisterClassWindow