Recent

Author Topic: It is possible to set the new dark theme for applications  (Read 3018 times)

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
It is possible to set the new dark theme for applications
« on: August 21, 2020, 09:20:03 am »
Hi, i update Windows 10 yesterday and now dark theme is available it is possible to set it for application with Lazarus ?

Thanks

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: It is possible to set the new dark theme for applications
« Reply #1 on: August 21, 2020, 09:31:48 am »
If your application is written in a Windows 10 conformant way, it should pick up it by itself. You should not need to change any code.
Specialize a type, not a var.

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: It is possible to set the new dark theme for applications
« Reply #2 on: August 21, 2020, 12:16:00 pm »
If your application is written in a Windows 10 conformant way, it should pick up it by itself. You should not need to change any code.

Unfortunally not, is why i ask ;)

See the screenshot. Backgrounds, menu, toolbar and buttons are not set to the dark mode

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: It is possible to set the new dark theme for applications
« Reply #3 on: August 21, 2020, 01:12:34 pm »
It is possible to use and set a custom manifest file. I don't see anything about this in project's options except the checkbox "use manifest..."

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: It is possible to set the new dark theme for applications
« Reply #4 on: August 21, 2020, 04:35:34 pm »
"Use manifest" applies a generic "standard" manifest and you can change very few options of it (mainly DPI awareness, etc.).

To apply a more carefully drafted manifest you should uncheck that option and add the manifest file as a resource to your project ("Project Options->Resource"). You might also want to add it as a project's file in the Project Inspector so the tools know it's there.

Can't offer much more help; I left Windows behind, other than for testing and very few other things, quite some time ago. :-\
« Last Edit: August 21, 2020, 04:37:39 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

mr-highball

  • Full Member
  • ***
  • Posts: 233
    • Highball Github
Re: It is possible to set the new dark theme for applications
« Reply #5 on: August 21, 2020, 05:02:22 pm »
Also interested what would need to be done for lazarus to utilize this too

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: It is possible to set the new dark theme for applications
« Reply #6 on: August 21, 2020, 06:38:11 pm »
"Use manifest" applies a generic "standard" manifest and you can change very few options of it (mainly DPI awareness, etc.).

To apply a more carefully drafted manifest you should uncheck that option and add the manifest file as a resource to your project ("Project Options->Resource"). You might also want to add it as a project's file in the Project Inspector so the tools know it's there.

Can't offer much more help; I left Windows behind, other than for testing and very few other things, quite some time ago. :-\

Ok so by adding manifest  (see https://docs.microsoft.com/fr-fr/windows/win32/controls/cookbook-overview?redirectedfrom=MSDN#using-manifests-or-directives-to-ensure-that-visual-styles-can-be-applied-to-applications) in resource,  dark theme is only apply to the form (just the title bar) not to the components, controls are draw with light theme (screenshoot 1) :(

Add the manifest or not in the project explorer have no impact

If  "use manifest" is unchecked  components are drawn with old style (Screenshoot 2) :(

I also trie with "SetWindowTheme" API function (https://docs.microsoft.com/fr-fr/windows/win32/api/uxtheme/nf-uxtheme-setwindowtheme?redirectedfrom=MSDN) but the theme is only applied to the form

I think it will be fine to add this option in next release of Lazarus
« Last Edit: August 21, 2020, 06:40:38 pm by BeanzMaster »

mr-highball

  • Full Member
  • ***
  • Posts: 233
    • Highball Github
Re: It is possible to set the new dark theme for applications
« Reply #7 on: August 21, 2020, 06:51:48 pm »
Did you try setwindowtheme with the handle to your control?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: It is possible to set the new dark theme for applications
« Reply #8 on: August 21, 2020, 06:59:06 pm »
I don't know if the most recent W10 update changed this, but W10 dark theme used to be for MS apps only.

mr-highball

  • Full Member
  • ***
  • Posts: 233
    • Highball Github
Re: It is possible to set the new dark theme for applications
« Reply #9 on: August 21, 2020, 08:59:18 pm »
tried fiddling around with some stuff without any luck, maybe someone else can play around to see if they can get it working... for me, it's about friday beer time 🍻
for reference was going off of posts like these,
https://github.com/derceg/explorerplusplus/issues/115
https://social.msdn.microsoft.com/Forums/en-US/e36eb4c0-4370-4933-943d-b6fe22677e6c/dark-mode-apis

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     ListBox1: TListBox;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28. uses
  29.   JwaWindows;
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.Button1Click(Sender: TObject);
  35. type
  36.   TAllowDarkModeForApp = function (AAllow : BOOL) : BOOL; stdcall;
  37.   TAllowDarkModeForWindow = function (AHandle : HWND; AAllow : BOOL) : BOOL; stdcall;
  38.   TFlushMenuTheme = procedure(); stdcall;
  39. var
  40.   LUXTheme : HMODULE;
  41.   LAllowFunc: TAllowDarkModeForApp;
  42.   LFlushFunc: TFlushMenuTheme;
  43.   LAllowWindowFunc: TAllowDarkModeForWindow;
  44. begin
  45.   //try to load theme lib
  46.   LUXTheme := LoadLibraryW('uxtheme.dll');
  47.  
  48.   //get undocumented procs
  49.   LAllowWindowFunc := TAllowDarkModeForWindow(GetProcAddress(LUXTheme, MAKEINTRESOURCE(133)));
  50.   LAllowFunc := TAllowDarkModeForApp(GetProcAddress(LUXTheme, MAKEINTRESOURCE(135)));
  51.   LFlushFunc := TFlushMenuTheme(GetProcAddress(LUXTheme, MAKEINTRESOURCE(136)));
  52.  
  53.   //call the methods and cross our fingers
  54.   LAllowFunc(True);
  55.   LAllowWindowFunc(Self.Handle, True);
  56.   LFlushFunc();
  57.  
  58.   SetWindowTheme(Self.Handle, 'DarkMode_Explorer', '');
  59.  
  60.   //unload lib
  61.   UnloadLibrary(LUXTHeme);
  62. end;
  63.  
  64. end.
  65.  
  66.  

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: It is possible to set the new dark theme for applications
« Reply #10 on: August 21, 2020, 09:39:34 pm »
Did you try setwindowtheme with the handle to your control?

It's not working because handle must be an HWND

I don't know if the most recent W10 update changed this, but W10 dark theme used to be for MS apps only.

From what I also read, it would seem that this is only possible with .NET and UWP Application https://docs.microsoft.com/en-us/windows/uwp/get-started/universal-application-platform-guide

On SO i found this https://stackoverflow.com/questions/53501268/win10-dark-theme-how-to-use-in-winapi
the last answer will be help, don't saying.

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: It is possible to set the new dark theme for applications
« Reply #11 on: August 21, 2020, 09:48:41 pm »
Possible issue, i've checked my comctl32.dll version and is  5.82 this version is for old legacy application
The newer version 6.x includes the UXTheme support. So perhaps it is why is not working. I don't know where to find the right version of this DLL   >:D

https://docs.microsoft.com/fr-fr/windows/win32/controls/common-control-versions?redirectedfrom=MSDN
« Last Edit: August 21, 2020, 09:50:37 pm by BeanzMaster »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: It is possible to set the new dark theme for applications
« Reply #12 on: August 22, 2020, 01:09:20 am »
hello Beanzounet,
have a look here

Quote
The introduction of this theming library also affected the common controls library, COMCTL32.DLL. For compatibility reasons, Windows XP (and all newer Windows versions) are equipped with two different versions of COMCTL32.DLL.

At the standard path C:\Windows\System32\, the old COMCTL32.DLL version 5 can be found. This library version contains the implementation of standard controls like list view, combo-box, etc., which are unaware of UXTHEME.DLL existence, hence applications linked with this library generally are not themed.

The newer version 6 of COMCTL32.DLL resides under C:\Windows\WinSxS\, available as a side-by-side assembly. Only applications explicitly manifesting their compatibility with the library version 6 use it. The other applications simply continue to use the version 5.

Also note, that historically some controls used to be implemented in USER32.DLL (window classes like, for example, BUTTON or EDIT), while others (known as common controls) resided in COMCTL32.DLL. This has changed with the introduction of COMCTL32.DLL version 6, and now all theming-aware controls live there.

Gotcha: The old (unthemed) implementation of standard controls is still available in USER32.DLL. If you instruct the linker to link your application with COMCTL32.DLL, it may silently omit it if the application never calls any function from it. Hence I recommend you to call InitCommonControls() when initializing the application. Otherwise, the app may be just unthemed instead of not working, using the old controls, masking perfectly the root cause of the problem.

Ami calmant, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: It is possible to set the new dark theme for applications
« Reply #13 on: August 22, 2020, 12:24:37 pm »
As marcov wrote, the problem is that there is no official API yet to enable dark mode for native WinAPI controls, the applications provided by Microsoft (e.g. Windows Explorer) simply use inofficial, undocumented ones. This C example shows what needs to be done, though I don't know whether applying these techniques to the LCL would already fix the whole of the LCL or if other things would need to be adjusted as well.

mr-highball

  • Full Member
  • ***
  • Posts: 233
    • Highball Github
Re: It is possible to set the new dark theme for applications
« Reply #14 on: August 22, 2020, 06:34:07 pm »
As marcov wrote, the problem is that there is no official API yet to enable dark mode for native WinAPI controls, the applications provided by Microsoft (e.g. Windows Explorer) simply use inofficial, undocumented ones. This C example shows what needs to be done, though I don't know whether applying these techniques to the LCL would already fix the whole of the LCL or if other things would need to be adjusted as well.

In my previous post i tried out calling some of the undocumented api calls (scroll down in the code block) but it didn't seem to do anything. Maybe someome could expand it a bit or see something I did wrong

 

TinyPortal © 2005-2018