新创建的模式窗口在 Windows Vista 中失去焦点并变得无法访问
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/743713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Newly created modal window loses focus and become inacessible in Windows Vista
提问by Fabio Gomes
Sometimes when I open a modal window in my Delphi application it takes a while to show up, then I notice that the application is kind of blocked, and what happened was that the modal form was open with ShowModal but wasn't displayed and the application became locked as if the Modal Window was in the first layer.
有时,当我在我的 Delphi 应用程序中打开一个模态窗口时,它需要一段时间才能显示出来,然后我注意到该应用程序被阻塞了,发生的事情是模态窗体用 ShowModal 打开但没有显示,应用程序被锁定,就好像模态窗口在第一层一样。
Usually when this happens I have to use Alt + Tab or Windows + Tab to find the "hidden" modal window, but this doesn't work everytime.
通常当发生这种情况时,我必须使用 Alt + Tab 或 Windows + Tab 来找到“隐藏的”模式窗口,但这并不是每次都有效。
This behavior just happens in Vista, but its quite annoying.
这种行为只发生在 Vista 中,但很烦人。
Is there some way to prevent this "focus weirdness" from happening?
有什么方法可以防止这种“焦点怪异”的发生?
Thanks.
谢谢。
* EDIT *
* 编辑 *
Apparently setting Application.MainFormOnTaskbar := True solved the problem, but it is still too early to jump to conclusions because this happens randomly.
显然设置 Application.MainFormOnTaskbar := True 解决了问题,但现在下结论还为时过早,因为这是随机发生的。
* EDIT 2 *
* 编辑 2 *
ModalFormOnTaskbar didn't solve the problem, after that I tried setting PopupMode = pmAuto , but that just made the problem worst.
ModalFormOnTaskbar 没有解决问题,之后我尝试设置 PopupMode = pmAuto ,但这只会使问题变得更糟。
Right now I'm trying to set the PopupParent explicitly and will let you know if the problem is solved.
现在,我正在尝试明确设置 PopupParent,如果问题已解决,我会通知您。
采纳答案by Jim
Take a look at the PopupParent property. You may want to set it explicitly for your modal form prior to the ShowModal call. When PopupParent is nil (default) VCL behaves a bit differently depending on the value of the related PopupMode property.
查看 PopupParent 属性。您可能希望在 ShowModal 调用之前为您的模态表单显式设置它。当 PopupParent 为 nil(默认)时,VCL 的行为会有所不同,具体取决于相关 PopupMode 属性的值。
If you set the modal form's PopupParent to the form that's active just before you call ShowModal, that may help.
如果您在调用 ShowModal 之前将模态表单的 PopupParent 设置为处于活动状态的表单,这可能会有所帮助。
回答by R?mulo Ceccon
The issue you have started happening when Windows XP introduced the concept of window ghosting. Due to the unusual architecture Delphi uses (all forms are children of a hidden window — TApplication) many Delphi applications experience the same problem.
当 Windows XP 引入窗口重影的概念时,您开始出现的问题。由于 Delphi 使用的不寻常架构(所有窗体都是隐藏窗口 - TApplication 的子级),许多 Delphi 应用程序遇到相同的问题。
One way to quickly solve it is to disable window ghostingwhen initializing the application:
快速解决它的一种方法是在初始化应用程序时禁用窗口重影:
var
User32: HMODULE;
DisableProcessWindowsGhosting: TProcedure;
begin
User32 := GetModuleHandle('USER32');
if User32 <> 0 then
begin
DisableProcessWindowsGhosting := GetProcAddress(User32, 'DisableProcessWindowsGhosting');
if Assigned(DisableProcessWindowsGhosting) then
DisableProcessWindowsGhosting;
end;
end;
Another possible (more elegant though laborious) solution is to normalize your Delphi application.
另一种可能(更优雅但更费力)的解决方案是规范化您的 Delphi 应用程序。
A third option would be switching to Delphi 2006 (Delphi 10.0).
第三种选择是切换到 Delphi 2006 (Delphi 10.0)。
Besides the issue you're reporting Delphi's architecture introduces more oddities, among them the different task bar menu and the inability to flash.
除了您报告的问题之外,Delphi 的体系结构引入了更多奇怪的东西,其中包括不同的任务栏菜单和无法闪烁。
回答by Maya
I have managed to reduce a lot of these occurences by removing any calls to Application.ProcessMessages that I have in my code, wherever I can.
我尽可能地通过删除我的代码中对 Application.ProcessMessages 的任何调用,设法减少了很多此类事件的发生。
回答by Rod Lima
Alt+P+V
(.dpr) has Application.MainFormOnTaskbar := True;
for default, I don't know why, but if I put Application.MainFormOnTaskbar := False;
the problem is solved.
Alt+P+V
(.dpr) 有Application.MainFormOnTaskbar := True;
默认,我不知道为什么,但如果我把Application.MainFormOnTaskbar := False;
问题解决了。
回答by JMC
I had the same issue on Windows 10, and I solved it by replacing in the dpr/dproj file :
我在 Windows 10 上遇到了同样的问题,我通过替换 dpr/dproj 文件解决了这个问题:
… Application.CreateForm(TFrmMain, FrmMain);
… Application.CreateForm(TFrmMain, FrmMain);
Application.run; …
应用程序运行;…
By
经过
… Application.CreateForm(TFrmMain, FrmMain);
… Application.CreateForm(TFrmMain, FrmMain);
Try FrmMain.ShowModal; Finally FrmMain.Free; End;
试试 FrmMain.ShowModal; 最后 FrmMain.Free; 结尾;
回答by JMC
You may want to try editing Forms.pas
to add the code below into TCustomForm.ShowModal()
, just before the call to Application.ModalStarted()
:
您可能想尝试编辑Forms.pas
以将以下代码添加到 中TCustomForm.ShowModal()
,就在调用 之前Application.ModalStarted()
:
if Assigned(Application) then begin
while PeekMessage(msg, Application.Handle, CM_ACTIVATE, CM_DEACTIVATE, PM_REMOVE) do begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
end;