微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

delphi – 检测Foreground窗口何时更改

我知道哪个使用 GetForegroundWindow功能我可以获得当前活动窗口句柄,但现在我想检测活动窗口(任何应用程序)何时更改(变为活动状态).我想到的第一个解决方案是

>存储GetForegroundWindow函数返回的当前值(句柄).
>使用计时器组件再次检查GetForegroundWindow返回的值并与旧值进行比较.

我想知道是否存在更好的方法来执行此操作可能使用Windows消息或其他东西.

解决方法

使用 SetWindowsHookEx安装CBT挂钩. MSDN描述了您将提供的 callback function

The system calls this function before activating,creating,destroying,minimizing,maximizing,moving,or sizing a window; before completing a system command; before removing a mouse or keyboard event from the system message queue; before setting the keyboard focus; or before synchronizing with the system message queue. A computer-based training (CBT) application uses this hook procedure to receive useful notifications from the system.

您感兴趣的电话是第一个参数是HCBT_Activate的电话. wParam参数将告诉您窗口句柄.

原文地址:https://www.jb51.cc/delphi/101841.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐