如何不断获取当前的前台窗口?
我想编写一个始终知道当前前台窗口是什么的进程。
我知道我可以在循环中使用 GetForegroundWindow 但我相信最好不要一直检查 GetForegroundWindow 。
所以我正在寻找类似事件 OnForegroundWindowChanged 或其他方法来执行此操作。
我知道我可以在 C++ 中为每个进程编写一个钩子并从那里发送事件,但我更喜欢在 C# 中完成这一切,而不是将 dll 注入到所有正在运行的进程(听起来不太稳定:)
谢谢,
Omri
I want to write a process that knows all the time what is the current foreground window.
I know i can use GetForegroundWindow in a loop but i believe it will be better not to check GetForegroundWindow all the time.
so what i'm looking for is something like an event OnForegroundWindowChanged or another method to do so.
I know i can writing an hook in C++ to every process and send the event from there but i prefer doing it all in c# and not to inject a dll to all running process (it don't sounds so stable :)
Thanks,
Omri
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您想要的是 UIAutomationEvents 的处理?
诚然,这是 Windows 辅助功能的一部分,我不确定它是否始终打开或需要启用,但是 尝试在这里获取指针。
I think that what you want is handling of UIAutomationEvents?
Admittedly this is part of windows accessibility functionality and I'm not sure if its always on or requires enabling, but Try here for pointers.