From 4dbc7d4204bbf11240fee34369292ce433744949 Mon Sep 17 00:00:00 2001 From: narzoul Date: Thu, 28 Jan 2021 00:45:54 +0100 Subject: [PATCH] Fixed inactive window caption icon background color --- DDrawCompat/Gdi/TitleBar.cpp | 32 +++++++++++++---------- DDrawCompat/Gdi/TitleBar.h | 1 - DDrawCompat/Gdi/User32WndProcs.cpp | 42 +++++------------------------- 3 files changed, 25 insertions(+), 50 deletions(-) diff --git a/DDrawCompat/Gdi/TitleBar.cpp b/DDrawCompat/Gdi/TitleBar.cpp index c355a4a..b18429e 100644 --- a/DDrawCompat/Gdi/TitleBar.cpp +++ b/DDrawCompat/Gdi/TitleBar.cpp @@ -101,7 +101,7 @@ namespace Gdi return; } - UINT flags = 0; + UINT flags = DC_TEXT; if (m_isActive) { flags |= DC_ACTIVE; @@ -116,18 +116,27 @@ namespace Gdi OffsetRect(&clipRect, m_windowRect.left - virtualScreenBounds.left, m_windowRect.top - virtualScreenBounds.top); Region clipRgn(clipRect); SelectClipRgn(m_compatDc, clipRgn); + CALL_ORIG_FUNC(DrawCaption)(m_hwnd, m_compatDc, &m_tbi.rcTitleBar, flags); + SelectClipRgn(m_compatDc, nullptr); - RECT textRect = m_tbi.rcTitleBar; if (m_hasIcon) { - CALL_ORIG_FUNC(DrawCaption)(m_hwnd, m_compatDc, &m_tbi.rcTitleBar, DC_ICON | flags); - textRect.left -= 1; + RECT r = m_tbi.rcTitleBar; + r.right = r.left + r.bottom - r.top; + CALL_ORIG_FUNC(FillRect)(m_compatDc, &r, + GetSysColorBrush(m_isActive ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION)); + + HICON icon = reinterpret_cast(SendMessage(m_hwnd, WM_GETICON, ICON_SMALL, 96)); + if (!icon) + { + icon = reinterpret_cast(GetClassLong(m_hwnd, GCL_HICONSM)); + } + int width = GetSystemMetrics(SM_CXSMICON); + int height = GetSystemMetrics(SM_CYSMICON); + int x = r.left + (r.right - r.left - width) / 2 + 2; + int y = r.top + (r.bottom - r.top - height) / 2; + CALL_ORIG_FUNC(DrawIconEx)(m_compatDc, x, y, icon, width, height, 0, nullptr, DI_NORMAL); } - - textRect.top -= 1; - CALL_ORIG_FUNC(DrawCaption)(m_hwnd, m_compatDc, &textRect, DC_TEXT | flags); - - SelectClipRgn(m_compatDc, nullptr); } void TitleBar::drawButton(std::size_t tbiIndex, UINT dfcState) const @@ -160,11 +169,6 @@ namespace Gdi } } - void TitleBar::setActive(bool isActive) - { - m_isActive = isActive; - } - bool TitleBar::isVisible(std::size_t tbiIndex) const { return !(m_tbi.rgstate[tbiIndex] & (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN)); diff --git a/DDrawCompat/Gdi/TitleBar.h b/DDrawCompat/Gdi/TitleBar.h index 225ba4f..d43439d 100644 --- a/DDrawCompat/Gdi/TitleBar.h +++ b/DDrawCompat/Gdi/TitleBar.h @@ -15,7 +15,6 @@ namespace Gdi void drawButtons() const; void drawCaption() const; void excludeFromClipRegion() const; - void setActive(bool isActive); private: void adjustButtonSize(RECT& rect) const; diff --git a/DDrawCompat/Gdi/User32WndProcs.cpp b/DDrawCompat/Gdi/User32WndProcs.cpp index 4d9f2b9..4fb9144 100644 --- a/DDrawCompat/Gdi/User32WndProcs.cpp +++ b/DDrawCompat/Gdi/User32WndProcs.cpp @@ -363,27 +363,13 @@ namespace return CallWindowProc(origWndProc, hwnd, WM_ERASEBKGND, reinterpret_cast(dc), 0); } - LRESULT onNcActivate(HWND hwnd, WPARAM wParam, LPARAM lParam) + LRESULT onNcActivate(HWND hwnd, WPARAM /*wParam*/, LPARAM lParam) { - if (-1 == lParam) + if (-1 != lParam) { - return TRUE; + RECT r = { -1, -1, 0, 0 }; + RedrawWindow(hwnd, &r, nullptr, RDW_INVALIDATE | RDW_FRAME); } - - HDC windowDc = GetWindowDC(hwnd); - HDC compatDc = Gdi::Dc::getDc(windowDc); - - if (compatDc) - { - D3dDdi::ScopedCriticalSection lock; - Gdi::AccessGuard accessGuard(Gdi::ACCESS_WRITE); - Gdi::TitleBar titleBar(hwnd, compatDc); - titleBar.setActive(wParam); - titleBar.drawAll(); - Gdi::Dc::releaseDc(windowDc); - } - - CALL_ORIG_FUNC(ReleaseDC)(hwnd, windowDc); return TRUE; } @@ -461,25 +447,11 @@ namespace 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)) + if (TRUE == result && (CALL_ORIG_FUNC(GetWindowLongA)(hwnd, GWL_STYLE) & WS_CAPTION)) { - return result; + RECT r = { -1, -1, 0, 0 }; + RedrawWindow(hwnd, &r, nullptr, RDW_INVALIDATE | RDW_FRAME); } - - HDC windowDc = GetWindowDC(hwnd); - HDC compatDc = Gdi::Dc::getDc(windowDc); - - if (compatDc) - { - D3dDdi::ScopedCriticalSection lock; - Gdi::AccessGuard accessGuard(Gdi::ACCESS_WRITE); - Gdi::TitleBar titleBar(hwnd, compatDc); - titleBar.drawAll(); - Gdi::Dc::releaseDc(windowDc); - } - - CALL_ORIG_FUNC(ReleaseDC)(hwnd, windowDc); return result; }