Browse Source

Make NewGetOpenOrSaveFileName able to follow Windows dark mode when VCL styles are active.

Martijn Laan 2 months ago
parent
commit
720c81f30b
1 changed files with 6 additions and 1 deletions
  1. 6 1
      Components/BrowseFunc.pas

+ 6 - 1
Components/BrowseFunc.pas

@@ -29,7 +29,7 @@ function NewGetSaveFileName(const Prompt: String; var FileName: String;
 implementation
 implementation
 
 
 uses
 uses
-  CommDlg, ShlObj, ActiveX,
+  CommDlg, ShlObj, ActiveX, Themes,
   PathFunc;
   PathFunc;
 
 
 function BrowseCallback(Wnd: HWND; uMsg: UINT; lParam, lpData: LPARAM): Integer; stdcall;
 function BrowseCallback(Wnd: HWND; uMsg: UINT; lParam, lpData: LPARAM): Integer; stdcall;
@@ -167,6 +167,10 @@ begin
 
 
   ActiveWindow := GetActiveWindow;
   ActiveWindow := GetActiveWindow;
   WindowList := DisableTaskWindows(ParentWnd);
   WindowList := DisableTaskWindows(ParentWnd);
+  { Temporarily clear SystemHooks to make it support dark mode if Windows is in dark mode.
+    Taken from Vcl.Dialogs' TCustomFileDialog.Execute }
+  const SaveHooks = TStyleManager.SystemHooks;
+  TStyleManager.SystemHooks := [];
   try
   try
     asm
     asm
       // Avoid FPU control word change in NETRAP.dll, NETAPI32.dll, etc
       // Avoid FPU control word change in NETRAP.dll, NETAPI32.dll, etc
@@ -194,6 +198,7 @@ begin
       end;
       end;
     end;
     end;
   finally
   finally
+    TStyleManager.SystemHooks := SaveHooks;
     EnableTaskWindows(WindowList);
     EnableTaskWindows(WindowList);
     SetActiveWindow(ActiveWindow);
     SetActiveWindow(ActiveWindow);
   end;
   end;