使 2 个表格能够相互重叠?

发布于 2024-10-25 04:37:20 字数 173 浏览 9 评论 0原文

我想要一个单独的表单,与我的主表单“一起”显示,这样它就不会与主表单重叠。

这是一个示例: Example

注意主程序如何重叠日志?我不知道如何在 Delphi 中做到这一点。

谢谢!

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: Example

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

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁许谁一生繁华 2024-11-01 04:37:20

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

相关信息是:

重叠或弹出窗口可以
由另一个重叠或弹出窗口拥有
窗户。拥有多个地方
窗口上的约束。

  • 在 z 顺序中,拥有的窗口始终位于其所有者之上。
  • 当拥有的窗口的所有者被删除时,系统会自动销毁该窗口。
    被毁了。
  • 当其所有者最小化时,拥有的窗口将被隐藏。

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

尝试创建一个包含 3 个表单的应用程序并显示所有表单。 .dpr 看起来像这样:

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.

您将看到主窗体始终位于其他两个窗体的下方,但这些其他拥有的窗体可以位于彼此的上方或下方。当您最小化主窗体时,它们都会消失。

如果您想让所有表单成为顶级无主窗口,您可以这样做:

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

在我的示例中,对于 TPopupForm2 也是如此。这将导致所有 3 个窗口都有任务栏按钮。

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

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

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

尽管您在注释中另有说明,但当我这样做时,我发现当我最小化主窗体时,弹出窗体确实是隐藏的。当主窗体恢复时,它会再次显示。因此我认为这确实完全解决了你的问题。

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.

挽心 2024-11-01 04:37:20

我现在还没有打开Delphi,但是可以设置

mainform.formstyle := fsStayOnTop 

并显示子窗体

childform.show;

吗?

或者尝试使用 SetWindowPos() 并设置主窗体上的 hWndInsertAfter 属性类似于 HWND_TOPMOST

I haven't got Delphi open now, but would setting

mainform.formstyle := fsStayOnTop 

and show the child form with

childform.show;

work?

or else try using SetWindowPos() and setting the hWndInsertAfter property to something like HWND_TOPMOST on the main form

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文