如何跟踪窗口何时被激活和停用?

发布于 2024-09-14 18:42:40 字数 82 浏览 2 评论 0 原文

我正在制作一个任务栏,我需要知道活动窗口何时更改。我不想使用计时器。我想也许有一个 WndProc 消息我可以拦截。

我正在使用 C#

I am making an taskbar and I need to know when the active window is changed. I don't want to use a timer. I'm thinking that maybe there is a WndProc message I can intercept.

I'm using C#

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

安人多梦 2024-09-21 18:42:40

这需要通过 SetWindowsHookEx WH_SHELL 设置一个钩子。该回调会获取 HSHELL_WINDOWACTIVATED 和 HSHELL_WINDOWCREATED 等通知,以便您可以了解顶级窗口发生的情况。查看“ShellProc 的 SDK 文章”查看您可以获得的通知的完整列表。几乎所有这些都与实现您自己的任务栏相关。

这是个好消息。坏消息是 WH_SHELL 是一个全局钩子。它需要一个可以注入另一个进程的 DLL。问题是,您无法用托管代码编写该 DLL。将托管代码注入非托管进程是不可能的。

再次回到好消息,有人解决了这个问题,并创建了一个可注入且可以与托管代码互操作的非托管 DLL。项目在这里。不知道它有多好。我怀疑它可能不太能证明 UAC。

That requires a hook set by SetWindowsHookEx, WH_SHELL. The callback gets notifications like HSHELL_WINDOWACTIVATED and HSHELL_WINDOWCREATED so that you can know what's happening with the top-level windows. Check out the SDK article for "ShellProc" for the full list of notifications you can get. Just about all of them are relevant to implementing your own taskbar.

That was the good news. The bad news is that WH_SHELL is a global hook. It requires a DLL that can be injected into another process. Problem is, you can't write that DLL in managed code. Injecting managed code into an unmanaged process is not possible.

Back to good news again, somebody has solved that problem and has created an unmanaged DLL that is injectable and can interop with managed code. The project is here. No idea how good it is. I suspect it might not be quite UAC proof.

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