From 12944404e81e2f90c0343875c6cb523d07ac2839 Mon Sep 17 00:00:00 2001 From: narzoul Date: Sat, 28 Nov 2020 12:48:36 +0100 Subject: [PATCH] Fixed WM_SETTEXT drawing over previous caption text --- DDrawCompat/Gdi/PaintHandlers.cpp | 28 ++++++++++++++++++++++++++++ DDrawCompat/Win32/Log.cpp | 8 ++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/DDrawCompat/Gdi/PaintHandlers.cpp b/DDrawCompat/Gdi/PaintHandlers.cpp index 3f723ea..daed450 100644 --- a/DDrawCompat/Gdi/PaintHandlers.cpp +++ b/DDrawCompat/Gdi/PaintHandlers.cpp @@ -46,6 +46,7 @@ namespace LRESULT onNcPaint(HWND hwnd, WPARAM wParam, WNDPROC origWndProc); LRESULT onPaint(HWND hwnd, WNDPROC origWndProc); LRESULT onPrint(HWND hwnd, UINT msg, HDC dc, LONG flags, WNDPROC origWndProc); + LRESULT onSetText(HWND hwnd, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc); User32WndProc* g_currentUser32WndProc = nullptr; std::vector g_failedHooks; @@ -148,6 +149,9 @@ namespace case WM_PRINTCLIENT: return onPrint(hwnd, msg, reinterpret_cast(wParam), lParam, origWndProc); + case WM_SETTEXT: + return onSetText(hwnd, wParam, lParam, origWndProc); + default: return CallWindowProc(origWndProc, hwnd, msg, wParam, lParam); } @@ -389,6 +393,30 @@ namespace return result; } + LRESULT onSetText(HWND hwnd, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc) + { + LRESULT result = CallWindowProc(origWndProc, hwnd, WM_SETTEXT, wParam, lParam); + if (0 == result || + 0 == (CALL_ORIG_FUNC(GetWindowLongA)(hwnd, GWL_STYLE) & WS_CAPTION)) + { + return result; + } + + HDC windowDc = GetWindowDC(hwnd); + HDC compatDc = Gdi::Dc::getDc(windowDc); + + if (compatDc) + { + Gdi::AccessGuard accessGuard(Gdi::ACCESS_WRITE); + Gdi::TitleBar titleBar(hwnd, compatDc); + titleBar.drawCaption(); + Gdi::Dc::releaseDc(windowDc); + } + + CALL_ORIG_FUNC(ReleaseDC)(hwnd, windowDc); + return result; + } + LRESULT scrollBarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc) { switch (msg) diff --git a/DDrawCompat/Win32/Log.cpp b/DDrawCompat/Win32/Log.cpp index 88eaca2..aa598e6 100644 --- a/DDrawCompat/Win32/Log.cpp +++ b/DDrawCompat/Win32/Log.cpp @@ -676,9 +676,9 @@ namespace Compat #define LOG_PARAM_CASE_2(param, msg, TypeA, TypeW) \ case msg: \ if (IsWindowUnicode(wm.hwnd)) \ - os << reinterpret_cast(param); \ + os << *reinterpret_cast(¶m); \ else \ - os << reinterpret_cast(param); \ + os << *reinterpret_cast(¶m); \ break; #define LOG_WPARAM_CASE_1(msg, ...) LOG_PARAM_CASE_1(wm.wParam, msg, __VA_ARGS__) @@ -798,7 +798,7 @@ namespace Compat switch (wm.msg.msg) { LOG_LPARAM_CASE_1(WM_ACTIVATE, HWND); - LOG_LPARAM_CASE_2(WM_ASKCBFORMATNAME, LPCSTR, LPCWSTR); + LOG_LPARAM_CASE_2(WM_ASKCBFORMATNAME, Compat::detail::Out, Compat::detail::Out); LOG_LPARAM_CASE_1(WM_CAPTURECHANGED, HWND); LOG_LPARAM_CASE_1(WM_CHANGECBCHAIN, HWND); LOG_LPARAM_CASE_1(WM_CHARTOITEM, HWND); @@ -826,7 +826,7 @@ namespace Compat LOG_LPARAM_CASE_1(WM_GETDPISCALEDSIZE, SIZE*); LOG_LPARAM_CASE_1(WM_GETICON, DWORD); LOG_LPARAM_CASE_1(WM_GETMINMAXINFO, MINMAXINFO*); - LOG_LPARAM_CASE_2(WM_GETTEXT, LPCSTR, LPCWSTR); + LOG_LPARAM_CASE_2(WM_GETTEXT, Compat::detail::Out, Compat::detail::Out); LOG_LPARAM_CASE_1(WM_HELP, HELPINFO*); LOG_LPARAM_CASE_1(WM_HOTKEY, std::pair, Compat::detail::Hex>); LOG_LPARAM_CASE_1(WM_HSCROLL, HWND);