Не открывается GUI WinApi
#include <Windows.h>
LRESULT CALLBACK SoftwareMainProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
WNDCLASS NewWindowClass(HBRUSH BGColor, HCURSOR Cursor, HINSTANCE hInst, HICON Icon, LPCWSTR Name, WNDPROC Procedure);
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int ncmdshow) {
HWND hWnd;
WNDCLASS SoftwareMainClass = NewWindowClass((HBRUSH)COLOR_WINDOW, LoadCursor(NULL, IDC_ARROW), hInst, LoadIcon(NULL, IDI_QUESTION), L"MainWndClass", SoftwareMainProcedure);
if (!RegisterClassW(&SoftwareMainClass)) { return -1; }
MSG SoftwareMainMessage = { 0 };
hWnd = CreateWindow(L"MainWndClass", L"First c++ window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 500, 250, NULL, NULL, NULL, NULL);
while (GetMessage(&SoftwareMainMessage, NULL, NULL, NULL)) {
TranslateMessage(&SoftwareMainMessage);
DispatchMessage(&SoftwareMainMessage);
}
return 0;
}
WNDCLASS NewWindowClass(HBRUSH BGColor, HCURSOR Cursor, HINSTANCE hInst, HICON Icon, LPCWSTR Name, WNDPROC Procedure) {
WNDCLASS NWC = { 0 };
NWC.hCursor = Cursor;
NWC.hIcon = Icon;
NWC.hInstance = hInst;
NWC.lpszClassName = Name;
NWC.hbrBackground = BGColor;
NWC.lpfnWndProc = Procedure;
return NWC;
}
LRESULT CALLBACK SoftwareMainProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg)
{
case WM_CREATE:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default: return DefWindowProc(hWnd, msg, wp, wp);
}
}
Не открывается GUI окошко, а процесс программы висит в диспетчере задач.
Опечатка: должно быть
default: return DefWindowProc(hWnd, msg, wp, lp);
вместо
default: return DefWindowProc(hWnd, msg, wp, wp);
Плюс обработчик WM_CREATE должен возвращать 0