{"id":95905,"date":"2017-04-05T07:00:00","date_gmt":"2017-04-05T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=95905"},"modified":"2019-03-13T01:09:10","modified_gmt":"2019-03-13T08:09:10","slug":"20170405-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20170405-00\/?p=95905","title":{"rendered":"How do I programmatically obtain the user&#8217;s selected accent color in Windows 10?"},"content":{"rendered":"<p>If you want to obtain the user&#8217;s accent color, you can ask <a HREF=\"https:\/\/msdn.microsoft.com\/library\/windows\/apps\/windows.ui.viewmanagement.uisettings.aspx\">the <code>UISettings<\/code> object<\/a> for the current color value of <a HREF=\"https:\/\/msdn.microsoft.com\/library\/windows\/apps\/windows.ui.viewmanagement.uicolortype.aspx\"><code>UIColorType.Accent<\/code><\/a>. <\/p>\n<p>How you get this information depends on what kind of program you&#8217;re writing. <\/p>\n<p>If you&#8217;re writing a Store app or a classic desktop program in C++\/CX, then you do this: <\/p>\n<pre>\nnamespace vm = Windows::UI::ViewManagement;\n\nvoid GetAccentColor()\n{\n    auto settings = ref new vm::UISettings();\n    auto color = settings-&gt;GetColorValue(vm::UIColorType::Accent);\n    \/\/ color.A, color.R, color.G, and color.B are the color channels.\n}\n<\/pre>\n<p>If you&#8217;re writing a Store app or <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/lucian\/2015\/10\/23\/how-to-call-uwp-apis-from-a-desktop-vbc-app\/\">a classic desktop program<\/a> in C#, then you do this: <\/p>\n<pre>\nusing vm = Windows.UI.ViewManagement;\n\nvoid GetAccentColor()\n{\n    var settings = new vm.UISettings();\n    var color = settings.GetColorValue(vm.UIColorType.Accent);\n    \/\/ color.A, color.R, color.G, and color.B are the color channels.\n}\n<\/pre>\n<p>If you&#8217;re writing a Store app in JavaScript, then you do this: <\/p>\n<pre>\nvar vm = Windows.UI.ViewManagement;\n\nfunction getAccentColor() {\n    var settings = new vm.UISettings();\n    var color = settings.getColorValue(vm.UIColorType.accent);\n    \/\/ color.a, color.r, color.g, and color.b are the color channels.\n}\n<\/pre>\n<p>If you&#8217;re writing a Store app or a classic desktop program in raw C++ (you crazy person you), then you get to do this: <\/p>\n<pre>\nnamespace abi_vm = ABI::Windows::UI::ViewManagement;\nnamespace wrl = Microsoft::WRL;\nnamespace wf = Windows::Foundation;\n\nvoid GetAccentColor()\n{\n    \/\/ Error checking has been elided for expository purposes.\n    wrl::ComPtr&lt;abi_vm::IUISettings&gt; settings;\n    wf::ActivateInstance(wrl::Wrappers::HStringReference(\n     RuntimeClass_Windows_UI_ViewManagement_UISettings).Get(), &amp;settings);\n    ABI::Windows::UI::Color color;\n    settings-&gt;GetColorValue(abi_vm::UIColorType::Accent, &amp;color);\n    \/\/ color.A, color.R, color.G, and color.B are the color channels.\n}\n<\/pre>\n<p>And if you&#8217;re writing a Store app or a classic desktop program in <a HREF=\"https:\/\/github.com\/Microsoft\/cppwinrt\">C++\/WinRT<\/a>, you write this: <\/p>\n<pre>\nnamespace winrt_vm = winrt::Windows::UI::ViewManagement;\n\nvoid GetAccentColor()\n{\n    winrt_vm::UISettings settings;\n    auto color = settings.GetColorValue(winrt_vm::UIColorType::Accent);\n    \/\/ color.A, color.R, color.G, and color.B are the color channels.\n}\n<\/pre>\n<p>Note that I used namespace aliases instead of importing the entire namespace. This makes the code a little bit uglier, but I think it&#8217;s useful for expository purposes because it makes it clearer which namespace each identifier comes from. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s in the UISettings object.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-95905","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>It&#8217;s in the UISettings object.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/95905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=95905"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/95905\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=95905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=95905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=95905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}