I'm trying to create a simple window with the code below.
void MainWindow::Create()
{
WNDCLASSEXW wcx;
wcx.cbSize = (UINT) sizeof(wcx);
wcx.style = (UINT) CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = (WNDPROC) MainWindowProc;
wcx.cbClsExtra = (int) 0;
wcx.cbWndExtra = (int) 0;
wcx.hInstance = (HINSTANCE) Status::hInstance;
wcx.hIcon = (HICON) NULL;
wcx.hCursor = (HCURSOR) NULL;
wcx.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wcx.lpszMenuName = (LPCWSTR) NULL;
wcx.lpszClassName = (LPCWSTR) m_ClassName.c_str();
wcx.hIconSm = (HICON) NULL;
RegisterClassExW(&wcx);
DWORD dw1 = GetLastError(); // Returns 0.
m_Handle = CreateWindowExW( (DWORD) WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_TABSTOP | WS_GROUP | WS_VISIBLE,
(LPCWSTR) m_ClassName.c_str(),
(LPCWSTR) m_WindowTitle.c_str(),
(DWORD) WS_EX_ACCEPTFILES | WS_EX_CONTROLPARENT | WS_EX_LEFT | WS_EX_LTRREADING,
(int) 50,
(int) 50,
(int) 800,
(int) 600,
(HWND) HWND_DESKTOP,
(HMENU) NULL,
(HINSTANCE) Status::hInstance,
(LPVOID) NULL);
DWORD dw2 = GetLastError(); // Returns 87.
}
The windows handle m_Handle is NULL, and the second GetLastError() returns 87, which means "The parameter is incorrect.". I tried sending different style codes, different class names, but it didn't change anything. Can you please help me fix this code?
Other relevant parts of the code are as shown below.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
Status::hInstance = hInstance; // hInstance is stored in a static class member here. It is not modified anywhere else.
Gui::GI()->MainWnd.Create(); // Calls the MainWindow::Create() method shown above.
MSG Msg;
HWND hWnd = Gui::GI()->MainWnd.GetHandle();
while (GetMessageW(&Msg, NULL, 0, 0))
{
if (!IsDialogMessageW(hWnd, &Msg))
{
TranslateMessage(&Msg);
DispatchMessageW(&Msg);
}
}
return (int) Msg.wParam;
}
MainWindow::MainWindow()
{
m_ClassName = L"MyMainWindowClass"; // std::wstring
m_WindowTitle = L"My Game"; // std::wstring
}