diff --git a/DDrawCompat/Gdi/PresentationWindow.cpp b/DDrawCompat/Gdi/PresentationWindow.cpp index 09dedff..56d4ca4 100644 --- a/DDrawCompat/Gdi/PresentationWindow.cpp +++ b/DDrawCompat/Gdi/PresentationWindow.cpp @@ -1,8 +1,10 @@ #include #include +#include #include #include #include +#include namespace { @@ -15,6 +17,28 @@ namespace HWND g_messageWindow = nullptr; bool g_isThreadReady = false; + BOOL CALLBACK initChildWindow(HWND hwnd, LPARAM /*lParam*/) + { + Gdi::WinProc::onCreateWindow(hwnd); + return TRUE; + } + + BOOL CALLBACK initTopLevelWindow(HWND hwnd, LPARAM /*lParam*/) + { + DWORD windowPid = 0; + GetWindowThreadProcessId(hwnd, &windowPid); + if (GetCurrentProcessId() == windowPid) + { + Gdi::WinProc::onCreateWindow(hwnd); + EnumChildWindows(hwnd, &initChildWindow, 0); + if (8 == Win32::DisplayMode::getBpp()) + { + PostMessage(hwnd, WM_PALETTECHANGED, reinterpret_cast(GetDesktopWindow()), 0); + } + } + return TRUE; + } + LRESULT CALLBACK messageWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LOG_FUNC("messageWindowProc", Compat::WindowMessageStruct(hwnd, uMsg, wParam, lParam)); @@ -98,8 +122,13 @@ namespace return 0; } - g_isThreadReady = true; - Gdi::WinProc::installHooks(); + { + D3dDdi::ScopedCriticalSection lock; + Gdi::WinProc::installHooks(); + g_isThreadReady = true; + EnumWindows(initTopLevelWindow, 0); + } + Compat::closeDbgEng(); MSG msg = {}; @@ -132,7 +161,7 @@ namespace Gdi void destroy(HWND hwnd) { - sendMessageBlocking(hwnd, WM_CLOSE, 0, 0); + PostMessage(hwnd, WM_CLOSE, 0, 0); } void installHooks() diff --git a/DDrawCompat/Gdi/WinProc.cpp b/DDrawCompat/Gdi/WinProc.cpp index 869ed06..f7549a8 100644 --- a/DDrawCompat/Gdi/WinProc.cpp +++ b/DDrawCompat/Gdi/WinProc.cpp @@ -15,7 +15,6 @@ #include #include #include -#include namespace { @@ -25,7 +24,6 @@ namespace WNDPROC wndProcW; }; - bool g_isInitialized = false; std::set g_windowPosChangeNotifyFuncs; Compat::SrwLock g_windowProcSrwLock; @@ -134,28 +132,6 @@ namespace return g_windowProc[hwnd]; } - BOOL CALLBACK initChildWindow(HWND hwnd, LPARAM /*lParam*/) - { - onCreateWindow(hwnd); - return TRUE; - } - - BOOL CALLBACK initTopLevelWindow(HWND hwnd, LPARAM /*lParam*/) - { - DWORD windowPid = 0; - GetWindowThreadProcessId(hwnd, &windowPid); - if (GetCurrentProcessId() == windowPid) - { - onCreateWindow(hwnd); - EnumChildWindows(hwnd, &initChildWindow, 0); - if (8 == Win32::DisplayMode::getBpp()) - { - PostMessage(hwnd, WM_PALETTECHANGED, reinterpret_cast(GetDesktopWindow()), 0); - } - } - return TRUE; - } - bool isTopLevelWindow(HWND hwnd) { return GetDesktopWindow() == GetAncestor(hwnd, GA_PARENT); @@ -463,16 +439,11 @@ namespace Gdi Dll::g_currentModule, &objectCreateEvent, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); SetWinEventHook(EVENT_OBJECT_STATECHANGE, EVENT_OBJECT_STATECHANGE, Dll::g_currentModule, &objectStateChangeEvent, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); - - g_isInitialized = true; - - EnumWindows(initTopLevelWindow, 0); - Gdi::Window::updateAll(); } void onCreateWindow(HWND hwnd) { - if (g_isInitialized) + if (PresentationWindow::isThreadReady()) { ::onCreateWindow(hwnd); }