这是一个非常干净的窗口,只有一个编辑框(窗口的句柄在我的GameLibrary.h中)但是我之前已经创建了很多窗口并且它工作正常我现在无法找到我的生活窗户打开和关闭的原因。
我正在查看我的WndProc并检查是否有任何东西泄漏到DestroyWindow消息中但是没有。有人能给我一双新鲜的眼睛,告诉我这个问题的原因是什么?谢谢!
#include "stdafx.h"
#include "GameLibrary.h"
LRESULT CALLBACK LoginWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) {
//Attributes for the Login Class
wchar_t szLoginWindowClassName[] = L"GameLauncherLogin";
MSG msg;
WNDCLASSW LoginWindowClass;
LoginWindowClass.cbClsExtra = 0;
LoginWindowClass.cbWndExtra = 0;
LoginWindowClass.hbrBackground = HBRUSH(GetStockObject(WHITE_BRUSH));
LoginWindowClass.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_ARROW));
LoginWindowClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
LoginWindowClass.hInstance = hInstance;
LoginWindowClass.lpfnWndProc = LoginWndProc;
LoginWindowClass.lpszClassName = szLoginWindowClassName;
LoginWindowClass.lpszMenuName = NULL;
LoginWindowClass.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass(&LoginWindowClass)) {
MessageBox(NULL, L"Class was not able to register!", L"Class Registration Error", MB_ICONERROR | MB_OK);
}
hLoginWindow = CreateWindow(szLoginWindowClassName, L"GameLibrary Login", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, hInstance, NULL);
if (hLoginWindow == NULL) {
return 1;
}
ShowWindow(hLoginWindow, SW_SHOW);
UpdateWindow(hLoginWindow);
if (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
这是WndProc。
LRESULT CALLBACK LoginWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) {
switch (uMessage) {
case WM_CREATE: {
hUsername = CreateWindow(L"Edit", L"Test", WS_VISIBLE | WS_CHILD, 5, 5, 5, 5, hWnd, NULL, NULL, NULL);
break;
}
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default: {
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
}
return 0;
}
答案 0 :(得分:3)
消息循环应该是......循环!
while (GetMessage(&msg, NULL, 0, 0))