我正在搜索如何获取系统主题颜色。我找到了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);
我认为它可行,因为我有默认的蓝色主题,并且窗口是蓝色的(颜色完全相同),然后我将主题更改为绿色,但窗口仍然是蓝色的(显然在重新启动程序之后)。
现在我的问题是:是否可以获取当前的系统主题颜色?
答案 0 :(得分:0)
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;
}
答案 1 :(得分:-1)