Property “ofOverwritePrompt” for TSaveDialog does not work when VCL Styles are used in Delphi 10.1 Berlin

[亡魂溺海] 提交于 2019-12-19 05:53:05

问题


  1. Create a new VCL Forms application
  2. On the main form add a Tbutton and a TSaveDialog

  3. Set "ofOverwritePrompt" to True in properties for the SaveDialog1

  4. Use:

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      SaveDialog1.Execute();
    end;
    
  5. Run the app. Press the button to execute the save dialog. Try to save to a file that already exists. A message box appears if you want to replace the file. Press cancel. All fine so far. Close the app.

  6. Go to Project/Options/Application/Appearance and select a Custom style (e.g. Amakrits). Set Amakrits as the default style.

  7. Run the app as in #5 above. Only a small bit of the message box will be shown. You will have to press Enter to be able to continue.

(Using a TFileSaveDialog will give the same result)

If I compile and run the app using Delphi XE8 it will be ok since the save dialog window seems to use the default windows style even if another style is chosen.

Edit: I have Windows 10 pro. Source compiled as win32 with Delphi 10.1 Berlin. The replace message box is partly hidden. Only a small top left part is shown, see figure.

And here it is compiled with XE8 win32:

Ps. I am using the default 100% scale factor.

Compiling with win64 (Delphi 10.1 Berlin) seems to be ok:

So, compiling to win32 does not work for me, but 64-bit will. Any clues?

Edit: Trying with "GetSaveFileName(OFN)" will also not work for me in win32 (win 64 is ok):


回答1:


You can avoid this issue using the dialog styling code of the VCL Styles Utils project.

Just Add these units to your project.

uses
  Vcl.Styles.Utils.Menus, //Popup and Shell Menus (class #32768)
  Vcl.Styles.Utils.Forms, //dialogs box (class #32770)
  Vcl.Styles.Utils.StdCtrls, //buttons, static, and so on
  Vcl.Styles.Utils.ComCtrls, //SysTreeView32, SysListView32
  Vcl.Styles.Utils.ScreenTips, //tooltips_class32 class
  Vcl.Styles.Utils.SysControls,
  Vcl.Styles.Utils.SysStyleHook;

{$R *.dfm}

procedure TForm26.Button1Click(Sender: TObject);
begin
  UseLatestCommonDialogs := false;
  SaveDialog1.Execute();
end;




回答2:


I cannot confirm the problem, and all looks well here, (32 bit executalbe, themed with Amakrits, compiled with 10.1 Berlin, on Windows 7, 100% scaling) but you could try this:

uses ... Winapi.CommDlg;

...

var
  OFN: TOpenFileName;
begin
  FillChar(OFN, SizeOf(OFN), 0);
  OFN.lStructSize := SizeOf(OFN);
  OFN.nMaxFile := MAX_PATH;
  OFN.Flags := OFN_OVERWRITEPROMPT or OFN_HIDEREADONLY or OFN_ENABLESIZING or OFN_EXPLORER;
  GetSaveFileName(OFN);
end;

The result is an Amakrits-themed, new Explorer-like save dialog, which works fine (for me). Only the two round, blue "back" and "forth" (<- and ->) buttons at the top left of the dialog look a little weird.

But I did not try this with custom scaling settings (e.g. Medium 125% in the Control Panel -> Display panel, etc.). I think this could influence such things.

Update

I just tried to use SaveDialog1 (commenting out the OFN code above) with custom Display scaling (125%). All looked fine, so that is not it. Also when I use the OFN code, all looks fine (actually, better, i.e. no XP style dialog, but a real Explorer-like dialog instead).




回答3:


If I set "Enable High-DPI" to true in Project/Options/Application it will work (replace box properly displayed). Disabling it will cause the problem (both in win32 and win64).




回答4:


For the record, I had exactly the same problem (Delphi 10.1 Berlin, compiling on Windows 10 64 bit, 100% screen settings, compiled for 32 bit target). Enabling or disabling High-DPMI awareness didn't help.

A workaround is to disable styles for dialog boxes before executing the TSaveDialog (or TOpenDialog) like this:

  TStyleManager.SystemHooks := TStyleManager.SystemHooks - [shDialogs];

The file dialog itself will still be themed. You will get standard Windows-style message boxes in case an overwrite prompt (or create prompt) pops up, but they will be large enough for the user to read and click them. After the file dialog has finished, you can enable styled dialogs again by re-adding shDialogs to SystemHooks if needed.



来源:https://stackoverflow.com/questions/38485043/property-ofoverwriteprompt-for-tsavedialog-does-not-work-when-vcl-styles-are-u

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