From ffed6ce1202a6890682efbf56128080234781753 Mon Sep 17 00:00:00 2001 From: lededev <30518126+lededev@users.noreply.github.com> Date: Sun, 27 Oct 2024 22:08:36 +0800 Subject: [PATCH] Foreground and background title bars are distinguishable --- Src/Common/MDITabBar.cpp | 6 +++++- Src/MainFrm.cpp | 20 +++++++++++++++++++- Src/MainFrm.h | 3 +++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Src/Common/MDITabBar.cpp b/Src/Common/MDITabBar.cpp index 5a931c2b4a7..dac033df011 100644 --- a/Src/Common/MDITabBar.cpp +++ b/Src/Common/MDITabBar.cpp @@ -9,6 +9,7 @@ #include "IMDITab.h" #include "cecolor.h" #include "RoundedRectWithShadow.h" +#include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -96,7 +97,10 @@ static COLORREF getBackColor(bool onTitleBar) const COLORREF clr = GetSysColor(COLOR_3DFACE); if (!onTitleBar) return clr; - return RGB(GetRValue(clr), std::clamp(GetGValue(clr) + 8, 0, 255), std::clamp(GetBValue(clr) + 8, 0, 255)); + const COLORREF bgclr = dynamic_cast(AfxGetMainWnd())->IsActivate() ? + RGB(GetRValue(clr), std::clamp(GetGValue(clr) + 8, 0, 255), std::clamp(GetBValue(clr) + 8, 0, 255)) + : clr; + return bgclr; } static inline bool IsHighContrastEnabled() diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index 5dd5bed4c6a..ccaf848a256 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -323,7 +323,8 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) ON_MESSAGE(WMU_CHILDFRAMEACTIVATE, &CMainFrame::OnChildFrameActivate) ON_MESSAGE(WMU_CHILDFRAMEACTIVATED, &CMainFrame::OnChildFrameActivated) //}}AFX_MSG_MAP -END_MESSAGE_MAP() + ON_WM_ACTIVATE() + END_MESSAGE_MAP() /** * @brief MainFrame statusbar panels/indicators @@ -366,6 +367,7 @@ CMainFrame::CMainFrame() , m_lfDiff(Options::Font::Load(GetOptionsMgr(), OPT_FONT_FILECMP)) , m_lfDir(Options::Font::Load(GetOptionsMgr(), OPT_FONT_DIRCMP)) , m_pDirWatcher(new DirWatcher()) +, m_bActivate(false) { } @@ -3704,3 +3706,19 @@ LRESULT CMainFrame::OnChildFrameActivated(WPARAM wParam, LPARAM lParam) return 1; } + + +void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) +{ + __super::OnActivate(nState, pWndOther, bMinimized); + + const bool bActivate = (nState != WA_INACTIVE); + if (bActivate != m_bActivate) + { + m_bActivate = bActivate; + + CRect titleBarRect; + m_wndTabBar.GetClientRect(&titleBarRect); + InvalidateRect(&titleBarRect, TRUE); + } +} diff --git a/Src/MainFrm.h b/Src/MainFrm.h index 39ddafe2a6a..52ca70f93b6 100644 --- a/Src/MainFrm.h +++ b/Src/MainFrm.h @@ -228,6 +228,7 @@ class CMainFrame : public CMDIFrameWnd CMenuBar* GetMenuBar() { return &m_wndMenuBar; } CToolBar* GetToolbar() { return &m_wndToolBar; } static void WaitAndDoMessageLoop(bool& completed, int ms); + bool IsActivate() const { return m_bActivate; } // Overrides virtual void GetMessageString(UINT nID, CString& rMessage) const; @@ -430,6 +431,7 @@ class CMainFrame : public CMDIFrameWnd afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnDestroy(); afx_msg void OnAccelQuit(); + afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized); afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam); @@ -454,4 +456,5 @@ class CMainFrame : public CMDIFrameWnd bool CompareFilesIfFilesAreLarge(IDirDoc* pDirDoc, int nFiles, const FileLocation ifileloc[]); std::unique_ptr m_upszLongTextW; std::unique_ptr m_upszLongTextA; + bool m_bActivate; };