-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathReaperMenuBarThemeDll.cpp
649 lines (591 loc) · 21.5 KB
/
ReaperMenuBarThemeDll.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
#include "UAHMenuBar.h"
#include "utils.h"
#define REAPERAPI_MINIMAL
#define REAPERAPI_WANT_GetMainHwnd
#include "reaper_plugin_functions.h"
int WM_NCACTIVATE_cnt = 0;
int WM_THEMECHANGED_cnt = 0;
int WM_UAHDRAWMENU_cnt = 0;
int WM_UAHDRAWMENUITEM_cnt = 0;
int WM_UAHMEASUREMENUITEM_cnt = 0;
static HTHEME g_menuTheme = nullptr;
void UAHDrawMenuNCBottomLine(HWND hWnd)
{
MENUBARINFO mbi = { sizeof(mbi) };
if (!GetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi))
{
char tmp[200];
sprintf(tmp, "GetMenuBarInfo error %d\n", GetLastError());
OutputDebugStringA(tmp);
return;
}
RECT rcClient = { 0 };
GetClientRect(hWnd, &rcClient);
MapWindowPoints(hWnd, nullptr, (POINT*)&rcClient, 2);
RECT rcWindow = { 0 };
GetWindowRect(hWnd, &rcWindow);
OffsetRect(&rcClient, -rcWindow.left, -rcWindow.top);
// the rcBar is offset by the window rect
RECT rcAnnoyingLine = rcClient;
rcAnnoyingLine.bottom = rcAnnoyingLine.top;
rcAnnoyingLine.top--;
HDC hdc = GetWindowDC(hWnd);
FillRect(hdc, &rcAnnoyingLine, load_config()->menubar_bgbrush);
ReleaseDC(hWnd, hdc);
}
static TCHAR __debug_buff[512];
#undef DBG_HWND
#define DBG_HWND(x,y) \
{ \
swprintf_s(__debug_buff, 512, L"%p", x); \
std::wstringstream ss; \
ss << std::format(L"{:%T}", std::chrono::system_clock::now()) << L" DBG_HWND(0x" << __debug_buff << L") " << L#y << L" "; \
GetWindowText(x, __debug_buff, 512); \
ss << __debug_buff << L" / "; \
GetClassName(x, __debug_buff, 512); \
ss << __debug_buff << std::endl; \
OutputDebugString(ss.str().c_str()); \
}
HHOOK hook_ = nullptr;
HWND main_hwnd{ nullptr };
LRESULT CALLBACK CallWndSubClassProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
// https://gist.github.com/rounk-ctrl/b04e5622e30e0d62956870d5c22b7017
// https://github.com/microsoft/WindowsAppSDK/issues/41
void allowDarkMode(HWND hWnd) {
static HMODULE hUxtheme = NULL;
enum class PreferredAppMode
{
Default,
AllowDark,
ForceDark,
ForceLight,
Max
};
using fnShouldAppsUseDarkMode = bool (WINAPI*)(); // ordinal 132
using fnAllowDarkModeForWindow = bool (WINAPI*)(HWND hWnd, bool allow); // ordinal 133
using fnSetPreferredAppMode = PreferredAppMode(WINAPI*)(PreferredAppMode appMode); // ordinal 135, in 1903
fnSetPreferredAppMode SetPreferredAppMode;
fnAllowDarkModeForWindow AllowDarkModeForWindow;
if (!hUxtheme) {
//DWORD dwFlags = (STAP_ALLOW_NONCLIENT |
// STAP_ALLOW_CONTROLS | STAP_ALLOW_WEBCONTENT);
//SetThemeAppProperties(dwFlags);
HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
ASSERT(hUxtheme);
SetPreferredAppMode = (fnSetPreferredAppMode)GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135));
ASSERT(SetPreferredAppMode);
AllowDarkModeForWindow = (fnAllowDarkModeForWindow)GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133));
ASSERT(AllowDarkModeForWindow);
//SetPreferredAppMode(PreferredAppMode::AllowDark);
SetPreferredAppMode(PreferredAppMode::ForceDark);
//FreeLibrary(hUxtheme);
}
if (hUxtheme && hWnd) {
//SetWindowTheme(hWnd, L"wstr", L"wstr");
SetWindowTheme(hWnd, L"DarkMode_Explorer", NULL);
//SetWindowTheme(hWnd, L"Explorer", NULL);
//SetWindowTheme(hWnd, L"CFD", NULL);
AllowDarkModeForWindow(hWnd, true);
}
}
// https://stackoverflow.com/questions/39261826/change-the-color-of-the-title-bar-caption-of-a-win32-application
void enableImmersiveDarkMode(HWND hWnd) {
BOOL USE_DARK_MODE = true;
BOOL SET_IMMERSIVE_DARK_MODE_SUCCESS = SUCCEEDED(DwmSetWindowAttribute(
hWnd, DWMWINDOWATTRIBUTE::DWMWA_USE_IMMERSIVE_DARK_MODE,
&USE_DARK_MODE, sizeof(USE_DARK_MODE)));
//ASSERT(SET_IMMERSIVE_DARK_MODE_SUCCESS);
}
LRESULT CALLBACK CBTProc(int nCode,
WPARAM wParam, LPARAM lParam)
{
switch (nCode) {
case HCBT_ACTIVATE:
{
HWND hWnd = (HWND)wParam;
DBG_HWND(hWnd, HCBT_ACTIVATE);
break;
}
case HCBT_CREATEWND:
{
HWND hWnd = (HWND)wParam;
DBG_HWND(hWnd, HCBT_CREATEWND);
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
// need to be careful with subclassing (avoiding conflict with SWS plugin)
if (isClass(hWnd, L"REAPERwnd") || isClass(hWnd, L"REAPERMediaExplorerMainwnd")
|| isClass(hWnd, L"#32770") || isClass(hWnd, L"Button") || isClass(hWnd, L"tooltips_class32")
|| isClass(hWnd, L"ComboBox")
// pick some widgets that aren't theme-able and leave the others alone
|| (isClass(hWnd, L"SysListView32") && style & WS_CHILDWINDOW)
|| (isClass(hWnd, L"SysTreeView32") && style & WS_CHILDWINDOW)
) {
enableImmersiveDarkMode(hWnd);
allowDarkMode(hWnd);
BOOL lr = SetWindowSubclass(hWnd, CallWndSubClassProc, 0, 0);
ASSERT(lr);
}
break;
}
case HCBT_DESTROYWND:
{
HWND hWnd = (HWND)wParam;
DBG_HWND(hWnd, HCBT_DESTROYWND);
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
if (isClass(hWnd, L"REAPERwnd") || isClass(hWnd, L"REAPERMediaExplorerMainwnd")
|| isClass(hWnd, L"#32770") || isClass(hWnd, L"Button") || isClass(hWnd, L"tooltips_class32")
|| isClass(hWnd, L"ComboBox")
// pick some widgets that aren't theme-able and leave the others alone
|| (isClass(hWnd, L"SysListView32") && style & WS_CHILDWINDOW)
|| (isClass(hWnd, L"SysTreeView32") && style & WS_CHILDWINDOW)
) {
RemoveWindowSubclass(hWnd, CallWndSubClassProc, 0);
}
break;
}
case HCBT_CLICKSKIPPED:
case HCBT_KEYSKIPPED:
case HCBT_MINMAX:
case HCBT_MOVESIZE:
case HCBT_QS:
case HCBT_SETFOCUS:
case HCBT_SYSCOMMAND:
{
break;
}
default:
break;
}
return 0;
}
// https://stackoverflow.com/questions/16313333/drawing-rounded-and-colored-owner-draw-buttons
void paint_ODT_BUTTON(const DRAWITEMSTRUCT& dis) {
HWND hwnd = dis.hwndItem;
RECT rc;
GetClientRect(hwnd, &rc);
PAINTSTRUCT ps;
//auto hdc = BeginPaint(hwnd, &ps);
auto hdc = dis.hDC;
auto bkcolor = load_config()->menubar_bgcolor;
auto brush = CreateSolidBrush(bkcolor);
auto pen = CreatePen(PS_SOLID, 1, load_config()->menubar_textcolor);
auto oldbrush = SelectObject(hdc, brush);
auto oldpen = SelectObject(hdc, pen);
SelectObject(hdc, (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0));
SetBkColor(hdc, bkcolor);
SetTextColor(hdc, load_config()->menubar_textcolor);
HBRUSH tmp = CreateSolidBrush(RGB(127, 192, 127)); // border
FillRect(hdc, &rc, tmp);
Rectangle(hdc, 0, 0, rc.right, rc.bottom);
if (GetFocus() == hwnd)
{
RECT temp = rc;
InflateRect(&temp, -2, -2);
DrawFocusRect(hdc, &temp);
}
TCHAR buf[128];
GetWindowText(hwnd, buf, 128);
//std::wstringstream ss;
//ss << "paint_ODT_BUTTON button text: " << buf << std::endl;
//OutputDebugString(ss.str().c_str());
DrawText(hdc, buf, -1, &rc, DT_EDITCONTROL | DT_CENTER | DT_VCENTER | DT_SINGLELINE);
SelectObject(hdc, oldpen);
SelectObject(hdc, oldbrush);
DeleteObject(brush);
DeleteObject(pen);
}
LRESULT CALLBACK CallWndSubClassProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
dbgMsg(hWnd, uIdSubclass, uMsg, wParam, lParam);
ASSERT(uIdSubclass == 0);
switch (uMsg) {
case WM_ACTIVATEAPP:
{
break;
}
case WM_CREATE:
{
break;
}
case WM_CTLCOLORBTN:
{
break;
}
case WM_CTLCOLORDLG:
{
HDC hdc = (HDC)wParam;
HWND dialog = (HWND)lParam;
if (!isClass(dialog, L"REAPERRoutePanel"))
return (INT_PTR)load_config()->menubar_bgcolor;
break;
}
case WM_CTLCOLOREDIT:
{
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, load_config()->menubar_textcolor);
SetBkColor(hdcStatic, load_config()->menubar_bgcolor);
return (INT_PTR)load_config()->menubar_bgbrush;
}
case WM_CTLCOLORLISTBOX:
{
if (isClass(hWnd, L"ComboBox")) {
COMBOBOXINFO info;
info.cbSize = sizeof(info);
SendMessage(hWnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)&info);
if ((HWND)lParam == info.hwndList)
{
HDC dc = (HDC)wParam;
SetBkMode(dc, OPAQUE);
SetTextColor(dc, load_config()->menubar_textcolor);
SetBkColor(dc, load_config()->menubar_bgcolor);
return (LRESULT)load_config()->menubar_bgbrush;
}
}
break;
}
case WM_CTLCOLORSCROLLBAR:
{
HDC hdc = reinterpret_cast<HDC>(wParam);
SetTextColor(hdc, load_config()->menubar_textcolor);
SetBkColor(hdc, load_config()->menubar_bgcolor);
return reinterpret_cast<LRESULT>(load_config()->menubar_bgbrush);
break;
}
case WM_CTLCOLORSTATIC:
{
HDC hdc = reinterpret_cast<HDC>(wParam);
SetTextColor(hdc, load_config()->menubar_textcolor);
SetBkColor(hdc, load_config()->menubar_bgcolor);
return reinterpret_cast<LRESULT>(load_config()->menubar_bgbrush);
break;
}
case WM_DRAWITEM:
{
const DRAWITEMSTRUCT& dis = *(DRAWITEMSTRUCT*)lParam;
//TCHAR buf[128];
//GetWindowText(dis.hwndItem, buf, 128);
//DWORD style = GetWindowLongPtr(dis.hwndItem, GWL_STYLE);
//std::wstringstream ss;
//ss << "WM_DRAWITEM button text: " << buf << ", style=" << style << std::endl;
//OutputDebugString(ss.str().c_str());
if (dis.CtlType == ODT_BUTTON) {
if (dis.itemAction) { // & ODA_DRAWENTIRE) {
paint_ODT_BUTTON(dis);
if (dis.itemState & ODS_FOCUS) {
DrawFocusRect(dis.hDC, &dis.rcItem);
}
}
return TRUE;
}
break;
}
case WM_ERASEBKGND:
{
DWORD style = GetWindowLongPtr(hWnd, GWL_STYLE);
switch (LOWORD(style)) {
case BS_GROUPBOX: // 0x7
break;
default:
{
RECT rc;
GetClientRect(hWnd, &rc);
FillRect(reinterpret_cast<HDC>(wParam), &rc, load_config()->menubar_bgbrush);
return TRUE;
break;
}
}
}
case WM_IME_SETCONTEXT:
{
break;
}
case WM_MOVE:
{
break;
}
case WM_NCACTIVATE:
{
if (isClass(hWnd, L"REAPERwnd") || isClass(hWnd, L"REAPERMediaExplorerMainwnd") || isClass(hWnd, L"#32770")) {
WM_NCACTIVATE_cnt++;
LRESULT lr = DefSubclassProc(hWnd, uMsg, wParam, lParam);
UAHDrawMenuNCBottomLine(hWnd);
return lr;
}
break;
}
case WM_NCCREATE:
{
allowDarkMode(hWnd);
enableImmersiveDarkMode(hWnd);
if (isClass(hWnd, L"tooltips_class32")) {
SetWindowTheme(hWnd, L"wstr", L"wstr");
}
else if (isClass(hWnd, L"ComboBox")) {
SetWindowTheme(hWnd, L"wstr", L"wstr");
}
else if (isClass(hWnd, L"Button")) {
DWORD style = GetWindowLongPtr(hWnd, GWL_STYLE);
switch(LOWORD(style)) {
case BS_AUTOCHECKBOX: // 0x3
case BS_AUTORADIOBUTTON: // 0x9
case BS_CHECKBOX: // 0x2
case BS_GROUPBOX: // 0x7
SetWindowTheme(hWnd, L"wstr", L"wstr");
break;
case BS_LEFT: // 0x100
case BS_PUSHBUTTON: // 0x0
case BS_CENTER:
case BS_RIGHT:
case BS_DEFPUSHBUTTON:
style = style | BS_OWNERDRAW;
//style = WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON;
SetWindowLongPtr(hWnd, GWL_STYLE, style);
break;
}
}
break;
}
case WM_NCPAINT:
{
if (isClass(hWnd, L"REAPERwnd") || isClass(hWnd, L"REAPERMediaExplorerMainwnd") || isClass(hWnd, L"#32770")) {
LRESULT lr = DefSubclassProc(hWnd, uMsg, wParam, lParam);
UAHDrawMenuNCBottomLine(hWnd);
return lr;
}
break;
}
case WM_NOTIFY:
{
break;
}
case WM_PAINT:
{
if (isClass(hWnd, L"tooltips_class32")) {
SendMessage(hWnd, TTM_SETTIPBKCOLOR, load_config()->menubar_bgcolor, 0);
SendMessage(hWnd, TTM_SETTIPTEXTCOLOR, load_config()->menubar_textcolor, 0);
}
else if (isClass(hWnd, L"SysTreeView32")) { // left pane of config dialog
TreeView_SetBkColor(hWnd, load_config()->menubar_bgcolor);
TreeView_SetTextColor(hWnd, load_config()->menubar_textcolor);
}
else if (isClass(hWnd, L"SysListView32")) { // left pane of FX dialog
ListView_SetBkColor(hWnd, load_config()->menubar_bgcolor);
ListView_SetTextBkColor(hWnd, load_config()->menubar_bgcolor);
ListView_SetTextColor(hWnd, load_config()->menubar_textcolor);
}
break;
}
case WM_SETFONT:
{
break;
}
case WM_SHOWWINDOW:
{
break;
}
case WM_STYLECHANGING:
case WM_STYLECHANGED:
{
if (isClass(hWnd, L"REAPERwnd")) {
// prevent propagation to prevent menu bar from going back to the standard one...?!? FIXME
return true;
}
break;
}
case WM_THEMECHANGED:
{
if (isClass(hWnd, L"REAPERwnd") || isClass(hWnd, L"REAPERMediaExplorerMainwnd") || isClass(hWnd, L"#32770")) {
WM_THEMECHANGED_cnt++;
if (g_menuTheme) {
CloseThemeData(g_menuTheme);
g_menuTheme = nullptr;
}
}
break;
}
// https://stackoverflow.com/questions/77985210/how-to-set-menu-bar-color-in-win32
case WM_UAHDRAWMENU:
{
if (isClass(hWnd, L"REAPERwnd") || isClass(hWnd, L"REAPERMediaExplorerMainwnd") || isClass(hWnd, L"#32770")) {
WM_UAHDRAWMENU_cnt++;
UAHMENU* pUDM = (UAHMENU*)lParam;
RECT rc = { 0 };
{
MENUBARINFO mbi = { sizeof(mbi) };
GetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
RECT rcWindow;
GetWindowRect(hWnd, &rcWindow);
// the rcBar is offset by the window rect
rc = mbi.rcBar;
OffsetRect(&rc, -rcWindow.left, -rcWindow.top);
}
FillRect(pUDM->hdc, &rc, load_config()->menubar_bgbrush);
return true;
}
break;
}
case WM_UAHDRAWMENUITEM:
{
if (isClass(hWnd, L"REAPERwnd") || isClass(hWnd, L"REAPERMediaExplorerMainwnd") || isClass(hWnd, L"#32770")) {
WM_UAHDRAWMENUITEM_cnt++;
UAHDRAWMENUITEM* pUDMI = (UAHDRAWMENUITEM*)lParam;
const HBRUSH* pbrBackground = &load_config()->menubaritem_bgbrush;
// get the menu item string
wchar_t menuString[256] = { 0 };
MENUITEMINFO mii = { sizeof(mii), MIIM_STRING };
{
mii.dwTypeData = menuString;
mii.cch = (sizeof(menuString) / 2) - 1;
GetMenuItemInfo(pUDMI->um.hmenu, pUDMI->umi.iPosition, TRUE, &mii);
}
// get the item state for drawing
DWORD dwFlags = DT_CENTER | DT_SINGLELINE | DT_VCENTER;
int iTextStateID = 0;
int iBackgroundStateID = 0;
{
if ((pUDMI->dis.itemState & ODS_INACTIVE) | (pUDMI->dis.itemState & ODS_DEFAULT)) {
// normal display
iTextStateID = MPI_NORMAL;
iBackgroundStateID = MPI_NORMAL;
}
if (pUDMI->dis.itemState & ODS_HOTLIGHT) {
// hot tracking
iTextStateID = MPI_HOT;
iBackgroundStateID = MPI_HOT;
pbrBackground = &load_config()->menubaritem_bgbrush_hot;
}
if (pUDMI->dis.itemState & ODS_SELECTED) {
// clicked -- MENU_POPUPITEM has no state for this, though MENU_BARITEM does
iTextStateID = MPI_HOT;
iBackgroundStateID = MPI_HOT;
pbrBackground = &load_config()->menubaritem_bgbrush_selected;
}
if ((pUDMI->dis.itemState & ODS_GRAYED) || (pUDMI->dis.itemState & ODS_DISABLED)) {
// disabled / grey text
iTextStateID = MPI_DISABLED;
iBackgroundStateID = MPI_DISABLED;
}
if (pUDMI->dis.itemState & ODS_NOACCEL) {
dwFlags |= DT_HIDEPREFIX;
}
}
if (!g_menuTheme) {
g_menuTheme = OpenThemeData(hWnd, L"Menu");
}
DTTOPTS opts = { sizeof(opts), DTT_TEXTCOLOR, iTextStateID != MPI_DISABLED ? load_config()->menubar_textcolor : load_config()->menubar_textcolor_disabled };
FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, *pbrBackground);
DrawThemeTextEx(g_menuTheme, pUDMI->um.hdc, MENU_BARITEM, MBI_NORMAL, menuString, mii.cch, dwFlags, &pUDMI->dis.rcItem, &opts);
return true;
}
break;
}
case WM_UAHMEASUREMENUITEM:
{
if (!isClass(hWnd, L"REAPERwnd") && !isClass(hWnd, L"REAPERMediaExplorerMainwnd") && !isClass(hWnd, L"#32770")) {
WM_UAHMEASUREMENUITEM_cnt++;
UAHMEASUREMENUITEM* pMmi = (UAHMEASUREMENUITEM*)lParam;
// allow the default window procedure to handle the message
// since we don't really care about changing the width
//*lr = DefWindowProc(hWnd, message, wParam, lParam);
LRESULT lr = DefSubclassProc(hWnd, uMsg, wParam, lParam);
// but we can modify it here to make it 1/3rd wider for example
//pMmi->mis.itemWidth = (pMmi->mis.itemWidth * 4) / 3;
return lr;
}
break;
}
case WM_ENTERIDLE:
{
break;
}
default:
break;
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
bool APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpRes)
{
OutputDebugString(L"DllMain");
static int cnt = 0;
switch (reason)
{
case DLL_PROCESS_ATTACH:
{
//while (!IsDebuggerPresent()) {
// Sleep(100);
//}
OutputDebugString(L"DLL_PROCESS_ATTACH\n");
cnt++;
ASSERT(cnt == 1);
allowDarkMode(NULL);
// catch windows that have been created before we set up the CBTProc hook
std::vector<HWND> vec;
std::wstringstream ss;
GetAllWindowsFromProcessID(GetCurrentProcessId(), vec);
ss << L"GetAllWindowsFromProcessID " << vec.size() << std::endl;
OutputDebugString(ss.str().c_str());
for (const HWND& h : vec) {
dbgMsg(h, 0, 0, 0, 0);
BOOL lr = SetWindowSubclass(h, CallWndSubClassProc, 0, 0);
ASSERT(lr);
enableImmersiveDarkMode(h);
allowDarkMode(h);
}
ASSERT(!hook_);
hook_ = SetWindowsHookEx(WH_CBT, CBTProc, NULL, GetCurrentThreadId());
ASSERT(hook_);
OutputDebugString(L"CBT Hook installed.\n");
break;
}
case DLL_THREAD_ATTACH:
OutputDebugString(L"DLL_THREAD_ATTACH\n");
break;
case DLL_THREAD_DETACH:
OutputDebugString(L"DLL_THREAD_DETACH\n");
break;
case DLL_PROCESS_DETACH:
OutputDebugString(L"DLL_PROCESS_DETACH\n");
if (hook_) {
UnhookWindowsHookEx(hook_);
hook_ = NULL;
OutputDebugString(L"CBT Hook uninstalled.\n");
}
std::wstringstream str;
str << L"WM_NCACTIVATE_cnt = " << WM_NCACTIVATE_cnt << std::endl;
str << L"WM_THEMECHANGED_cnt = " << WM_THEMECHANGED_cnt << std::endl;
str << L"WM_UAHDRAWMENU_cnt = " << WM_UAHDRAWMENU_cnt << std::endl;
str << L"WM_UAHDRAWMENUITEM_cnt = " << WM_UAHDRAWMENUITEM_cnt << std::endl;
str << L"WM_UAHMEASUREMENUITEM_cnt = " << WM_UAHMEASUREMENUITEM_cnt << std::endl;
OutputDebugString(str.str().c_str());
break;
}
return true;
}
REAPER_PLUGIN_HINSTANCE g_hInst{ nullptr };
extern "C" {
REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hInstance, reaper_plugin_info_t* rec)
{
OutputDebugString(L"REAPER_PLUGIN_ENTRYPOINT\n");
ASSERT(hInstance);
g_hInst = hInstance;
if (rec)
{
if (rec->caller_version != REAPER_PLUGIN_VERSION || !rec->GetFunc) {
OutputDebugString(L"REAPER_PLUGIN_ENTRYPOINT: ERROR\n");
return 0;
}
*((void**)&GetMainHwnd) = rec->GetFunc("GetMainHwnd");
ASSERT(GetMainHwnd);
main_hwnd = GetMainHwnd();
ASSERT(main_hwnd);
OutputDebugString(L"REAPER_PLUGIN_ENTRYPOINT: SUCCESS\n");
return 1;
}
else
{
OutputDebugString(L"REAPER_PLUGIN_ENTRYPOINT: ERROR\n");
return 0;
}
}
}