2010-11-22 178 views
4

如果在Delphi 2010或XE Application.MainFormOnTaskbar设置为true,则所有辅助窗体始终位于主窗口的前面。无论Popupmode或PopupParent属性设置为什么都无关紧要。不过,我有辅助窗口,我希望能够在主窗体后面显示。如何在主窗体背后隐藏Delphi辅助窗体

如果我将MainFormOnTaskbar设置为false,它将起作用,但Windows 7的功能已损坏(Alt-tab,Windows栏图标等)。

如何保持Windows 7功能正常工作,同时仍允许辅助表单隐藏在主窗体后面?

回答

4

基本上你不行。 MainFormOnTaskBar的整点是具有Vista兼容性。如果你没有设置它,兼容性不见了,如果你设置它,z-order就完成了。以下摘录是从D2007的自述:

The property controls how Window's TaskBar buttons are handled by VCL. This property can be applied to older applications, but it affects the Z-order of your MainForm, so you should ensure that you have no dependencies on the old behavior.


但看到这个QC report,它描述了完全相同的问题(和封闭方式AsDesigned)。该报告指出了一种解决方法,其中涉及覆盖表格的CreateParams以将WndParent设置为'0'。它还介绍了该解决方法导致的一些问题,以及这些问题的可能解决方法。要小心,要找到并解决所有问题并不容易/可能。请参阅Steve Trefethen的article以了解可能涉及的内容。

+2

提到的文章是现在[这里](http://www.stevetrefethen.com/blog/the-new-vcl-property-tapplication-mainformontaskbar-in-delphi-2007)。 – 2013-11-25 20:03:46

0

我会想到,一个办法是有一个“幕后的”主要只用于以下目的形式:

  1. 选择和显示的其他形式作为一个主窗体,然后永久隐藏自己(可见:= 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.