Skip to content

Commit

Permalink
Improve display in high contrast mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Oct 20, 2024
1 parent 2c84ba4 commit daf6120
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
13 changes: 10 additions & 3 deletions Src/Common/MDITabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ static COLORREF getBackColor(bool onTitleBar)
return RGB(GetRValue(clr), std::clamp(GetGValue(clr) + 8, 0, 255), std::clamp(GetBValue(clr) + 8, 0, 255));
}

static inline bool IsHighContrastEnabled()
{
HIGHCONTRAST hc = { sizeof(HIGHCONTRAST) };
SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(hc), &hc, 0);
return (hc.dwFlags & HCF_HIGHCONTRASTON) != 0;
}

void CMyTabCtrl::OnPaint()
{
CPaintDC dc(this);
Expand Down Expand Up @@ -360,16 +367,16 @@ void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
if (lpDraw->itemState & ODS_SELECTED)
{
const COLORREF clrShadow = CEColor::GetIntermediateColor(GetSysColor(COLOR_3DSHADOW), getBackColor(m_bOnTitleBar), 0.5f);
if (GetSysColor(COLOR_3DFACE) == GetSysColor(COLOR_WINDOW))
if (IsHighContrastEnabled())
{
DrawRoundedRectWithShadow(lpDraw->hDC, rc.left + sw, rc.top + sw - 1, rc.Width() - sw * 2, rc.top - sw * 2 + 2, r, sw,
DrawRoundedRectWithShadow(lpDraw->hDC, rc.left + sw, rc.top + sw - 1, rc.Width() - sw * 2, rc.Height() - rc.top - sw * 2 + 2, r, sw,
GetSysColor(COLOR_HIGHLIGHT), clrShadow, getBackColor(m_bOnTitleBar));
SetTextColor(lpDraw->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
}
else
{
DrawRoundedRectWithShadow(lpDraw->hDC, rc.left + sw, rc.top + sw - 1, rc.Width() - sw * 2, rc.Height() - sw * 2 + 2, r, sw,
GetSysColor(COLOR_WINDOW), clrShadow, getBackColor(m_bOnTitleBar));
GetSysColor(COLOR_3DHIGHLIGHT), clrShadow, getBackColor(m_bOnTitleBar));
SetTextColor(lpDraw->hDC, getTextColor());
}
}
Expand Down
2 changes: 2 additions & 0 deletions Src/FilepathEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,12 @@ void CFilepathEdit::OnPaint()
{
CClientDC dc(this);
CFont *pFontOld = dc.SelectObject(GetFont());
int oldTextColor = dc.SetTextColor(m_crText);
int oldBkMode = dc.SetBkMode(TRANSPARENT);
CRect rc = GetMenuCharRect(&dc);
dc.TextOutW(rc.left, 0, IsWin7_OrGreater() ? _T("\u2261") : _T("="));
dc.SetBkMode(oldBkMode);
dc.SetTextColor(oldTextColor);
dc.SelectObject(pFontOld);
}
}
Expand Down
11 changes: 9 additions & 2 deletions Src/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ CMenuBar::CMenuBar()
m_pThis = this;
}

static inline bool IsHighContrastEnabled()
{
HIGHCONTRAST hc = { sizeof(HIGHCONTRAST) };
SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(hc), &hc, 0);
return (hc.dwFlags & HCF_HIGHCONTRASTON) != 0;
}

static TBBUTTON makeTBButton(int id, const TCHAR* str)
{
TBBUTTON btn{ I_IMAGENONE, id, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_DROPDOWN | BTNS_AUTOSIZE };
Expand Down Expand Up @@ -211,8 +218,8 @@ void CMenuBar::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
}
else if (dwDrawState == CDDS_ITEMPREPAINT)
{
pNMCD->clrHighlightHotTrack = GetSysColor(COLOR_3DFACE);
pNMCD->clrText = GetSysColor(COLOR_MENUTEXT);
pNMCD->clrHighlightHotTrack = GetSysColor(IsHighContrastEnabled() ? COLOR_HIGHLIGHT : COLOR_3DFACE);
pNMCD->clrText = GetSysColor(COLOR_BTNTEXT);
*pResult = CDRF_DODEFAULT | TBCDRF_USECDCOLORS | TBCDRF_HILITEHOTTRACK;
return;
}
Expand Down
10 changes: 9 additions & 1 deletion Src/MyReBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ CMyReBar::CMyReBar()
{
}

static inline bool IsHighContrastEnabled()
{
HIGHCONTRAST hc = { sizeof(HIGHCONTRAST) };
SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(hc), &hc, 0);
return (hc.dwFlags & HCF_HIGHCONTRASTON) != 0;
}

BOOL CMyReBar::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(&rect);
pDC->FillSolidRect(&rect, GetSysColor(COLOR_3DHIGHLIGHT));
pDC->FillSolidRect(&rect, GetSysColor(
IsHighContrastEnabled() ? COLOR_BTNFACE : COLOR_3DHIGHLIGHT));
return TRUE;
}

Expand Down

0 comments on commit daf6120

Please sign in to comment.