我正在寻找如何获得系统主题颜色。我找到了 GetSysColor 和 GetSysColorBrush。然后我用类似的东西对其进行了测试:
cout << GetSysColorBrush(COLOR_HIGHLIGHT) << endl; //checking the value if it's changing when
//changing system color
WNDCLASSW wc = {0};
wc.hbrBackground = GetSysColorBrush(COLOR_HIGHLIGHT);
wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
wc.hInstance = hInst;
wc.lpfnWndProc = WindowProc;
wc.lpszClassName = L"WindowClass";
if(!RegisterClassW(&wc)) return -1;
CreateWindowW(L"WindowClass", L"Window Name", WS_VISIBLE | WS_POPUP, 0, 0, windowWidth - 500,
windowHeight - 500, NULL, NULL, NULL, NULL);
我认为它可以工作,因为我有默认的蓝色主题并且窗口是蓝色的(完全相同的颜色),然后我将主题更改为绿色但窗口仍然是蓝色的(显然在重新启动程序之后)。
现在我的问题是:是否可以获得当前的系统主题颜色?
最佳答案
Windows 10 主题颜色可通过 UISettings 获得类型。它也适用于经典桌面应用程序。
以下代码使用C++/WinRT检索当前选择的强调色:
#include <winrt/Windows.UI.ViewManagement.h>
#include <iostream>
using namespace winrt;
using namespace Windows::UI::ViewManagement;
int main()
{
UISettings const ui_settings {};
auto const accent_color { ui_settings.GetColorValue(UIColorType::Accent) };
std::wcout << L"R: " << accent_color.R
<< L" G: " << accent_color.G
<< L" B: " << accent_color.B << std::endl;
}
关于c++ - 在经典 C++ WinAPI (Win32) 应用程序中获取 Windows 10 主题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63159666/