使2个表格能够相互重叠? [英] Make 2 forms able to overlap each other?

查看:166
本文介绍了使2个表格能够相互重叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这里有一个例子:

我想要一个单独的表单与主窗体显示沿,所以它不与主窗体重叠。 img src =https://i.stack.imgur.com/cxYOy.pngalt =示例>



注意主程序如何重叠日志?我不知道在Delphi中怎么做。



谢谢!

解决方案

这个问题的答案在于非常有用的窗口功能 MSDN主题。



相关信息是:


重叠或弹出窗口可以是另一个重叠或弹出式
窗口所拥有的
。在窗口中拥有几个
约束。




  • 拥有的窗口始终位于z列的所有者的上方。 / li>
  • 当系统的所有者
    被销毁时,系统会自动破坏拥有的窗口。

  • 当所有者的所有者最小化时,所有的窗口将被隐藏。 / li>

应用程序中的主窗体是所有者(在Windows术语中,而不是Delphi术语)其他弹出窗口。上面的第一个项目点意味着所有的窗口总是出现在主窗体(所有者)的上方。



尝试创建一个包含3个表单的应用程序并显示所有窗体。 .dpr将如下所示:

 程序OwnedWindows; 

使用
表单,
主要在Main.pas{MainForm},
Popup1在Popup1.pas{PopupForm1},
Popup2在Popup2.pas{PopupForm2}中;

{$ R * .res}

begin
Application.Initialize;
Application.MainFormOnTaskbar:= True;
Application.CreateForm(TMainForm,Main);
Application.CreateForm(TPopupForm1,PopupForm1);
Application.CreateForm(TPopupForm2,PopupForm2);
PopupForm1.Show;
PopupForm2.Show;
Application.Run;
结束。

您将看到主窗体总是位于其他两种窗体之下,但这些其他拥有的窗体可以在彼此之上或之下。当您最小化主窗体时,它们全部消失。



如果要使所有窗体顶级未知窗口,您可以:

 程序TPopupForm1.CreateParams(var Params:TCreateParams); 
开始
继承;
Params.WndParent:= 0;
结束

在我的例子中,像TPopupForm2一样聪明。这将导致所有3个窗口都有任务栏按钮。



另一种方法是恢复到Vista之前的方式,使应用程序的隐藏窗口成为顶级的,级别所有者窗口。您可以通过确保Application.MainFormOnTaskbar为False来执行此操作。跳过所有CreateParams代码,现在您将在任务栏上有一个窗口,任何一个窗口都可以高于任何其他窗口,因为顶层所有者窗口是隐藏的窗口Application.Handle。当然,缺点是你失去了你的航空Peek。



所以,我想你需要做的是使主窗体像往常一样出现在任务栏上,但是确保其他表单不是以主窗体所有(在Windows中)。但是它们需要拥有,以避免将它们放在任务栏中。因此,您可以使用CreateParams方法使隐藏的应用程序窗口成为所有者,如下所示:

 过程TOverlappedPopupForm.CreateParams(var Params :TCreateParams); 
开始
继承;
Params.WndParent:= Application.Handle;
结束

虽然您在评论中另有说明,但是当我这样做时,我发现弹出窗体确实隐藏当我最小化主窗体。当主窗体恢复时再次显示。因此,我认为这完全可以解决你的问题。


I would like to have a seperate form that shows "along" with my main form, so it does not overlap the main form.

Here's an example:

Notice how the main program, overlaps the log? I can't figure out how to do that in Delphi.

Thanks!

解决方案

The answers to this question lie in the very useful Window Features MSDN topic.

The pertinent information is:

An overlapped or pop-up window can be owned by another overlapped or pop-up window. Being owned places several constraints on a window.

  • An owned window is always above its owner in the z-order.
  • The system automatically destroys an owned window when its owner is destroyed.
  • An owned window is hidden when its owner is minimized.

The main form in your app is the owner (in Windows terminology rather than Delphi terminology) of the other popup windows. The first bullet point above implies that the owned windows always appear above the main form (the owner).

Try creating an app with 3 forms and show them all. The .dpr would look like this:

program OwnedWindows;

uses
  Forms,
  Main in 'Main.pas' {MainForm},
  Popup1 in 'Popup1.pas' {PopupForm1},
  Popup2 in 'Popup2.pas' {PopupForm2};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TMainForm, Main);
  Application.CreateForm(TPopupForm1, PopupForm1);
  Application.CreateForm(TPopupForm2, PopupForm2);
  PopupForm1.Show;
  PopupForm2.Show;
  Application.Run;
end.

You will see that the main form is always underneath the other two forms, but these other owned forms can be above or below each other. When you minimize the main form they all disappear.

You could if you want make all of your forms top-level unowned windows:

procedure TPopupForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.WndParent := 0;
end;

And like wise for TPopupForm2 in my example. This would result in all 3 windows having taskbar buttons.

One other approach is to revert to the pre-Vista way of things and make the Application's hidden window be the top-level owner window. You do this by making sure that Application.MainFormOnTaskbar is False. Skip all the CreateParams code and you'll now have a single window on the taskbar and any of your windows can be above any other because the top-level owner window is the hidden window Application.Handle. Of course the downside is that you lose your Aero Peek.

So, I guess what you need to do is to make the main form appear on the taskbar as usual, but ensure that the other forms are not owned (in the Windows sense) by the main form. But they need to be owned to avoid having them in the taskbar. So you can make the hidden application window be the owner using the CreateParams method, like so:

procedure TOverlappedPopupForm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.WndParent := Application.Handle;
end;

Although you state otherwise in the comments, when I do this I find that the popup form is indeed hidden when I minimize the main form. And it is shown again when the main form is restored. Thus I think this does solve your problem completely.

这篇关于使2个表格能够相互重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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