梦是幽蓝色彩 灵魂如雪纯白
馋了Java Swing的Flatlaf Darkmode样式的标题栏好久了x
12345678910111213141516171819202122232425262728293031323334
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); } } }}