Add dark title bar support for Windows 11.

This commit is contained in:
okrc 2022-10-06 02:16:24 +08:00
parent 59c3829c08
commit e57ce2dc37
No known key found for this signature in database
GPG Key ID: 7BFFDD3B3BF40F01
2 changed files with 44 additions and 0 deletions

View File

@ -83,6 +83,12 @@ public:
if (theGUI && theConf->GetInt("Options/UseDarkTheme", 2) == 2)
theGUI->UpdateTheme();
}
else if (msg->message == WM_SHOWWINDOW && msg->wParam)
{
QWidget* pWidget = QWidget::find((WId)msg->hwnd);
if (theGUI && pWidget && (pWidget->windowType() | Qt::Dialog) == Qt::Dialog)
theGUI->UpdateTitleTheme(msg->hwnd);
}
}
return false;
}
@ -2919,6 +2925,37 @@ void CSandMan::SetUITheme()
font.setPointSizeF(newFontSize);
QApplication::setFont(font);
}
#if defined(Q_OS_WIN)
foreach(QWidget * pWidget, QApplication::topLevelWidgets())
{
if (pWidget->isVisible())
SetTitleTheme((HWND)pWidget->winId());
}
#endif
}
void CSandMan::SetTitleTheme(const HWND& hwnd)
{
static const int CurrentVersion = QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
QSettings::NativeFormat).value("CurrentBuild").toInt();
if (CurrentVersion < 22000) // Windows 11-
return;
HMODULE dwmapi = GetModuleHandle(L"dwmapi.dll");
if (dwmapi)
{
typedef HRESULT(WINAPI* P_DwmSetWindowAttribute)(HWND, DWORD, LPCVOID, DWORD);
P_DwmSetWindowAttribute pDwmSetWindowAttribute = reinterpret_cast<P_DwmSetWindowAttribute>(GetProcAddress(dwmapi, "DwmSetWindowAttribute"));
if (pDwmSetWindowAttribute)
{
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif
BOOL value = m_DarkTheme;
pDwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
}
}
}
void CSandMan::UpdateTheme()
@ -2930,6 +2967,11 @@ void CSandMan::UpdateTheme()
}
}
void CSandMan::UpdateTitleTheme(const HWND& hwnd)
{
SetTitleTheme(hwnd);
}
void CSandMan::LoadLanguage()
{
QString Lang = theConf->GetString("Options/UiLanguage");

View File

@ -72,6 +72,7 @@ public:
bool CheckCertificate(QWidget* pWidget);
void UpdateTheme();
void UpdateTitleTheme(const HWND& hwnd);
void UpdateCertState();
@ -221,6 +222,7 @@ private slots:
void OnSysTray(QSystemTrayIcon::ActivationReason Reason);
void SetUITheme();
void SetTitleTheme(const HWND& hwnd);
void AddLogMessage(const QString& Message);
void AddFileRecovered(const QString& BoxName, const QString& FilePath);