SHARE
TWEET

Untitled

a guest Sep 17th, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <roapi.h>
  3.  
  4. #include <iostream>
  5. #include <cwchar>
  6. #include <string>
  7.  
  8. // For Windows.UI.ViewManagement.UISettings
  9. #include <windows.ui.viewmanagement.h>
  10.  
  11. int main() {
  12.     ::RoInitialize(RO_INIT_MULTITHREADED);
  13.  
  14.     HSTRING_HEADER header;
  15.     HSTRING hstring;
  16.     ::WindowsCreateStringReference(
  17.         RuntimeClass_Windows_UI_ViewManagement_UISettings,
  18.         wcslen(RuntimeClass_Windows_UI_ViewManagement_UISettings),
  19.         &header,
  20.         &hstring);
  21.  
  22.     std::cout << "Activating UISettings" << std::endl;
  23.     // TODO: Use an RAII container/wrapper (such as Microsoft::WRL::ComPtr from the WRL library) to prevent leaks.
  24.     IInspectable* uiSettingsAsInspectable = nullptr;
  25.     HRESULT hr = ::RoActivateInstance(hstring, &uiSettingsAsInspectable);
  26.     if (FAILED(hr)) {
  27.         std::cout << std::hex << hr << std::endl;
  28.         return 1;
  29.     }
  30.  
  31.     std::cout << "Querying for the appropriate interface..." << std::endl;
  32.     ::ABI::Windows::UI::ViewManagement::IUISettings3* uiSettings = nullptr;
  33.     hr = uiSettingsAsInspectable->QueryInterface(__uuidof(uiSettings), reinterpret_cast<void**>(&uiSettings));
  34.     if (FAILED(hr)) {
  35.         std::cout << std::hex << hr << std::endl;
  36.         return 2;
  37.     }
  38.  
  39.     std::cout << "Asking for the current background color..." << std::endl;
  40.     ::ABI::Windows::UI::Color color;
  41.     hr = uiSettings->GetColorValue(::ABI::Windows::UI::ViewManagement::UIColorType_Background, &color);
  42.     if (FAILED(hr)) {
  43.         std::cout << std::hex << hr << std::endl;
  44.         return 3;
  45.     }
  46.  
  47.     std::string colorName;
  48.     if (color.A == 0xff && color.R == 0 && color.G == 0 && color.B == 0) {
  49.         colorName = "Black/Dark";
  50.     } else if (color.A == 0xff && color.R == 0xff && color.G == 0xff && color.B == 0xff) {
  51.         colorName = "White/Light";
  52.     } else {
  53.         colorName = "Other";
  54.     }
  55.  
  56.     std::cout << "Current background color is " << colorName << std::endl;
  57.  
  58.     return 0;
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top