2
0
forked from Ivasoft/DSView

on windows, able to use dark style for native title

This commit is contained in:
dreamsourcelabTAI
2024-01-19 15:13:54 +08:00
parent 3312a13906
commit ed65bba7e3
3 changed files with 91 additions and 3 deletions

View File

@@ -72,10 +72,10 @@ MainFrame::MainFrame()
AppControl::Instance()->SetTopWindow(this);
#ifdef Q_OS_DARWIN
_is_native_title = false;
#ifdef _WIN32
_is_native_title = true;
#else
_is_native_title = true;
_is_native_title = false;
#endif
setMinimumWidth(MainWindow::Min_Width);

View File

@@ -117,6 +117,7 @@ namespace pv
_frame = parent;
assert(title_bar);
assert(_frame);
_title_bar = title_bar;
AppControl::Instance()->add_font_form(title_bar);
@@ -1425,6 +1426,10 @@ namespace pv
qApp->setStyleSheet(qss.readAll());
qss.close();
#ifdef _WIN32
setDark_Titlebar(reinterpret_cast<HWND>(_frame->winId()), style == THEME_STYLE_DARK);
#endif
data_updated();
}
@@ -2191,4 +2196,28 @@ namespace pv
_view->update_all_trace_postion();
}
#ifdef _WIN32
void MainWindow::setDark_Titlebar(HWND hwnd, bool isDarkStyle)
{
HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
HMODULE hUser32 = GetModuleHandleW(L"user32.dll");
fnAllowDarkModeForWindow AllowDarkModeForWindow
= reinterpret_cast<fnAllowDarkModeForWindow>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133)));
fnSetPreferredAppMode SetPreferredAppMode
= reinterpret_cast<fnSetPreferredAppMode>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135)));
fnSetWindowCompositionAttribute SetWindowCompositionAttribute
= reinterpret_cast<fnSetWindowCompositionAttribute>(GetProcAddress(hUser32, "SetWindowCompositionAttribute"));
SetPreferredAppMode(AllowDark);
BOOL dark = isDarkStyle;
AllowDarkModeForWindow(hwnd, dark);
WINDOWCOMPOSITIONATTRIBDATA data = {
WCA_USEDARKMODECOLORS,
&dark,
sizeof(dark)
};
SetWindowCompositionAttribute(hwnd, &data);
}
#endif
} // namespace pv

View File

@@ -34,6 +34,61 @@
#include <chrono>
#include "dstimer.h"
#ifdef _WIN32
#include <Windows.h>
#include <dwmapi.h>
#pragma comment (lib, "Dwmapi.lib")
enum PreferredAppMode {
Default,
AllowDark,
ForceDark,
ForceLight,
Max
};
enum WINDOWCOMPOSITIONATTRIB {
WCA_UNDEFINED = 0,
WCA_NCRENDERING_ENABLED = 1,
WCA_NCRENDERING_POLICY = 2,
WCA_TRANSITIONS_FORCEDISABLED = 3,
WCA_ALLOW_NCPAINT = 4,
WCA_CAPTION_BUTTON_BOUNDS = 5,
WCA_NONCLIENT_RTL_LAYOUT = 6,
WCA_FORCE_ICONIC_REPRESENTATION = 7,
WCA_EXTENDED_FRAME_BOUNDS = 8,
WCA_HAS_ICONIC_BITMAP = 9,
WCA_THEME_ATTRIBUTES = 10,
WCA_NCRENDERING_EXILED = 11,
WCA_NCADORNMENTINFO = 12,
WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
WCA_VIDEO_OVERLAY_ACTIVE = 14,
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
WCA_DISALLOW_PEEK = 16,
WCA_CLOAK = 17,
WCA_CLOAKED = 18,
WCA_ACCENT_POLICY = 19,
WCA_FREEZE_REPRESENTATION = 20,
WCA_EVER_UNCLOAKED = 21,
WCA_VISUAL_OWNER = 22,
WCA_HOLOGRAPHIC = 23,
WCA_EXCLUDED_FROM_DDA = 24,
WCA_PASSIVEUPDATEMODE = 25,
WCA_USEDARKMODECOLORS = 26,
WCA_LAST = 27
};
struct WINDOWCOMPOSITIONATTRIBDATA {
WINDOWCOMPOSITIONATTRIB Attrib;
PVOID pvData;
SIZE_T cbData;
};
using fnAllowDarkModeForWindow = BOOL (WINAPI *)(HWND hWnd, BOOL allow);
using fnSetPreferredAppMode = PreferredAppMode (WINAPI *)(PreferredAppMode appMode);
using fnSetWindowCompositionAttribute = BOOL (WINAPI *)(HWND hwnd, WINDOWCOMPOSITIONATTRIBDATA *);
#endif
class QAction;
class QMenuBar;
class QMenu;
@@ -157,6 +212,10 @@ private:
QJsonArray get_decoder_json_from_data_file(QString file, bool &bSucesss);
void check_config_file_version();
void load_demo_decoder_config(QString optname);
#ifdef _WIN32
static void setDark_Titlebar(HWND hwnd, bool isDarkStyle);
#endif
private:
//ISessionCallback