Workaround Microsoft dark mode API bug of Windows 11
Notepad++ dark mode works fine under Microsft Windows 7, 8, 8.1 & 10. Under Windows 11 while Notepad++ being switched into dark mode, the hightlighting (background) of toolbar's hot-track icons remains in light mode. Hence this workaround to remedy Notepad++ dark mode visual glitchy due to the bug of Windows 11. Fix #10510, close #10685
This commit is contained in:
parent
d80b0b254e
commit
5d086f93a8
|
@ -258,6 +258,11 @@ constexpr bool CheckBuildNumber(DWORD buildNumber)
|
|||
buildNumber >= 22000); // Windows 11 insider builds
|
||||
}
|
||||
|
||||
bool IsWindows11() // or later OS version
|
||||
{
|
||||
return (g_buildNumber >= 22000);
|
||||
}
|
||||
|
||||
void InitDarkMode()
|
||||
{
|
||||
fnRtlGetNtVersionNumbers RtlGetNtVersionNumbers = nullptr;
|
||||
|
|
|
@ -15,3 +15,4 @@ void AllowDarkModeForApp(bool allow);
|
|||
void EnableDarkScrollBarForWindowAndChildren(HWND hwnd);
|
||||
void InitDarkMode();
|
||||
void SetDarkMode(bool useDarkMode, bool fixDarkScrollbar);
|
||||
bool IsWindows11();
|
||||
|
|
|
@ -364,6 +364,11 @@ namespace NppDarkMode
|
|||
return g_darkModeSupported;
|
||||
}
|
||||
|
||||
bool isWindows11()
|
||||
{
|
||||
return IsWindows11();
|
||||
}
|
||||
|
||||
COLORREF invertLightness(COLORREF c)
|
||||
{
|
||||
WORD h = 0;
|
||||
|
@ -1146,34 +1151,6 @@ namespace NppDarkMode
|
|||
SetWindowSubclass(hwnd, GroupboxSubclass, g_groupboxSubclassID, pButtonData);
|
||||
}
|
||||
|
||||
constexpr UINT_PTR g_toolbarSubclassID = 42;
|
||||
|
||||
LRESULT CALLBACK ToolbarSubclass(
|
||||
HWND hWnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam,
|
||||
UINT_PTR uIdSubclass,
|
||||
DWORD_PTR dwRefData
|
||||
)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(uIdSubclass);
|
||||
UNREFERENCED_PARAMETER(dwRefData);
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_NCDESTROY:
|
||||
RemoveWindowSubclass(hWnd, ToolbarSubclass, g_toolbarSubclassID);
|
||||
break;
|
||||
}
|
||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
void subclassToolbarControl(HWND hwnd)
|
||||
{
|
||||
SetWindowSubclass(hwnd, ToolbarSubclass, g_toolbarSubclassID, 0);
|
||||
}
|
||||
|
||||
constexpr UINT_PTR g_tabSubclassID = 42;
|
||||
|
||||
LRESULT CALLBACK TabSubclass(
|
||||
|
|
|
@ -83,6 +83,8 @@ namespace NppDarkMode
|
|||
bool isDarkMenuEnabled();
|
||||
bool isExperimentalSupported();
|
||||
|
||||
bool isWindows11();
|
||||
|
||||
COLORREF invertLightness(COLORREF c);
|
||||
COLORREF invertLightnessSofter(COLORREF c);
|
||||
double calculatePerceivedLighness(COLORREF c);
|
||||
|
@ -145,7 +147,6 @@ namespace NppDarkMode
|
|||
|
||||
void subclassButtonControl(HWND hwnd);
|
||||
void subclassGroupboxControl(HWND hwnd);
|
||||
void subclassToolbarControl(HWND hwnd);
|
||||
void subclassTabControl(HWND hwnd);
|
||||
void subclassComboBoxControl(HWND hwnd);
|
||||
|
||||
|
|
|
@ -306,6 +306,11 @@ void ToolBar::reset(bool create)
|
|||
{
|
||||
setDefaultImageListDM();
|
||||
setDisableImageListDM();
|
||||
|
||||
if (NppDarkMode::isWindows11())
|
||||
{
|
||||
setHoveredImageListDM();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -319,6 +324,11 @@ void ToolBar::reset(bool create)
|
|||
{
|
||||
setDefaultImageListDM2();
|
||||
setDisableImageListDM2();
|
||||
|
||||
if (NppDarkMode::isWindows11())
|
||||
{
|
||||
setHoveredImageListDM2();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -534,8 +544,7 @@ void ReBar::init(HINSTANCE hInst, HWND hPere)
|
|||
_hSelf = CreateWindowEx(WS_EX_TOOLWINDOW,
|
||||
REBARCLASSNAME,
|
||||
NULL,
|
||||
WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|RBS_VARHEIGHT|
|
||||
CCS_NODIVIDER | CCS_NOPARENTALIGN,
|
||||
WS_CHILD|WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | RBS_VARHEIGHT | CCS_NODIVIDER | CCS_NOPARENTALIGN,
|
||||
0,0,0,0, _hParent, NULL, _hInst, NULL);
|
||||
|
||||
SetWindowSubclass(_hSelf, RebarSubclass, g_rebarSubclassID, 0);
|
||||
|
|
|
@ -147,6 +147,14 @@ private :
|
|||
::SendMessage(_hSelf, TB_SETDISABLEDIMAGELIST, 0, reinterpret_cast<LPARAM>(_toolBarIcons.getDisableLstSetDM2()));
|
||||
};
|
||||
|
||||
void setHoveredImageListDM() {
|
||||
::SendMessage(_hSelf, TB_SETHOTIMAGELIST, 0, reinterpret_cast<LPARAM>(_toolBarIcons.getDefaultLst()));
|
||||
};
|
||||
|
||||
void setHoveredImageListDM2() {
|
||||
::SendMessage(_hSelf, TB_SETHOTIMAGELIST, 0, reinterpret_cast<LPARAM>(_toolBarIcons.getDefaultLstSet2()));
|
||||
};
|
||||
|
||||
void reset(bool create = false);
|
||||
void setState(toolBarStatusType state) {
|
||||
_state = state;
|
||||
|
|
Loading…
Reference in New Issue