在经典 C++ WinAPI (Win32) 应用程序中获取 Windows 10 主题颜色

daw*_*345 5 c++ windows winapi codeblocks

我正在寻找如何获取系统主题颜色。我找到了 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);
Run Code Online (Sandbox Code Playgroud)

我认为它有效,因为我有默认的蓝色主题,窗口是蓝色的(完全相同的颜色),然后我将主题更改为绿色,但窗口仍然是蓝色的(显然重新启动程序后)。

现在我的问题是:是否可以获得当前的系统主题颜色?

IIn*_*ble 8

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;
}
Run Code Online (Sandbox Code Playgroud)