如何不断获取当前的前台窗口?

发布于 2024-12-08 18:48:00 字数 281 浏览 5 评论 0原文

我想编写一个始终知道当前前台窗口是什么的进程。

我知道我可以在循环中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北座城市 2024-12-15 18:48:00

我认为您想要的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文