diff --git a/DDrawCompat/Gdi/PresentationWindow.cpp b/DDrawCompat/Gdi/PresentationWindow.cpp index d4a7252..8eec79d 100644 --- a/DDrawCompat/Gdi/PresentationWindow.cpp +++ b/DDrawCompat/Gdi/PresentationWindow.cpp @@ -9,9 +9,23 @@ namespace { ATOM g_classAtom = 0; + std::wstring getWindowText(HWND hwnd) + { + const UINT MAX_LEN = 256; + wchar_t windowText[MAX_LEN] = {}; + InternalGetWindowText(hwnd, windowText, MAX_LEN); + return windowText; + } + LRESULT CALLBACK presentationWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LOG_FUNC("presentationWindowProc", Compat::WindowMessageStruct(hwnd, uMsg, wParam, lParam)); + if (WM_NULL == uMsg && WM_GETTEXT == wParam && WM_SETTEXT == lParam) + { + std::wstring windowText(L"[DDrawCompat] " + getWindowText(GetParent(hwnd))); + SetWindowTextW(hwnd, windowText.c_str()); + return LOG_RESULT(0); + } return LOG_RESULT(CALL_ORIG_FUNC(DefWindowProcA)(hwnd, uMsg, wParam, lParam)); } } diff --git a/DDrawCompat/Gdi/WinProc.cpp b/DDrawCompat/Gdi/WinProc.cpp index e19fa26..3e985e1 100644 --- a/DDrawCompat/Gdi/WinProc.cpp +++ b/DDrawCompat/Gdi/WinProc.cpp @@ -54,7 +54,6 @@ namespace decltype(&DwmSetIconicThumbnail) g_dwmSetIconicThumbnail = nullptr; - wchar_t g_dummyWindowText; std::map g_menuMaxHeight; std::set g_windowPosChangeNotifyFuncs; @@ -71,7 +70,6 @@ namespace void dwmSendIconicThumbnail(HWND hwnd, LONG width, LONG height); WindowProc getWindowProc(HWND hwnd); - std::wstring getWindowText(HWND hwnd, WNDPROC wndProc); bool isUser32ScrollBar(HWND hwnd); void onDestroyWindow(HWND hwnd); void onGetMinMaxInfo(MINMAXINFO& mmi); @@ -146,19 +144,6 @@ namespace } break; - case WM_NULL: - if (WM_GETTEXT == wParam && reinterpret_cast(&g_dummyWindowText) == lParam) - { - auto presentationWindow = Gdi::Window::getPresentationWindow(hwnd); - if (presentationWindow) - { - std::wstring windowText(L"[DDrawCompat] " + getWindowText(hwnd, wndProc)); - SendMessageW(presentationWindow, WM_SETTEXT, 0, reinterpret_cast(windowText.c_str())); - } - return 0; - } - break; - case WM_SYNCPAINT: if (Gdi::Window::isTopLevelWindow(hwnd)) { @@ -412,25 +397,6 @@ namespace return it != g_windowProc.end() ? it->second : WindowProc{}; } - std::wstring getWindowText(HWND hwnd, WNDPROC wndProc) - { - const UINT MAX_LEN = 256; - if (IsWindowUnicode(hwnd)) - { - wchar_t windowText[MAX_LEN] = {}; - CallWindowProcW(wndProc, hwnd, WM_GETTEXT, MAX_LEN, reinterpret_cast(windowText)); - windowText[MAX_LEN - 1] = 0; - return windowText; - } - else - { - char windowText[MAX_LEN] = {}; - CallWindowProcA(wndProc, hwnd, WM_GETTEXT, MAX_LEN, reinterpret_cast(windowText)); - windowText[MAX_LEN - 1] = 0; - return std::wstring(windowText, windowText + strlen(windowText)); - } - } - template int WINAPI messageBox(Params... params) { @@ -813,7 +779,11 @@ namespace case EVENT_OBJECT_NAMECHANGE: if (OBJID_WINDOW == idObject && Gdi::Window::isTopLevelWindow(hwnd) && !Gdi::GuiThread::isGuiThreadWindow(hwnd)) { - Gdi::WinProc::updatePresentationWindowText(hwnd); + auto presentationWindow = Gdi::Window::getPresentationWindow(hwnd); + if (presentationWindow) + { + Gdi::Window::updatePresentationWindowText(presentationWindow); + } break; } @@ -1038,11 +1008,6 @@ namespace Gdi } } - void updatePresentationWindowText(HWND owner) - { - SendNotifyMessageW(owner, WM_NULL, WM_GETTEXT, reinterpret_cast(&g_dummyWindowText)); - } - void watchWindowPosChanges(WindowPosChangeNotifyFunc notifyFunc) { g_windowPosChangeNotifyFuncs.insert(notifyFunc); diff --git a/DDrawCompat/Gdi/Window.cpp b/DDrawCompat/Gdi/Window.cpp index f9babb5..c90cecb 100644 --- a/DDrawCompat/Gdi/Window.cpp +++ b/DDrawCompat/Gdi/Window.cpp @@ -290,7 +290,7 @@ namespace if (!isLayered) { it->second.presentationWindow = Gdi::PresentationWindow::create(hwnd); - Gdi::WinProc::updatePresentationWindowText(hwnd); + Gdi::Window::updatePresentationWindowText(it->second.presentationWindow); } else if (it->second.presentationWindow) { @@ -662,7 +662,7 @@ namespace Gdi if (it->second.presentationWindow) { - Gdi::WinProc::updatePresentationWindowText(hwnd); + updatePresentationWindowText(it->second.presentationWindow); Gdi::GuiThread::setWindowRgn(it->second.presentationWindow, getWindowRgn(hwnd)); } @@ -729,6 +729,11 @@ namespace Gdi }); } + void updatePresentationWindowText(HWND presentationWindow) + { + PostMessageW(presentationWindow, WM_NULL, WM_GETTEXT, WM_SETTEXT); + } + void updateWindowPos(HWND hwnd) { if (IsWindowVisible(hwnd) && !IsIconic(hwnd)) diff --git a/DDrawCompat/Gdi/Window.h b/DDrawCompat/Gdi/Window.h index 270bafe..5120c1c 100644 --- a/DDrawCompat/Gdi/Window.h +++ b/DDrawCompat/Gdi/Window.h @@ -33,6 +33,7 @@ namespace Gdi void updateLayeredWindowInfo(HWND hwnd, HDC hdcSrc, const POINT* pptSrc, COLORREF colorKey, BYTE alpha, BYTE alphaFormat); void updatePresentationWindowPos(HWND presentationWindow, HWND owner); + void updatePresentationWindowText(HWND presentationWindow); void updateWindowPos(HWND hwnd); } }