如何将被另一个窗口隐藏的OpenDialog置于最前面 [英] How to bring an OpenDialog hidden by another window to the front

查看:135
本文介绍了如何将被另一个窗口隐藏的OpenDialog置于最前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an application with multiple forms and a separate taskbar button for each form.

比方说,form2显示一个OpenDialog,然后单击另一个覆盖整个屏幕区域的最大化应用程序,然后通过选择它的任务栏按钮返回到form2.瞧! OpenDialog隐藏在我选择的其他应用程序的后面,我必须单击现在不可访问的form2,以将对话框带回到最前面.这确实很烦人,并且可能会使用户感到困惑.

Let's say form2 displays an OpenDialog, I click away to another maximized application covering the full screen area, then I go back to form2 by selecting it's taskbar button. Voila! The OpenDialog is hidden behind the other application I selected, and I have to click on the now non-accessible form2 to bring the dialog back to the front. This is really annoying and may confuse the user.

以下是一些说明问题的代码:

Here is some code to illustrate the issue:

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的句柄?以前曾经有可能,但是如果使用了新的Vista风格的OpenDialog(如果我捕获了OnDialogShow),则OpenDialog会恢复为旧样式,这对我来说现在是不行的.

Is it possible maybe to get the handle of the visible opendialog? It used to be possible, but with the new Vista style OpenDialog if I trap OnDialogShow the OpenDialog reverts back to the old style which is a no go for me now.

有什么想法吗?

推荐答案

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

TOpenDialog.Execute() has an optional parameter that lets you specify a parent window that the dialog is not allowed to fall behind:

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

如果未指定父窗口,则如果Application.ModalPopupMode不是pmNone,则使用活动窗体的窗口,否则使用Application.MainForm窗口.

If you do not specify a parent window, the active Form's window is used if Application.ModalPopupMode is not pmNone, otherwise the Application.MainForm window is used instead.

这篇关于如何将被另一个窗口隐藏的OpenDialog置于最前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆