检测任务栏图标闪烁
我想制作一个脚本来检测任务栏图标何时闪烁并激活程序。我想使用 AutoIt 或 Windows API。
如何检测程序的任务栏图标何时开始闪烁?
I want to make a script that detects when taskbar icon flashes, and activates a program. I would like to use AutoIt or the Windows API.
How to detect when a program's taskbar icon starts flashing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 RegisterShellHookWindow API 并侦听 HSHELL_FLASH 消息。
http://msdn.microsoft。 com/en-us/library/windows/desktop/ms644989(v=vs.85).aspx
Use the RegisterShellHookWindow API and listen for HSHELL_FLASH messages.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644989(v=vs.85).aspx
为了直接回答您的问题,
没有简单(有记录且可靠)的方法来检测窗口的闪烁。这是由于 FlashWindow 导致的/FlashWindowEx。一个非常侵入性且严厉的选项是对两个 API 执行全局挂钩。您可以通过向每个用户模式应用程序注入 DLL 并执行本地钩子/绕行(通知您拥有的某些中央可执行文件)来实现此目的。然而,您的提议存在一个更大的根本问题,这使得它非常不可取。想象一个应用程序在没有焦点时不断闪烁。您的应用程序会将其设置为前台。如果有两个这样的应用程序会发生什么?
按照 Raymond 的建议使用 WH_SHELL 钩子并不太困难,可以通过调用 SetWindowsHookEx 如下:
这将使用
HOOKPROC
设置 shell 钩子hook_proc
和dwPID
是我们想要与钩子关联的线程。既然您提到您已经知道要定位哪个程序,我假设您已经有该窗口的HWND
。您需要生成dwPID
,可以按如下方式完成:这将使用
HWND
的关联 PID 填充dwPID
。对于下一步,我假设挂钩过程位于当前可执行文件中,而不是 DLL 中。挂钩过程可能是这样的:上面的代码尚未经过测试,可能包含错误,但应该让您大致了解要做什么。
关于窗口挂钩需要注意的一件重要事情是,必须从与目标具有相同位数的程序中调用
SetWindowHookEx
。即,如果您的目标是 64 位,则 SetWindowHookEx 的调用者也必须是 64 位。另外,完成后,您应该通过使用 UnhookWindowsHookEx.To answer your question directly,
there is no easy (documented and reliable) way to detect the flashing of the window. It occurs as a result of FlashWindow/FlashWindowEx. A very intrusive and heavy-handed option is to perform global hooking of both APIs. You could do this by injecting a DLL to every usermode application and performing a local hook/detour which notifies some central executable you own.However, there is a greater underlying problem with what you are proposing, which makes it extremely undesirable. Imagine an application which constantly flashes when it does not have focus. Your app would set it to the foreground. What would happen if there were two such applications?
Using a
WH_SHELL
hook as Raymond suggests is not too difficult and is done by calling SetWindowsHookEx as so:This sets a shell hook with the
HOOKPROC
ashook_proc
anddwPID
is the thread which we want to associate the hook with. Since you mention that you already know which program you want to target, I'll assume you have aHWND
to that window already. You need to generate thedwPID
, which can be done as so:This will populate
dwPID
with the associated PID of theHWND
. For the next step, I assume the hook procedure to be in the current executable as opposed to a DLL. The hook procedure might be something like this:The code above has not been tested and might contain mistakes but should give you a general idea of what to do.
One important thing to note with window hooks is that
SetWindowHookEx
must be called from a program with the same bitiness as the target. i.e. if your target is 64 bit, the caller ofSetWindowHookEx
must also be 64 bit. Also, after you are done, you should cleanup by removing your hook with UnhookWindowsHookEx.