Skip to content

Commit f43d504

Browse files
committed
Update files, add non-mica acrylic effect
1 parent a513474 commit f43d504

File tree

10 files changed

+150
-119
lines changed

10 files changed

+150
-119
lines changed

Plugin/Plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2020-2022 oZone
2+
Copyright (C) 2020-2022 oZone10
33
This program is free software: you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
55
the Free Software Foundation, either version 3 of the License, or

Plugin/Plugin.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2020-2022 oZone
2+
Copyright (C) 2020-2025 oZone10
33
This program is free software: you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
55
the Free Software Foundation, either version 3 of the License, or

Plugin/PluginDefinition.cpp

Lines changed: 98 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2020-2022 oZone
2+
Copyright (C) 2020-2025 oZone10
33
This program is free software: you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
55
the Free Software Foundation, either version 3 of the License, or
@@ -24,11 +24,11 @@ const wchar_t sectionName[] = L"DarkNpp";
2424

2525
static bool enableDark = false;
2626

27-
int micaType = 0;
27+
static int micaType = 0;
2828

2929
constexpr int menuItemEnableDark = 0;
3030
constexpr int menuItemMica = menuItemEnableDark + 3;
31-
constexpr int menuItemAbout = menuItemMica + 5;
31+
constexpr int menuItemAbout = menuItemMica + 7;
3232

3333
constexpr size_t classNameLenght = 64;
3434

@@ -42,14 +42,16 @@ void PluginInit()
4242

4343
void CommandMenuInit()
4444
{
45-
funcItem[menuItemEnableDark] = { L"Enable Dark Mode", DarkCheckTag, 0, enableDark, nullptr };
45+
funcItem[menuItemEnableDark + 0] = { L"Enable Dark Mode", DarkCheckTag, 0, enableDark, nullptr };
4646
funcItem[menuItemEnableDark + 1] = { L"Refresh Dark Mode", SetDarkNpp, 0, false, nullptr };
4747
funcItem[menuItemEnableDark + 2] = { L"---", nullptr, 0, false, nullptr };
48-
funcItem[menuItemMica] = { L"None", SetMicaTagNone, 0, micaType == 0, nullptr };
49-
funcItem[menuItemMica + 1] = { L"Mica", SetMicaTagMica, 0, micaType == 2, nullptr };
50-
funcItem[menuItemMica + 2] = { L"Acrylic", SetMicaTagAcrylic, 0, micaType == 3, nullptr };
51-
funcItem[menuItemMica + 3] = { L"Tabbed", SetMicaTagTabbed, 0, micaType == 4, nullptr };
52-
funcItem[menuItemMica + 4] = { L"---", nullptr, 0, false, nullptr };
48+
funcItem[menuItemMica + 0] = { L"Auto", SetMicaTagAuto, 0, micaType == 0, nullptr };
49+
funcItem[menuItemMica + 1] = { L"None", SetMicaTagNone, 0, micaType == 1, nullptr };
50+
funcItem[menuItemMica + 2] = { L"Mica", SetMicaTagMica, 0, micaType == 2, nullptr };
51+
funcItem[menuItemMica + 3] = { L"Mica Acrylic", SetMicaTagAcrylic, 0, micaType == 3, nullptr };
52+
funcItem[menuItemMica + 4] = { L"Mica Alternative", SetMicaTagTabbed, 0, micaType == 4, nullptr };
53+
funcItem[menuItemMica + 5] = { L"Acrylic", SetTagAcrylic, 0, micaType == 5, nullptr };
54+
funcItem[menuItemMica + 6] = { L"---", nullptr, 0, false, nullptr };
5355
funcItem[menuItemAbout] = { L"&About...", About, 0, false, nullptr };
5456
}
5557

@@ -67,11 +69,10 @@ void SavePluginParams()
6769
{
6870
funcItem[menuItemEnableDark]._init2Check = enableDark;
6971
::WritePrivateProfileString(sectionName, L"useDark", enableDark ? L"1" : L"0", iniFilePath);
70-
71-
funcItem[menuItemMica]._init2Check = (micaType == 0);
72-
funcItem[menuItemMica + 1]._init2Check = (micaType == 2);
73-
funcItem[menuItemMica + 2]._init2Check = (micaType == 3);
74-
funcItem[menuItemMica + 3]._init2Check = (micaType == 4);
72+
for (int i = 0; i < 6; i++)
73+
{
74+
funcItem[menuItemMica + i]._init2Check = (micaType == i);
75+
}
7576
::WritePrivateProfileString(sectionName, L"micaType", std::to_wstring(micaType).c_str(), iniFilePath);
7677
}
7778

@@ -83,12 +84,18 @@ void DarkCheckTag()
8384
SavePluginParams();
8485
}
8586

86-
void SetMicaTagNone()
87+
void SetMicaTagAuto()
8788
{
8889
micaType = 0;
8990
MicaCheckTag();
9091
}
9192

93+
void SetMicaTagNone()
94+
{
95+
micaType = 1;
96+
MicaCheckTag();
97+
}
98+
9299
void SetMicaTagMica()
93100
{
94101
micaType = 2;
@@ -107,12 +114,21 @@ void SetMicaTagTabbed()
107114
MicaCheckTag();
108115
}
109116

117+
void SetTagAcrylic()
118+
{
119+
micaType = 5;
120+
MicaCheckTag();
121+
}
122+
110123
void MicaCheckTag()
111124
{
112-
::CheckMenuItem(::GetMenu(nppData._nppHandle), funcItem[menuItemMica]._cmdID, MF_BYCOMMAND | (micaType == 0 ? MF_CHECKED : MF_UNCHECKED));
113-
::CheckMenuItem(::GetMenu(nppData._nppHandle), funcItem[menuItemMica + 1]._cmdID, MF_BYCOMMAND | (micaType == 2 ? MF_CHECKED : MF_UNCHECKED));
114-
::CheckMenuItem(::GetMenu(nppData._nppHandle), funcItem[menuItemMica + 2]._cmdID, MF_BYCOMMAND | (micaType == 3 ? MF_CHECKED : MF_UNCHECKED));
115-
::CheckMenuItem(::GetMenu(nppData._nppHandle), funcItem[menuItemMica + 3]._cmdID, MF_BYCOMMAND | (micaType == 4 ? MF_CHECKED : MF_UNCHECKED));
125+
const auto hMenu = ::GetMenu(nppData._nppHandle);
126+
127+
for (int i = 0; i < 6; i++)
128+
{
129+
::CheckMenuItem(hMenu, funcItem[menuItemMica + i]._cmdID, MF_BYCOMMAND | (micaType == i ? MF_CHECKED : MF_UNCHECKED));
130+
}
131+
116132
SetMicaNpp();
117133
SavePluginParams();
118134
}
@@ -123,7 +139,7 @@ void About()
123139
NULL,
124140
L"This is Dark mode & Mica effects Notepad++ test.\n"
125141
L"Plugin is using undocumented WINAPI.\n"
126-
L"@2020-2022 by oZone",
142+
L"@2020-2025 by oZone10",
127143
L"About",
128144
MB_OK);
129145
}
@@ -145,7 +161,7 @@ bool IsAtLeastWin10Build(DWORD buildNumber)
145161

146162
void SetMode(HMODULE hUxtheme)
147163
{
148-
const auto ord135 = GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135));
164+
const auto ord135 = ::GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135));
149165

150166
if (IsAtLeastWin10Build(VER_1903))
151167
{
@@ -173,7 +189,7 @@ void SetMode(HMODULE hUxtheme)
173189

174190
void SetTheme(HWND hWnd)
175191
{
176-
const auto hUxtheme = LoadLibraryEx(L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS | LOAD_LIBRARY_SEARCH_SYSTEM32);
192+
const auto hUxtheme = LoadLibraryEx(L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
177193

178194
if (hUxtheme == nullptr)
179195
{
@@ -203,15 +219,12 @@ void SetTitleBar(HWND hWnd)
203219
if (IsAtLeastWin10Build(BUILD_WIN11))
204220
{
205221
::DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &dark, sizeof(dark));
206-
return;
207222
}
208-
209-
if (IsAtLeastWin10Build(VER_1903))
223+
else if (IsAtLeastWin10Build(VER_1903))
210224
{
211-
const auto hUser32 = ::LoadLibraryEx(L"user32.dll", nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS | LOAD_LIBRARY_SEARCH_SYSTEM32);
225+
const auto hUser32 = ::LoadLibraryEx(L"user32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
212226
if (hUser32)
213227
{
214-
using SWCA = bool (WINAPI*)(HWND hWnd, WINDOWCOMPOSITIONATTRIBDATA* wcaData);
215228
const auto _SetWindowCompositionAttribute = reinterpret_cast<SWCA>(::GetProcAddress(hUser32, "SetWindowCompositionAttribute"));
216229

217230
if (_SetWindowCompositionAttribute != nullptr)
@@ -228,8 +241,10 @@ void SetTitleBar(HWND hWnd)
228241
::FreeLibrary(hUser32);
229242
}
230243
}
231-
232-
::SetProp(hWnd, L"UseImmersiveDarkModeColors", reinterpret_cast<HANDLE>(static_cast<INT_PTR>(dark)));
244+
else if (IsAtLeastWin10Build(VER_1809))
245+
{
246+
::SetProp(hWnd, L"UseImmersiveDarkModeColors", reinterpret_cast<HANDLE>(static_cast<INT_PTR>(dark)));
247+
}
233248
}
234249

235250
void SetTooltips(HWND hWnd)
@@ -295,7 +310,7 @@ BOOL CALLBACK ScrollBarChildProc(HWND hWnd, LPARAM lparam)
295310
const auto dwStyle = ::GetWindowLongPtr(hWnd, GWL_STYLE);
296311
if ((dwStyle & (WS_CHILD | WS_VSCROLL)) > 0x0L)
297312
{
298-
WCHAR className[classNameLenght] = { '\0' };
313+
wchar_t className[classNameLenght] = { '\0' };
299314
if (GetClassName(hWnd, className, classNameLenght) > 0)
300315
{
301316
if ((wcscmp(className, WC_TREEVIEW) == 0) ||
@@ -313,58 +328,74 @@ BOOL CALLBACK ScrollBarChildProc(HWND hWnd, LPARAM lparam)
313328

314329
void SetMica(HWND hWnd)
315330
{
316-
if (IsAtLeastWin10Build(BUILD_22H2))
331+
if (IsAtLeastWin10Build(WIN10_22H2))
317332
{
318-
auto mica = DWMSBT_NONE;
319-
switch (micaType)
320-
{
321-
case 1:
333+
const auto hUser32 = ::LoadLibraryEx(L"user32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
334+
if (hUser32)
322335
{
323-
mica = DWMSBT_AUTO;
324-
}
325-
break;
336+
const auto _SetWindowCompositionAttribute = reinterpret_cast<SWCA>(::GetProcAddress(hUser32, "SetWindowCompositionAttribute"));
326337

327-
case 2:
328-
{
329-
mica = DWMSBT_MAINWINDOW;
338+
if (_SetWindowCompositionAttribute != nullptr)
339+
{
340+
ACCENTPOLICY policy = { (micaType == 5) ? ACCENT_ENABLE_ACRYLICBLURBEHIND : ACCENT_DISABLED, 2, 0x01101010, 0 };
341+
WINDOWCOMPOSITIONATTRIBDATA data = { WCA_ACCENT_POLICY, &policy, sizeof(ACCENTPOLICY) };
342+
_SetWindowCompositionAttribute(hWnd, &data);
343+
}
344+
::FreeLibrary(hUser32);
330345
}
331-
break;
346+
}
332347

333-
case 3:
334-
{
335-
mica = DWMSBT_TRANSIENTWINDOW;
336-
}
337-
break;
348+
constexpr MARGINS marginsExtended = { -1 };
349+
constexpr MARGINS marginsReset{};
338350

339-
case 4:
351+
if (IsAtLeastWin10Build(BUILD_22H2))
352+
{
353+
auto mica = DWMSBT_AUTO;
354+
switch (micaType)
340355
{
341-
mica = DWMSBT_TABBEDWINDOW;
342-
}
343-
break;
356+
case 1:
357+
{
358+
mica = DWMSBT_NONE;
359+
}
360+
break;
344361

345-
default:
346-
{
347-
mica = DWMSBT_NONE;
348-
}
349-
}
362+
case 2:
363+
{
364+
mica = DWMSBT_MAINWINDOW;
365+
}
366+
break;
350367

351-
if (mica != DWMSBT_NONE)
352-
{
353-
constexpr MARGINS margins = { -1 };
354-
::DwmExtendFrameIntoClientArea(hWnd, &margins);
368+
case 3:
369+
{
370+
mica = DWMSBT_TRANSIENTWINDOW;
371+
}
372+
break;
373+
374+
case 4:
375+
{
376+
mica = DWMSBT_TABBEDWINDOW;
377+
}
378+
break;
379+
380+
default:
381+
{
382+
mica = DWMSBT_AUTO;
383+
}
355384
}
385+
386+
::DwmExtendFrameIntoClientArea(hWnd, (mica != DWMSBT_AUTO) ? &marginsExtended : &marginsReset);
356387
::DwmSetWindowAttribute(hWnd, DWMWA_SYSTEMBACKDROP_TYPE, &mica, sizeof(mica));
357388
}
358389
else if (IsAtLeastWin10Build(BUILD_WIN11))
359390
{
360391
const BOOL useMica = (micaType == 0);
361-
if (micaType != 0)
362-
{
363-
constexpr MARGINS margins = { -1 };
364-
::DwmExtendFrameIntoClientArea(hWnd, &margins);
365-
}
392+
::DwmExtendFrameIntoClientArea(hWnd, (micaType != 0) ? &marginsExtended : &marginsReset);
366393
::DwmSetWindowAttribute(hWnd, DWMWA_MICA_EFFECT, &useMica, sizeof(useMica));
367394
}
395+
else
396+
{
397+
::DwmExtendFrameIntoClientArea(hWnd, &marginsReset);
398+
}
368399
}
369400

370401
void SetDarkNpp()
@@ -375,6 +406,8 @@ void SetDarkNpp()
375406
SetTooltips(hwnd);
376407

377408
::EnumChildWindows(hwnd, &ScrollBarChildProc, reinterpret_cast<LPARAM>(enableDark ? L"DarkMode_Explorer" : nullptr));
409+
410+
SetMica(hwnd);
378411
}
379412

380413
void SetMicaNpp()

Plugin/PluginDefinition.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2020-2022 oZone
2+
Copyright (C) 2020-2025 oZone10
33
This program is free software: you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
55
the Free Software Foundation, either version 3 of the License, or
@@ -21,6 +21,8 @@
2121
constexpr DWORD VER_1809 = 17763; // Windows 10 1809 (October 2018 Update)
2222
constexpr DWORD VER_1903 = 18362; // Windows 10 1903 (May 2019 Update)
2323

24+
constexpr DWORD WIN10_22H2 = 19045; // Windows 10 22H2 (Last)
25+
2426
constexpr DWORD BUILD_WIN11 = 22000; // Windows 11 first "stable" build
2527
constexpr DWORD BUILD_22H2 = 22621; // Windows 11 22H2 first to support mica properly
2628

@@ -73,19 +75,40 @@ struct WINDOWCOMPOSITIONATTRIBDATA
7375
SIZE_T cbData;
7476
};
7577

76-
const TCHAR NPP_PLUGIN_NAME[] = L"DarkNpp";
77-
constexpr int nbFunc = 9;
78+
enum AccentTypes : int {
79+
ACCENT_DISABLED = 0,
80+
ACCENT_ENABLE_GRADIENT = 1,
81+
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
82+
ACCENT_ENABLE_BLURBEHIND = 3,
83+
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4,
84+
ACCENT_ENABLE_HOSTBACKDROP = 5,
85+
ACCENT_ENABLE_TRANSPARENT = 6
86+
};
87+
88+
struct ACCENTPOLICY {
89+
AccentTypes nAccentState = AccentTypes::ACCENT_DISABLED;
90+
int32_t nFlags = 0;
91+
uint32_t nColor = 0;
92+
int32_t nAnimationId = 0;
93+
};
94+
95+
using SWCA = bool (WINAPI*)(HWND hWnd, WINDOWCOMPOSITIONATTRIBDATA* wcaData);
96+
97+
const wchar_t NPP_PLUGIN_NAME[] = L"DarkNpp";
98+
constexpr int nbFunc = 11;
7899

79100
void PluginInit();
80101
void CommandMenuInit();
81102

82103
void LoadSettings();
83104
void SavePluginParams();
84105
void DarkCheckTag();
106+
void SetMicaTagAuto();
85107
void SetMicaTagNone();
86108
void SetMicaTagMica();
87109
void SetMicaTagAcrylic();
88110
void SetMicaTagTabbed();
111+
void SetTagAcrylic();
89112
void MicaCheckTag();
90113
void About();
91114

Plugin/StdAfx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2020-2022 oZone
2+
Copyright (C) 2020-2025 oZone10
33
This program is free software: you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
55
the Free Software Foundation, either version 3 of the License, or

Plugin/StdAfx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2020-2022 oZone
2+
Copyright (C) 2020-2025 oZone10
33
This program is free software: you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
55
the Free Software Foundation, either version 3 of the License, or

Plugin/version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2020-2022 oZone
2+
Copyright (C) 2020-2025 oZone10
33
This program is free software: you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
55
the Free Software Foundation, either version 3 of the License, or
@@ -18,8 +18,8 @@
1818

1919
#define VER_PLUGIN_NAME_STR "DarkNpp"
2020
#define VER_PLUGIN_MAJOR 0
21-
#define VER_PLUGIN_MINOR 4
21+
#define VER_PLUGIN_MINOR 5
2222
#define VER_PLUGIN_REVISION 0
2323
#define VER_PLUGIN_BUILD 0
24-
#define VER_PLUGIN_AUTHOR_STR "oZone"
25-
#define VER_PLUGIN_YEAR 2022
24+
#define VER_PLUGIN_AUTHOR_STR "oZone10"
25+
#define VER_PLUGIN_YEAR 2025

0 commit comments

Comments
 (0)