Recent

Author Topic: Windows 10 - How to use or apply the "theme" or "color scheme"?  (Read 8226 times)

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Windows 10 - How to use or apply the "theme" or "color scheme"?
« on: January 14, 2020, 12:30:22 pm »
I'm looking for a way to apply the Windows "theme" or "color scheme" under Windows 10, to my application, as set with the "Personalize" option (right click desktop).
So if the user sets the colors to "dark" then I'd ideally would like to see my application to reflect that as well.
I'm not a dark theme user myself, but I do believe that when a user changes the appearance of Windows to their liking, that my application should at least try to match that style and color scheme.


I've read about the project options (use manifest), which applies the theme (I think) but not the colors of the personalized options.
Trying to find more info on the manifest unfortunately did not clarify this for me.


I also read that the modern (Windows 10) colors uses a different mechanism (UWP vs Win32?), and I've noticed that GetSysColor (winuser.h) does NOT provide these colors and instead returns the fixed and unchanged default colors (probably used by LCL as well?).


The Windows registry seems to hold a flag that indicates if the user uses dark or light mode - but relying on a registry value (versus a proper API call) doesn't seem right to me and feels a little like a hack. Trying it anyway did show me that the values stored there are not the best to rely on.


I did read about JwaUxTheme, but it seems this relies on UXTheme from Windows XP, which doesn't include the colors either. (please correct me if I'm wrong)


Is there a way. or a future plan to implement this in LCL, without switching to a different (custom drawn) widgetset, to accomplish this?
It seems even Xojo supports this (I'm not using Xojo, just bumped into it when googling for a solution).


Note: I'm not a Windows expert, so any help or insight would be appreciated.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Windows 10 - How to use or apply the "theme" or "color scheme"?
« Reply #1 on: March 24, 2020, 07:37:39 pm »
I would be interested in this solution, too. I have successfully converted my apps to support the dark mode on macOS, so it should be easy to do this on Windows, too. It would be necessary to know if the the dark theme is activated, however.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

mr-highball

  • Full Member
  • ***
  • Posts: 233
    • Highball Github
Re: Windows 10 - How to use or apply the "theme" or "color scheme"?
« Reply #2 on: March 24, 2020, 07:55:31 pm »
posted this on a different topic a minute ago,
https://forum.lazarus.freepascal.org/index.php/topic,48179.msg354269.html#msg354269

but I haven't tried the steps yet (or if this is the most up to date process). Would be nice to know if someone else has already figured this out

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Windows 10 - How to use or apply the "theme" or "color scheme"?
« Reply #3 on: March 25, 2020, 01:49:48 pm »
Please find at https://forum.lazarus.freepascal.org/index.php/topic,42810.msg354372/topicseen.html#new a possible cross-platform solution that works on Windows and macOS as well.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Re: Windows 10 - How to use or apply the "theme" or "color scheme"?
« Reply #4 on: March 25, 2020, 04:42:33 pm »
Thanks for the Tip!  :)
Your function works great - thanks!


Just one "but" - well actually maybe more than one ...
The application still does not get notified when the "theme" changes back and forth between light and dark.
If we test DarkTheme during the onPaint event, then we can detect it easily with your function. However when changing the theme nothing seems to notify the application that the theme has been changed (not a flaw in you function of course). So the user will need to "touch" the form, or move over it to trigger an OnPaint event.
Additionally, and I think the is probably related to Win32 vs UWP, none of the LCL controls adapt to the new theme colors (like we see in Cocoa).

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Windows 10 - How to use or apply the "theme" or "color scheme"?
« Reply #5 on: March 25, 2020, 04:45:43 pm »
Yes, both are known problems. We will not change the design decisions made in Windows, but it would be great to get a notification on the Mac.

In fact, I check in the OnPaint event of every form if the light or the dark mode is active, but this doesn't solve every issue.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Re: Windows 10 - How to use or apply the "theme" or "color scheme"?
« Reply #6 on: March 25, 2020, 04:54:09 pm »
In my apps, I solely rely on the main form's onPaint event - it gets triggered in Cocoa when the use changes to dark or light theme. A dedicated event or notification would have been nice though.
Under Windows: is there any messaging going on when Windows changes to dark or light theme?
I'm not an expert on the messaging Windows uses, but I do recall that there is some sorts of messaging going on under Windows when things change.


p.s. you code nicely completed the code I had for macOS! Thanks again!

 

TinyPortal © 2005-2018