聚焦右窗 [英] Focussing the right window

查看:86
本文介绍了聚焦右窗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况是,我有一个主应用程序和一个帮助程序。 帮助程序弹出在键盘钩上,是否有东西,然后重新调整主程序窗口的焦点。问题在于,如果在辅助程序处于活动状态时主应用程序弹出一个模式对话框,然后该辅助程序将错误的窗口重新聚焦,则该模式对话框将被隐藏,并且主应用程序显示为冻结。

The scenario is that I have a 'main app' and a 'helper app'. The 'helper app' pops up on a keyboard hook, does it's stuff, then refocuses the main app window. The problem is that if the main app pops up a modal dialog when helper is active, and the helper then refocuses the wrong window, the modal dialog is hidden and the main app appears 'frozen'.

是否有解决此问题的策略建议?

Any suggestions of strategies to solve this?

推荐答案

它看起来像主应用程序的模态形式'不是主应用程序窗口所拥有,否则模态表单将始终保持在主表单上方。因此,可能是对于已编译的Delphi版本没有 MainFormOnTaskbar 属性,或者未设置该属性。然后,它必须是拥有这些窗口的隐藏的应用程序窗口。

It looks like the modal form of the 'main app' is not owned by the main app window, otherwise the modal form would stay above the main form at all times. So, possibly, either there's no MainFormOnTaskbar property for the Delphi version that it was compiled, or it is not set. Then it must be the hidden application window that owns the windows.

您可以在关闭帮助应用程序表单时测试主应用程序窗口是否被禁用( (如果有模式形式的话),并恢复由隐藏的应用程序窗口拥有的最后一个活动弹出窗口。

You can test if the main app window is disabled when closing your 'helper app' form (that would be the case if there's a modal form), and restore the last active popup window that is owned by the hidden application window if it is.

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函数结果的测试。)

(Don't forget to include tests for the result of the API functions of course.)

这篇关于聚焦右窗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆