Detecting a taskbar icon flashing?

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.

Up vote 0 down vote favorite share g+ share fb share tw.

I want to make a program that detects this and then opens the program that is flashing and does stuff with it. Ideally I would like to use AutoIT or some part of the windows api to detect it but I can't find any solutions. Windows winapi windows-7 taskbar autoit link|improve this question asked Feb 16 at 4:40Michael3617 77% accept rate.

6 This doesn't make sense. A button is flashing because a program tried to push its window in the foreground while the user is busy using a window. Preventing this focus steal is strongly preferred by users.

Google SPI_SETFOREGROUNDLOCKTIMEOUT if you want to ignore that. – Hans Passant Feb 16 at 4:46 You could just do a PixelSearch at your taskbar region (found with: $taskbar = WinGetHandle("Class:Shell_TrayWnd"), $taskbarPos = WinGetPos($taskbar), $tasklistPos = ControlGetPos($taskbar, "", "CLASS:MSTaskListWClass; INSTANCE:1")) like PixelSearch($taskbarPos0 + $tasklistPos0, $taskbarPos1 + $tasklistPos1, $taskbarPos0 + $tasklistPos2, $taskbarPos1 + $tasklistPos3, 0x00CCCC00) with 0x00CCCC00 being that orange flash colour... search for a constant occurance. – Johannes Thomas Meyer Feb 20 at 22:39.

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: SetWindowsHookEx(WH_SHELL, hook_proc, NULL, dwPID); This sets a shell hook with the HOOKPROC as hook_proc and dwPID 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 a HWND to that window already. You need to generate the dwPID, which can be done as so: DWORD dwID = GetWindowThreadProcessId(hwnd, NULL) This will populate dwPID with the associated PID of the HWND. 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: LRESULT CALLBACK hook_proc(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode == HSHELL_REDRAW && lParam){ SetForegroundWindow(hwnd); // assumed hwnd is a global } return CallNextHookEx(NULL, nCode, wParam, lParam); } 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 of SetWindowHookEx must also be 64 bit. Also, after you are done, you should cleanup by removing your hook with UnhookWindowsHookEx.

The documented and realiable (but not necessarily easy) way is to register a WH_SHELL hook and listen for a HSHELL_REDRAW event with a nonzero lParam. – Raymond Chen Feb 17 at 21:17 I only care about one specific program that will be flashing, so that issue will never arise. Would you be able to shed some light on how to inject DLL's into applications?

I'm not quite sure what hooking is either. – Michael Feb 17 at 23:45 As Raymond has pointed out, I was actually wrong! However, let me post some code which might help you with the way he's suggesting.

– Mike Kwan Feb 17 at 23:55.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions