comparison foosdk/sdk/libPPUI/DarkMode.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #pragma once
2 #include <functional>
3 #include <list>
4
5 namespace DarkMode {
6 // Is dark mode supported on this system or not?
7 bool IsSupportedSystem();
8 // Is system in dark mode or not?
9 bool QueryUserOption();
10
11 // Darken menus etc app-wide
12 void SetAppDarkMode(bool bDark);
13 // Darken window title bar
14 void UpdateTitleBar(HWND wnd, bool bDark );
15 void ApplyDarkThemeCtrl(HWND ctrl, bool bDark, const wchar_t * ThemeID = L"Explorer");
16 void ApplyDarkThemeCtrl2(HWND ctrl, bool bDark, const wchar_t* ThemeID_light = L"Explorer", const wchar_t* ThemeID_dark = L"DarkMode_Explorer");
17 void AllowDarkModeForWindow(HWND wnd, bool bDark);
18
19 // One-shot version of darkening function for editboxes
20 void DarkenEditLite(HWND ctrl);
21 // One-shot version of darkening function for comboboxes
22 void DarkenComboLite(HWND ctrl);
23
24 // Returns if the dialog appears to be using dark mode (text brighter than background)
25 bool IsDialogDark(HWND dlg, UINT msgSend = WM_CTLCOLORDLG);
26 // Returns if the DC appears to be using dark mode (text brighter than background)
27 bool IsDCDark(HDC dc);
28
29 // Returns if these colors (text, background) look like dark theme
30 bool IsThemeDark(COLORREF text, COLORREF background);
31
32 COLORREF GetSysColor(int, bool bDark = true);
33
34 LRESULT CustomDrawToolbar(NMHDR*);
35 // Custom draw handler that paints registered darkened controls.
36 // Can be used with NOTIFY_CODE_HANDLER() directly
37 LRESULT OnCustomDraw(int, NMHDR*, BOOL & bHandled);
38
39 // Handle WM_NCPAINT drawing dark frame
40 void NCPaintDarkFrame(HWND ctrl, HRGN rgn);
41
42 bool IsHighContrast();
43
44 // msgSetDarkMode
45 // return 1 if understood, 0 otherwise
46 // WPARAM = 0, DISABLE dark mode
47 // WPARAM = 1, ENABLE dark mode
48 // WPARAM = -1, query if supported
49 UINT msgSetDarkMode();
50
51 //! CHooks class: entrypoint class for all Dark Mode hacks. \n
52 //! Usage: Keep CHooks m_dark = detectDarkMode(); as a member of your window class, replacing detectDarkMode() with your own function returning dark mode on/off state. \n
53 //! When initializing your window (WM_CREATE, WM_INITDIALOG), call m_dark.AddDialogWithControls(m_hWnd); \n
54 //! AddDialogWithControls() walks all child windows of your window; call other individual methods to finetune handling of Dark Mode if that's not acceptable in your case.
55 class CHooks {
56 public:
57 CHooks(bool enabled = false) : m_dark(enabled) {}
58 CHooks(const CHooks&) = delete;
59 void operator=(const CHooks&) = delete;
60
61 void AddDialog(HWND);
62 void AddTabCtrl(HWND);
63 void AddComboBox(HWND);
64 void AddComboBoxEx(HWND);
65 void AddButton(HWND);
66 void AddEditBox(HWND);
67 void AddPopup(HWND);
68 void AddStatusBar(HWND);
69 void AddScrollBar(HWND);
70 void AddToolBar(HWND, bool bExplorerTheme = true);
71 void AddReBar(HWND);
72 void AddStatic(HWND);
73 void AddUpDown(HWND);
74 void AddListBox(HWND);
75 void AddListView(HWND);
76 void AddTreeView(HWND);
77 void AddPPListControl(HWND);
78
79
80 // SetWindowTheme with DarkMode_Explorer <=> Explorer
81 void AddGeneric(HWND, const wchar_t * name = L"explorer");
82 // SetWindowTheme(wnd, L"", L"") for dark, Explorer theme for normal
83 void AddClassic(HWND, const wchar_t* normalTheme = L"explorer");
84
85 void AddCtrlAuto(HWND);
86 void AddCtrlMsg(HWND);
87
88 void AddDialogWithControls(HWND);
89 void AddControls(HWND wndParent);
90
91 void SetDark(bool v = true);
92 bool IsDark() const { return m_dark; }
93 operator bool() const { return m_dark; }
94
95 ~CHooks() { clear(); }
96 void clear();
97
98 void AddApp();
99 private:
100 template<typename obj_t> void addObj(obj_t* arg) {
101 m_apply.push_back([arg, this] { arg->SetDark(m_dark); });
102 m_cleanup.push_back([arg] { delete arg; });
103 }
104 void addOp(std::function<void()> f) { f(); m_apply.push_back(f); }
105 bool m_dark = false;
106 std::list<std::function<void()> > m_apply;
107 std::list<std::function<void()> > m_cleanup;
108
109 void flushMoveToBack();
110 std::list<HWND> m_lstMoveToBack;
111 };
112 }