delphi - 如何将被另一个窗口隐藏的 OpenDialog 带到前面

标签 delphi topendialog createparams bringtofront

我有一个包含多个表单的应用程序,每个表单都有一个单独的任务栏按钮。

假设 form2 显示一个 OpenDialog,我点击另一个最大化的应用程序覆盖全屏区域,然后我通过选择它的任务栏按钮返回到 form2。瞧! OpenDialog 隐藏在我选择的另一个应用程序后面,我必须单击现在不可访问的 form2 才能将对话框重新置于前面。这真的很烦人,可能会使用户感到困惑。

下面是一些代码来说明这个问题:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;

end.
________________

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  OpenDialog1.Execute;
end;

procedure TForm2.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
  Params.WndParent := GetDesktopWindow;
end;

end.

是否有可能获得可见 opendialog 的句柄?它曾经是可能的,但是如果我捕获 OnDialogShow,那么使用新的 Vista 风格的 OpenDialog,OpenDialog 会恢复到旧的风格,这对我来说现在是不行的。

有任何想法吗?

最佳答案

TOpenDialog.Execute()有一个可选参数,可让您指定不允许对话框落后的父窗口:

procedure TForm2.Button1Click(Sender: TObject);
begin
  OpenDialog1.Execute(Self.Handle);
end;

如果您不指定父窗口,则在 Application.ModalPopupMode 时使用事件窗体的窗口。不是 pmNone , 否则 Application.MainForm改为使用窗口。

关于delphi - 如何将被另一个窗口隐藏的 OpenDialog 带到前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25291108/

相关文章:

delphi - 为什么从 dll 调用函数并且使用记录时出现访问冲突?

delphi - 集合的乘法运算符是否有记录?

delphi - 使用 Delphi 创建文件夹选择对话框的最常见方法是什么?

c# - 如何使用系统菜单创建无边框表单?

ios - Delphi XE4 iOS 打开电子邮件程序不工作

delphi - 如何将Delphi应用程序转换为Web应用程序?

c# - Windows 窗体应用程序中的闪烁

delphi - tOpenDialog 后面意外触发 tStringGrid.OnFixedCellClick

multithreading - OpenDialog 没有出现在 Delphi 多线程应用程序中