gpt4 book ai didi

windows - Delphi - 应用程序主窗体的焦点不正确

转载 作者:可可西里 更新时间:2023-11-01 14:35:00 29 4
gpt4 key购买 nike

在我的应用程序的两个部分中,主窗体在错误的时刻获得焦点:

错误 1。在特定打印机表单中单击“确定”时。

  1. 我打开 FastReports PDF 预览 - 这是第一个弹出窗口。该弹出窗口不会单独显示在任务栏中。这种形式是模态的。
  2. 然后我点击打印,
  3. 这会打开另一个带有标准打印选项的窗口。
  4. 然后我单击属性 - 打开驱动程序的特定形式。我更改双重打印设置。
  5. 当我点击“确定”时,预览表单 (1) 应该获得焦点,但主表单被带到前面。因为预览窗体仍然是模态的,所以很难返回到预览窗体。只有随机点击,预览表单才会再次聚焦。

clicking through


错误 2. 单击或拖动此特定滚动框会聚焦主窗体

  1. 此窗口处于事件状态。这是 Windows 任务栏中的一个独立窗口,不是模式窗口。此表格上有一个 gnostice pdf 查看器。
  2. 当我点击 scrollbox开始拖动,主窗体被带到前面。当我继续拖动时,pdf 表单的滚动仍在继续。此外,鼠标附近的工具提示会指示当前显示的页面。

Bug 2

我想解决这个奇怪的行为。所以,我的问题是:


What can be causing these focussing bugs?


关于申请:

  • 我已经注意到:弹出式表单似乎有点太大,如您在此处所见: form seems to large
  • 查看编辑
  • 一些窗体是 MDI 子窗体。
  • 我在代码中搜索了所有鼠标事件并在其中设置了断点。但是在出现这两个错误时该代码并未执行。
  • VCLskin被使用。
  • 错误 1 出现在 Fast 报告版本 5.6.1 和 5.6.8 中。
  • Windows 10。
  • 德尔福 XE 10.2。

编辑

  • 应用程序主窗体设置正确。启动时,首先会显示一个登录表单。登录后,将创建数据模块,创建一些没有所有者的表单(它们在应用程序端被释放)。

所有其他表单,包括主表单,都由应用程序拥有,而不是由登录表单拥有。确实不是作为 parent ,而是作为所有者,就像@uwe-raabe 说的那样。

然后主窗体就创建好了。这是通过登录表单创建的:

Frm_DatabaseLogin.CreateForm(TFrm_MainMenu, Frm_MainMenu);

调用:

procedure TFrm_DataBaseLogin.CreateForm(InstanceClass: TComponentClass;
var Reference);
begin
Updateprogress(InstanceClass.ClassName);
Application.CreateForm(InstanceClass,Reference);
end;

在 UpdateProgress 中没有什么特别的事情发生。

之后,其他表单也被创建,由应用程序拥有。最后,登录表单隐藏,因此显示主表单。

最佳答案

我在这里对您的启动代码做了一些假设。

“主窗体”可能是一个令人困惑的术语。从 TApplication 的角度来看,Application.MainForm 始终是使用 Application.CreateForm 创建的第一个窗体。

由于您的登录表单创建了您的应用程序的主表单然后隐藏了自身,因此登录表单仍然是“主要”表单。

您的屏幕截图在任务栏上显示了两个图标。我假设您要么正在覆盖 CreateParams,要么正在调用 SetWindowLong 来实现这一点。

我有一个类似的设置,其中包含一个“主”登录表单,该表单随后被隐藏。

在我的应用程序中,我为应该独立且具有任务栏图标的表单覆盖了 CreateParams:

procedure TMgrMain.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := 0;
end;

然后在显示弹出窗口时,我创建了带有所有者的表单(可能不需要),然后设置 PopupMode 和 PopupParent。自从我开始这个以来,我不再有弹出的表格。

procedure ShowAbout(Owner: TForm);
var
LocalForm: TAbout;
begin
LocalForm := TAbout.Create(Owner);
try
LocalForm.PopupMode := pmExplicit;
LocalForm.PopupParent := Owner;
LocalForm.ShowModal;
finally
FreeAndNil(LocalForm);
end;
end;

来自PopupParent help :

If the PopupMode property is set to pmExplicit and PopupParent is nil, then the Application.MainForm is implicitly used as the PopupParent. If no Application.MainForm is assigned, then Application.Handle is used as the PopupParent.

If the PopupMode property is set to pmAuto, Screen.ActiveForm is used as the PopupParent property.

我迈步的部分地方来自一位老 Peter Below newsgroup post .这也是现在非常古老的建议,并且是在添加 PopupParent/PopupMode 之前

Newsgroups: borland.public.delphi.winapi
From: "Peter Below (TeamB)" <100113.1...@compuXXserve.com>
Date: 2000/11/30
Subject: Re: Modeless window act like .exe

.. cut ..
Note that this can cause some problems with modal forms shown from secondary forms. If the user switches away from the app while a modal form is up and then back to the form that showed it the modal form may hide beneath the form. It is possible to deal with this by making sure the modal form is parented to the form that showed it (using params.WndParent as above) but this is not possible with the standard dialogs from the Dialogs unit and exceptions, which need more effort to get them to work right (basically handling Application.OnActivate, looking for modal forms parented to Application via GetLastActivepopup and bringing them to the top of the Z-order via SetWindowPos).
.. cut ..

最后是一个blog post讨论了为什么要对 PopupMode 和 PopupParent 进行更改。

关于windows - Delphi - 应用程序主窗体的焦点不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47200322/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com