瀏覽代碼

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

Martijn Laan 2 月之前
父節點
當前提交
720c81f30b
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      Components/BrowseFunc.pas

+ 6 - 1
Components/BrowseFunc.pas

@@ -29,7 +29,7 @@ function NewGetSaveFileName(const Prompt: String; var FileName: String;
 implementation
 
 uses
-  CommDlg, ShlObj, ActiveX,
+  CommDlg, ShlObj, ActiveX, Themes,
   PathFunc;
 
 function BrowseCallback(Wnd: HWND; uMsg: UINT; lParam, lpData: LPARAM): Integer; stdcall;
@@ -167,6 +167,10 @@ begin
 
   ActiveWindow := GetActiveWindow;
   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
     asm
       // Avoid FPU control word change in NETRAP.dll, NETAPI32.dll, etc
@@ -194,6 +198,7 @@ begin
       end;
     end;
   finally
+    TStyleManager.SystemHooks := SaveHooks;
     EnableTaskWindows(WindowList);
     SetActiveWindow(ActiveWindow);
   end;