Are there any solutions to prevent applications stealing focus from the active window?
This is especially annoying when I'm starting an application, switch to do something else and the new application starts receiving half a sentence of text.
window focuswindows
Are there any solutions to prevent applications stealing focus from the active window?
This is especially annoying when I'm starting an application, switch to do something else and the new application starts receiving half a sentence of text.
Best Answer
This is not possible without extensive manipulation of Windows internals and you need to get over it.
There are moments in daily computer use when it is really important that you make one action before the operating system allows you to do another. To do that, it needs to lock your focus on certain windows. In Windows, control over this behavior is largely left to the developers of the individual programs that you use.
Not every developer makes the right decisions when it comes to this topic.
I know that this is very frustrating and annoying, but you can't have your cake and eat it too. There are probably many cases throughout your daily life where you're perfectly fine with the focus being moved to a certain UI element or an application requesting that the focus remains locked on it. But most applications are somewhat equal when it comes to deciding who is the lead right now and the system can never be perfect.
A while ago I did extensive research on solving this issue once and for all (and failed). The result of my research can be found on the annoyance project page.
The project also includes an application that repeatedly tries to grab focus by calling:
As we can see from this snippet, my research was also focused on other aspects of user interface behavior I don't like.
The way I tried to solve this was to load a DLL into every new process and hook the API calls that cause another windows to be activated.
The last part is the easy one, thanks to awesome API hooking libraries out there. I used the very great mhook library:
From my tests back then, this worked great. Except for the part of loading the DLL into every new process. As one might imagine, that's nothing to take too lightly. I used the AppInit_DLLs approach back then (which is simply not sufficient).
Basically, this works great. But I never found the time to write something that properly injects my DLL into new processes. And the time invested in this largely overshadows the annoyance the focus stealing causes me.
In addition to the DLL injection problem, there is also a focus-stealing method which I didn't cover in the implementation on Google Code. A co-worker actually did some additional research and covered that method. The problem was discussed on SO: https://stackoverflow.com/questions/7430864/windows-7-prevent-application-from-losing-focus