【问题标题】:How to allow Delphi secondary forms behind the main form如何让Delphi辅助窗体在主窗体后面
【发布时间】:2011-05-13 13:57:59
【问题描述】:

如果在 Delphi 2010 或 XE Application.MainFormOnTaskbar 中设置为 true,则所有辅助窗体始终位于主窗口前面。 Popupmode 或 PopupParent 属性设置为什么并不重要。但是,我希望能够在主窗体后面显示辅助窗口。

如果我将 MainFormOnTaskbar 设置为 false,它可以工作,但是 Windows 7 功能被破坏(Alt-tab、Windows 栏图标等)。

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

【问题讨论】:

    标签: delphi forms delphi-2010 delphi-xe


    【解决方案1】:

    基本上你不能。 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,了解可能涉及的内容。

    【讨论】:

    • 提到的文章现在是here
    【解决方案2】:

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

    1. 选择并显示其他表单之一作为主表单,然后像老式的“flash”屏幕一样永久隐藏自身(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.
    

    【讨论】:

      【解决方案3】:

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

      *.dpr

      改变 Application.MainFormOnTaskbar := true;Application.MainFormOnTaskbar := false;

      这将允许你在主窗体后面的子窗体。

      【讨论】:

      • 来自问题:“如果我将 MainFormOnTaskbar 设置为 false,它可以工作,但是...”.
      猜你喜欢
      • 1970-01-01
      • 2022-01-08
      • 2010-12-26
      • 1970-01-01
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多