馋了Java Swing的Flatlaf Darkmode样式的标题栏好久了x
typedef HRESULT (WINAPI* DwmSetWindowAttribute)(HWND, DWORD, LPCVOID, DWORD);
typedef HRESULT (WINAPI* SetWindowTheme)(HWND, const wchar_t*, const wchar_t*);
static DwmSetWindowAttribute pDwmSetWindowAttribute = 0;
static SetWindowTheme pSetWindowTheme = 0;
void setDarkTitle() {
HMODULE dwm = LoadLibraryA("dwmapi.dll");
HMODULE uxtheme = LoadLibraryA("uxtheme.dll");
if (dwm && uxtheme) {
pDwmSetWindowAttribute = reinterpret_cast<DwmSetWindowAttribute>(GetProcAddress(dwm, "DwmSetWindowAttribute"));
pSetWindowTheme = reinterpret_cast<SetWindowTheme>(GetProcAddress(uxtheme, "SetWindowTheme"));
if (pDwmSetWindowAttribute && pSetWindowTheme) {
HWND w = GetConsoleWindow();
pSetWindowTheme(w, L"DarkMode_Explorer", NULL);
BOOL dark = 1;
if (S_OK != pDwmSetWindowAttribute(w, 20, &dark, sizeof dark)) {
pDwmSetWindowAttribute(w, 19, &dark, sizeof dark);
}
// force dwm redraw title
RECT rect = { NULL };
if (GetWindowRect(w, &rect)) {
SetWindowPos(w, NULL, rect.left, rect.top, rect.right - rect.left - 1, rect.bottom - rect.top,
SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
SetWindowPos(w, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
}
}
}
}
上一篇
下一篇