场景是我有一个’主应用’和’帮助应用’. ‘helper app’弹出一个键盘钩子,它是什么东西,然后重新聚焦主应用程序窗口.问题是,如果主应用程序在帮助程序处于活动状态时弹出模式对话
有什么策略可以解决这个问题?
看起来“主应用程序”的模态形式不属于主应用程序窗口,否则模态形式将始终位于主窗体之上.因此,可能是,它编译的Delphi版本没有MainFormOnTaskbar属性,或者没有设置.然后它必须是拥有窗口的隐藏应用程序窗口.您可以在关闭“帮助应用程序”表单时测试主应用程序窗口是否被禁用(如果有模式表单则会出现这种情况),并恢复隐藏应用程序窗口所拥有的最后一个活动弹出窗口(如果有).
var
Wnd: HWND; // handle to 'main app's main form
mWnd: HWND; // handle to possible modal form
AppWnd: HWND; // handle to hidden Application window
begin
..
if not IsWindowEnabled(Wnd) then begin // test if there's a modal form
AppWnd := GetWindowLong(Wnd, GWL_HWNDPARENT); // TApplication window handle
mWnd := GetLastActivePopup(AppWnd); // most recently active popup window
// restore focus to mWnd
end else
// restore focus to Wnd
(当然,不要忘记包含API函数结果的测试.)
