- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
祝大家有美好的一天!
我想在我的应用程序中将不同形式的工作模拟为不同的程序。
所有表单在任务栏上都有自己的按钮,应用程序的主窗体是不可见的并且 Application.ShowMainForm := false。
但是如果我显示两个表单,然后打开一些覆盖两个表单的程序,然后打开第一个表单(第二个表单在某个程序后面),然后关闭第一个表单,第二个表单在某个程序前面激活并恢复。
我知道它会恢复,因为在关闭第一个表单后,我的应用程序保持事件状态,这就是显示第一个可见表单的原因。如何防止恢复第二种形式?似乎我需要在关闭后发送回我的应用程序,但我不知道如何。
@David Heffernan
It's actually Windows that is behind all of that. When one of your forms is closed, Windows has to decide where to move the focus too. And it chooses to move it to another top-level window in your process, since a visible one exists. It makes this happen by sending the window that it selects a WM_SETFOCUS message. No doubt you can intercept this and stop it happening
type
TfMyForm = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FOldWindowProc: TWndMethod;
procedure NewWindowProc(var Message: TMessage);
end;
implementation
procedure TfMyForm.FormCreate(Sender: TObject);
begin
FOldWindowProc := WindowProc;
WindowProc := NewWindowProc;
end;
procedure TfMyForm.NewWindowProc(var Message: TMessage);
begin
if Message.Msg = WM_SETFOCUS then
Beep;
FOldWindowProc(Message);
end;
最佳答案
这是我自己找到的解决方案。
procedure SwitchToPreviousWindow(AHandle: HWND);
var PrevWindow: HWND;
begin
PrevWindow := GetNextWindow(AHandle, GW_HWNDNEXT);
while PrevWindow <> NULL do
begin
if IsWindowVisible(PrevWindow) then
begin
SetForegroundWindow(PrevWindow);
Exit;
end;
PrevWindow := GetNextWindow(PrevWindow, GW_HWNDNEXT);
end;
end;
procedure TfMyForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SwitchToPreviousWindow(Self.Handle);
end;
关于forms - 类似于 TApplication 的 SendToBack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20545142/
这个属性是什么时候引入的? (如果它说答案太短 - 包含 VERnnn 条件符号 :) 最佳答案 RAD Studio 2007 的“非破坏性”版本引入了 TApplication.MainFormO
Application 实例是在何时何地创建的?(Screen 实例也是如此)。 我在 Forms 或 System initialization 部分中没有看到任何内容。 在 Application
有一天,我有了一个疯狂的想法,要制作一个全新的 TApplication 替代品来进行实验。我已经编译和运行了所有内容,它确实正确显示了主窗体,一切都响应良好,但是关闭窗体后,应用程序不会停止。我确定
我有一个应用程序需要几秒钟才能加载(大量初始化)。 GUI 在启动期间卡住。所以我想创建一个在应用程序加载时淡入和淡出的启动屏幕。我用TBackgroundWorker组件在后台线程中执行动画。 但是
祝大家有美好的一天! 我想在我的应用程序中将不同形式的工作模拟为不同的程序。 所有表单在任务栏上都有自己的按钮,应用程序的主窗体是不可见的并且 Application.ShowMainForm :=
我是一名 Delphi 新手,但我试图使用 Spy++ 来理解 TApplication 和 TfrmMain 窗口之间的关系。看起来 TfrmMain 窗口是具有正确屏幕坐标的真实窗口,但 TApp
我用 D6 检查了 FastMM4。当我使用“Forms”调试一个简单的应用程序时,每次都会出现 3 行内存泄漏。 This application has leaked memory. The sm
这就是问题(剩下的只是为了让你可以告诉我我做错了)。 有什么方法可以确保要运行的第一个二进制文件(即我的可执行文件)是第一个初始化 vcl.controls.pas 的文件? 我问this quest
我是一名优秀的程序员,十分优秀!