Get Windows 10 Theme Color In Classic C++ WinAPI (Win32) Application

Viewed 2057

I was searching how to get system theme color. I found GetSysColor and GetSysColorBrush. Then I tested it with something like that:

    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);

I thought it works, because I had default blue theme and the window was blue (exactly same color), then i changed my theme to green but window was still blue (after restarting program obviously).

And now my question: Is it possible to get current system theme color?

2 Answers

The Windows 10 theme colors are available through the UISettings type. It is available to classic desktop applications as well.

The following code uses C++/WinRT to retrieve the currently selected accent color:

#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;
}
Related