Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get Windows 10 Accent Colour
QtWS25 Last Chance

Get Windows 10 Accent Colour

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mourke
    wrote on 3 Feb 2019, 16:14 last edited by mourke 2 Mar 2019, 19:24
    #1

    Is it possible to get the windows 10 accent colour?

    I have tried to do this using native APIs:

    
    #include <wrl.h>
    #include <windows.ui.viewmanagement.h>
    
    namespace abi_vm = ABI::Windows::UI::ViewManagement;
    namespace wrl = Microsoft::WRL;
    namespace wf = Windows::Foundation;
    
    void GetAccentColor()
    {
    
    // Error checking has been elided for expository purposes.
    	wrl::ComPtr<abi_vm::IUISettings3> settings;
    	wf::ActivateInstance(wrl::Wrappers::HStringReference(RuntimeClass_Windows_UI_ViewManagement_UISettings).Get(), &settings);
    	ABI::Windows::UI::Color color;
    	settings->GetColorValue(abi_vm::UIColorType::UIColorType_Accent, &color);
    	// color.A, color.R, color.G, and color.B are the color channels.
    }
    

    But I keep getting unresolved symbol linker errors. I am using Visual Studio as my development environment so I do not have a .pro file. Instead of switching to Qt Creator as my IDE is there any way to just get the system accent colour? This seems like an awful lot of work to get a colour.

    Thanks.

    A 1 Reply Last reply 3 Feb 2019, 17:12
    0
    • M mourke
      3 Feb 2019, 16:14

      Is it possible to get the windows 10 accent colour?

      I have tried to do this using native APIs:

      
      #include <wrl.h>
      #include <windows.ui.viewmanagement.h>
      
      namespace abi_vm = ABI::Windows::UI::ViewManagement;
      namespace wrl = Microsoft::WRL;
      namespace wf = Windows::Foundation;
      
      void GetAccentColor()
      {
      
      // Error checking has been elided for expository purposes.
      	wrl::ComPtr<abi_vm::IUISettings3> settings;
      	wf::ActivateInstance(wrl::Wrappers::HStringReference(RuntimeClass_Windows_UI_ViewManagement_UISettings).Get(), &settings);
      	ABI::Windows::UI::Color color;
      	settings->GetColorValue(abi_vm::UIColorType::UIColorType_Accent, &color);
      	// color.A, color.R, color.G, and color.B are the color channels.
      }
      

      But I keep getting unresolved symbol linker errors. I am using Visual Studio as my development environment so I do not have a .pro file. Instead of switching to Qt Creator as my IDE is there any way to just get the system accent colour? This seems like an awful lot of work to get a colour.

      Thanks.

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 3 Feb 2019, 17:12 last edited by
      #2

      @mourke untesolved symbol means, the Linker cannot find these functions.

      You will need to link the appropriate DLLs to solve this. MSDN usually tells you which library that is for each function.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mourke
        wrote on 3 Feb 2019, 17:29 last edited by
        #3

        How do I do this without using a .pro file?

        M 1 Reply Last reply 3 Feb 2019, 17:32
        0
        • M mourke
          3 Feb 2019, 17:29

          How do I do this without using a .pro file?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 3 Feb 2019, 17:32 last edited by
          #4

          @mourke
          Hi
          Would that not be as normal in visual studio?
          https://stackoverflow.com/questions/4445418/how-to-add-additional-libraries-to-visual-studio-project

          1 Reply Last reply
          1
          • C Online
            C Online
            Chris Kawa
            Lifetime Qt Champion
            wrote on 3 Feb 2019, 17:47 last edited by
            #5

            Using WRL is like eating razors. I strongly suggest you switch to the much nicer c++/winrt library included in the Windows SDK.

            To get accent color with it you would do:

            #include <winrt/Windows.UI.ViewManagement.h>
            #pragma comment(lib, "windowsapp")
            
            winrt::init_apartment(); // call this only once at the start of your app
            
            winrt::Windows::UI::ViewManagement::UISettings settings;
            winrt::Windows::UI::Color color = settings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Accent);
            

            Yes, the namespaces are ungodly, that's Windows runtime api for you :)

            M 1 Reply Last reply 3 Feb 2019, 19:21
            4
            • C Chris Kawa
              3 Feb 2019, 17:47

              Using WRL is like eating razors. I strongly suggest you switch to the much nicer c++/winrt library included in the Windows SDK.

              To get accent color with it you would do:

              #include <winrt/Windows.UI.ViewManagement.h>
              #pragma comment(lib, "windowsapp")
              
              winrt::init_apartment(); // call this only once at the start of your app
              
              winrt::Windows::UI::ViewManagement::UISettings settings;
              winrt::Windows::UI::Color color = settings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Accent);
              

              Yes, the namespaces are ungodly, that's Windows runtime api for you :)

              M Offline
              M Offline
              mourke
              wrote on 3 Feb 2019, 19:21 last edited by
              #6

              @Chris-Kawa said in Get Windows 10 Accent Colour:

              #pragma comment(lib, "windowsapp")

              When I tried to include any winrt headersI got about 3 thousand build errors complaining about syntax and what not inside the library itself

              1 Reply Last reply
              0
              • C Online
                C Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on 3 Feb 2019, 19:25 last edited by
                #7

                It's a C++17 library, so make sure your project is set up to use that version of the language or later.

                Go to project properties C/C++ -> Language -> C++ Language Standard and set it to either ISO C++ 17 or ISO C++ Latest Draft Standard.

                It's 2019. You should be doing that for all your new projects anyway.

                M 1 Reply Last reply 3 Feb 2019, 19:40
                2
                • C Chris Kawa
                  3 Feb 2019, 19:25

                  It's a C++17 library, so make sure your project is set up to use that version of the language or later.

                  Go to project properties C/C++ -> Language -> C++ Language Standard and set it to either ISO C++ 17 or ISO C++ Latest Draft Standard.

                  It's 2019. You should be doing that for all your new projects anyway.

                  M Offline
                  M Offline
                  mourke
                  wrote on 3 Feb 2019, 19:40 last edited by
                  #8

                  @Chris-Kawa Thanks so much it works perfectly!

                  winrt::init_apartment(); // call this only once at the start of your app
                  

                  this line crashes the app but taking it out removes the crash and everything still works as expected. Thanks!

                  C 1 Reply Last reply 3 Feb 2019, 19:51
                  0
                  • M mourke
                    3 Feb 2019, 19:40

                    @Chris-Kawa Thanks so much it works perfectly!

                    winrt::init_apartment(); // call this only once at the start of your app
                    

                    this line crashes the app but taking it out removes the crash and everything still works as expected. Thanks!

                    C Online
                    C Online
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on 3 Feb 2019, 19:51 last edited by
                    #9

                    I'm glad I could help but

                    this line crashes the app

                    This line initializes COM. It should definitely not crash your app and it is needed for winrt stuff to even work.

                    but taking it out removes the crash and everything still works as expected

                    That's like saying taking out main() fixes an app. It's suspicious to say the least. I'd suggest to look into it because now you basically don't know why your app is working. Where did you put that line? Are you initializing COM in some other way?

                    1 Reply Last reply
                    2

                    9/9

                    3 Feb 2019, 19:51

                    • Login

                    • Login or register to search.
                    9 out of 9
                    • First post
                      9/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved