diff --git a/Client/CMakeLists.txt b/Client/CMakeLists.txt index 08fe71e..95a2f22 100644 --- a/Client/CMakeLists.txt +++ b/Client/CMakeLists.txt @@ -16,6 +16,6 @@ if(WIN32) System/System.cpp Window/Window.cpp ) - add_executable(TSO ${NIOTSOCLIENT_SOURCES}) + add_executable(TSO WIN32 ${NIOTSOCLIENT_SOURCES}) target_link_libraries(TSO FileHandler_shared freetype_shared ole32 opengl32) endif() \ No newline at end of file diff --git a/Client/Window/Window.cpp b/Client/Window/Window.cpp index 302602b..6aff40a 100644 --- a/Client/Window/Window.cpp +++ b/Client/Window/Window.cpp @@ -25,7 +25,8 @@ HWND hWnd; static HANDLE Response = NULL; static HANDLE Thread = NULL; -static volatile int Result; +static DWORD ThreadID = NULL; +static volatile int Result = NULL; static DWORD WINAPI Procedure(LPVOID); static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -39,7 +40,7 @@ int Initialize(){ return ERROR_WINDOW_SYNCOBJECT; } - Thread = CreateThread(NULL, 1024 /* very tiny stack size is needed */, Window::Procedure, NULL, 0, NULL); + Thread = CreateThread(NULL, 1024 /* very tiny stack size is needed */, Window::Procedure, NULL, 0, &ThreadID); if(Thread == NULL){ MessageBox(NULL, "Failed to create the message loop thread.", NULL, MB_OK | MB_ICONERROR); Shutdown(); @@ -75,7 +76,7 @@ void Shutdown(){ if(Thread){ DWORD value; while(GetExitCodeThread(Thread, &value) && value){ - //PostQuitMessage() doesn't reliably work from a separate thread + PostThreadMessage(ThreadID, WM_QUIT, 0, 0); Sleep(1); } Thread = NULL; @@ -103,12 +104,6 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar case WM_CLOSE: System::UserInput_v.CloseWindow = true; return 0; - - case WM_SHOWWINDOW: - //Once the window is hidden (we cannot safely destroy the window while we have the OpenGL context), - //WM_QUIT and WM_DESTROY won't show up when a separate thread calls DestroyWindow() or PostQuitMessage(). - if(wParam == FALSE) PostQuitMessage(0); - return 0; case WM_DEVMODECHANGE: { DEVMODE dm;