Delphi. How to disable Vcl Themes for TFileOpenDialog and TOpenDialog

只谈情不闲聊 提交于 2019-12-23 18:47:25

问题


How to disable Vcl Themes for TFileOpenDialog and TOpenDialog ?

I try

procedure TForm1.FormCreate(Sender: TObject);
var
  chosenDirectory: String;
  openDialog : TFileOpenDialog;
begin

  TStyleManager.Engine.RegisterStyleHook(TFileOpenDialog, TStyleHook);

  chosenDirectory:='';

  try
    openDialog:=TFileOpenDialog.Create(Self);
    openDialog.Options := [fdoPickFolders];
    // var 2
    // Not works
    //TStyleManager.Engine.RegisterStyleHook(TFileOpenDialog, TStyleHook);

    if openDialog.Execute then
      chosenDirectory:=openDialog.FileName;
  finally
    openDialog.Free;
  end;
end;

but it's not work. I try variation 2. It's not work too.


回答1:


It does not work because FileOpenDialog is system windows dialog, rather than implemented in VCL, so you'll need add system hook based on class name. Plus you'll need to add hooks to class names of all Windows controls on this dialog.

Try something like this. Note that this will affect all system dialogs.

  TStyleManager.Engine.RegisterSysStyleHook('#32770', TSysStyleHook);
  TStyleManager.Engine.RegisterSysStyleHook('ReBarWindow32', TSysStyleHook);
  TStyleManager.Engine.RegisterSysStyleHook('Static', TSysStyleHook);
  TStyleManager.Engine.RegisterSysStyleHook('Edit', TSysStyleHook);
  TStyleManager.Engine.RegisterSysStyleHook('ScrollBar', TSysStyleHook);
  TStyleManager.Engine.RegisterSysStyleHook('ToolbarWindow32', TSysStyleHook);
  TStyleManager.Engine.RegisterSysStyleHook('ComboBox', TSysStyleHook);



回答2:


The proper way of disable the styling of the common dialogs is removing the shDialogs element of the TStyleManager.SystemHooks property.

TStyleManager.SystemHooks := [shMenus, shToolTips];


来源:https://stackoverflow.com/questions/41656918/delphi-how-to-disable-vcl-themes-for-tfileopendialog-and-topendialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!