Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <roapi.h>
- #include <iostream>
- #include <cwchar>
- #include <string>
- // For Windows.UI.ViewManagement.UISettings
- #include <windows.ui.viewmanagement.h>
- int main() {
- ::RoInitialize(RO_INIT_MULTITHREADED);
- HSTRING_HEADER header;
- HSTRING hstring;
- ::WindowsCreateStringReference(
- RuntimeClass_Windows_UI_ViewManagement_UISettings,
- wcslen(RuntimeClass_Windows_UI_ViewManagement_UISettings),
- &header,
- &hstring);
- std::cout << "Activating UISettings" << std::endl;
- // TODO: Use an RAII container/wrapper (such as Microsoft::WRL::ComPtr from the WRL library) to prevent leaks.
- IInspectable* uiSettingsAsInspectable = nullptr;
- HRESULT hr = ::RoActivateInstance(hstring, &uiSettingsAsInspectable);
- if (FAILED(hr)) {
- std::cout << std::hex << hr << std::endl;
- return 1;
- }
- std::cout << "Querying for the appropriate interface..." << std::endl;
- ::ABI::Windows::UI::ViewManagement::IUISettings3* uiSettings = nullptr;
- hr = uiSettingsAsInspectable->QueryInterface(__uuidof(uiSettings), reinterpret_cast<void**>(&uiSettings));
- if (FAILED(hr)) {
- std::cout << std::hex << hr << std::endl;
- return 2;
- }
- std::cout << "Asking for the current background color..." << std::endl;
- ::ABI::Windows::UI::Color color;
- hr = uiSettings->GetColorValue(::ABI::Windows::UI::ViewManagement::UIColorType_Background, &color);
- if (FAILED(hr)) {
- std::cout << std::hex << hr << std::endl;
- return 3;
- }
- std::string colorName;
- if (color.A == 0xff && color.R == 0 && color.G == 0 && color.B == 0) {
- colorName = "Black/Dark";
- } else if (color.A == 0xff && color.R == 0xff && color.G == 0xff && color.B == 0xff) {
- colorName = "White/Light";
- } else {
- colorName = "Other";
- }
- std::cout << "Current background color is " << colorName << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement