Property “ofOverwritePrompt” for TSaveDialog does

2020-03-15 16:49发布

  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.

The replace message box is partly hidden. Only a small top left part is shown.

And here it is compiled with XE8 win32:

enter image description here

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

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

enter image description here

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):

enter image description here

4条回答
Anthone
2楼-- · 2020-03-15 16:52

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).

查看更多
我想做一个坏孩纸
3楼-- · 2020-03-15 16:54

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.

查看更多
男人必须洒脱
4楼-- · 2020-03-15 17:04

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;

enter image description here

查看更多
在下西门庆
5楼-- · 2020-03-15 17:08

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).

查看更多
登录 后发表回答