-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWinMTRDarkHeaderCtrl.cpp
More file actions
52 lines (42 loc) · 1.49 KB
/
Copy pathWinMTRDarkHeaderCtrl.cpp
File metadata and controls
52 lines (42 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "WinMTRGlobal.h"
#include "WinMTRDarkHeaderCtrl.h"
BEGIN_MESSAGE_MAP(WinMTRDarkHeaderCtrl, CHeaderCtrl)
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
BOOL WinMTRDarkHeaderCtrl::OnEraseBkgnd(CDC* pDC)
{
if(!WinMTRIsDarkModeEnabled()) {
return CHeaderCtrl::OnEraseBkgnd(pDC);
}
CRect rect;
GetClientRect(&rect);
pDC->FillSolidRect(rect, WinMTRGetThemeColors().controlBackground);
return TRUE;
}
void WinMTRDarkHeaderCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
CRect rect(lpDrawItemStruct->rcItem);
const WinMTRThemeColors& colors = WinMTRGetThemeColors();
const bool dark = WinMTRIsDarkModeEnabled();
COLORREF background = dark ? colors.controlBackground : ::GetSysColor(COLOR_BTNFACE);
COLORREF textColor = dark ? colors.textColor : ::GetSysColor(COLOR_BTNTEXT);
COLORREF borderColor = dark ? RGB(85, 85, 85) : ::GetSysColor(COLOR_3DSHADOW);
dc.FillSolidRect(rect, background);
dc.Draw3dRect(rect, borderColor, borderColor);
HDITEM item = {0};
char text[256] = {0};
item.mask = HDI_TEXT | HDI_FORMAT;
item.pszText = text;
item.cchTextMax = sizeof(text) - 1;
GetItem(static_cast<int>(lpDrawItemStruct->itemID), &item);
CRect textRect(rect);
textRect.DeflateRect(6, 2);
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(textColor);
UINT format = DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
format |= (item.fmt & HDF_CENTER) ? DT_CENTER : ((item.fmt & HDF_RIGHT) ? DT_RIGHT : DT_LEFT);
dc.DrawText(text, textRect, format);
dc.Detach();
}