hMainWindow возвращается нулевое значение. ошибку не вижу в упор
#include <windows.h>
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
char szClassName[] = "TestWindow";
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, int nCommandShow) {
HWND hMainWindow;
WNDCLASSEX wcex;
wcex.hInstance = hInstance;
wcex.lpszClassName = szClassName;
wcex.lpfnWndProc = WindowProcedure;
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wcex.lpszMenuName = NULL;
wcex.cbClsExtra = NULL;
wcex.cbWndExtra = NULL;
if(!RegisterClassEx(&wcex)) {
MessageBox(NULL, "Class registration failed", "Error", MB_ICONERROR);
return NULL;
}
hMainWindow = CreateWindow(szClassName, "Window", WS_OVERLAPPEDWINDOW | WS_VSCROLL, CW_USEDEFAULT, NULL, 400, 300, HWND(NULL), NULL, HINSTANCE(hInstance), NULL);
if(!hMainWindow) {
MessageBox(NULL, "Window creation failed", "Error", MB_ICONERROR);
return NULL;
}
ShowWindow(hMainWindow, nCommandShow);
UpdateWindow(hMainWindow);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
return NULL;
}