Code:
int Window::Create() { WNDCLASSEX wcex{}; auto szWindowClass = _T("Scream2DEngineWindow"); auto hInstance = GetModuleHandle(nullptr); auto hIcon = LoadIcon(nullptr, IDI_APPLICATION); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_DBLCLKS; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = hIcon; wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hbrBackground = GetSysColorBrush(COLOR_3DFACE); wcex.lpszMenuName = nullptr; wcex.lpszClassName = szWindowClass; wcex.hIconSm = hIcon; if (!RegisterClassEx(&wcex)) { return 1; } auto hWnd = CreateWindowEx(0, szWindowClass, "Title", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 100, HWND_DESKTOP, nullptr, hInstance, nullptr); std::cout << GetLastError() << std::endl; if (!hWnd) { return 2; } ShowWindow(hWnd, SW_SHOW); return 0; } It outputs “0” to the console (GetLastError), but the function returns 2, that is, hWnd == 0.
Where is the mistake?
hWndwithIsWindow(). If the HWND is not null (and you yourself wrote thathWndis two), it is quite possible that the system simply gives you such a descriptor, and as it should be. - ߊߚߤߘHWNDfromCreateWindowEx,WndProcwill be called several times. Attach the contents of this function to the question; this may clarify the situation. - mega