如何允许Delphi辅助窗体位于主窗体后面?

6
如果在Delphi 2010或XE中设置了Application.MainFormOnTaskbar为true,则所有次要窗体始终在主窗口前面。无论Popupmode或PopupParent属性设置为什么,都没有用。但是我有一些次要窗口,我希望能够显示在主窗体后面。
如果将MainFormOnTaskbar设置为false,则可以正常工作,但是Windows 7的功能会受到影响(Alt-tab,Windows任务栏图标等)。
如何在允许次要窗体隐藏在主窗体后面的同时保持Windows 7功能正常工作?
3个回答

4
基本上你做不到。 MainFormOnTaskBar 的全部目的是为了与 Vista 兼容。如果不设置它,兼容性就会丢失;如果设置了,z-order 就可以完成。以下摘自 D2007 的 readme: 此属性控制 VCL 如何处理窗口任务栏按钮。该属性可以应用于旧应用程序,但它会影响您的 MainForm 的 Z-order,因此您应确保没有依赖于旧行为。 但请参阅此 QC 报告,其中描述了完全相同的问题(并关闭为 AsDesigned)。报告指出了一种解决方案,涉及重写一个表单的 CreateParams 来将 WndParent 设置为“0”。它还描述了这个解决方法引起的一些问题以及这些问题的可能解决方法。请注意,找到并解决所有问题不是易事/可能。查看 Steve Trefethen 的 文章,以了解可能涉及的内容。

2
提到的文章现在在这里:http://www.stevetrefethen.com/blog/the-new-vcl-property-tapplication-mainformontaskbar-in-delphi-2007。 - Sertac Akyuz

0

我找到了解决这个问题的方法。

*.dpr文件中,将 Application.MainFormOnTaskbar := true; 改为 Application.MainFormOnTaskbar := false;

这样可以让你的子窗体出现在主窗体后面。


1
如果我将 MainFormOnTaskbar 设置为 false,它就可以工作了,但是... - Sertac Akyuz

0

我认为一种方法是创建一个“幕后”主窗体,仅用于以下目的:

  1. 选择并显示其他窗体作为主窗体,然后永久隐藏自己(Visible:= FALSE),就像旧式的“闪屏”一样。

  2. 当所选的主窗体关闭时(只需连接适当的OnClose事件),作为应用程序终止器。

  3. 代表指定的伪主窗体打开其他窗体,使隐藏的真实主窗体成为其他窗体的“所有者”,而不是“伪主窗体”。如果您的所有其他窗体都具有“非”弹出样式,并通过Show调用可见,而不是ShowModal,则似乎会发生这种情况。

这种应用程序行为的小改组可能会让您获得所需的用户交互。

unit FlashForm;
interface

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

type
  TFlash = class(TForm)
    lblTitle: TLabel;
    lblCopyright: TLabel;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  public
    procedure CloseApp;
  end;

var
  Flash: TFlash;

implementation

{$R *.dfm}

uses Main;

procedure TFlash.CloseApp;  // Call this from the Main.Form1.OnClose or CanClose (OnFormCloseQuery) event handlers
begin
   close
end;

procedure TFlash.FormCreate(Sender: TObject);  // You can get rid of the standard border icons if you want to
begin
   lblCopyright.Caption := 'Copyright (c) 2016  AT Software Engineering Ltd';
   Refresh;
   Show;
   BringToFront;
end;


procedure TFlash.Timer1Timer(Sender: TObject);
begin
   Application.MainFormOnTaskBar := FALSE;  // This keeps the taskbar icon alive
   if assigned(Main.MainForm) then
   begin
       visible := FALSE;
       Main.MainForm.Show;
       Timer1.Enabled := FALSE;
   end else Timer1.Interval := 10;  // The initial time is longer than this (flash showing time)
end;

end.

// Finally, make this the FIRST form created by the application in the project file.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接