What makes Notepad (and others) open behind my program when invoked through an IExplorerCommand?
See the question and my original answer on StackOverflowWindows restricts which processes can get and can set the foreground window to prevent focus stealing, for security and end-user experience reasons mostly. The quite complex rules are detailed here: AllowSetForegroundWindow function Remarks
But what's interesting is a process that can set the foreground window can enable another process to set the foreground window by calling AllowSetForegroundWindow
, which is what you want.
In your case, you don't know which (future) process will need the focus, so you can call AllowSetForegroundWindow(ASFW_ANY)
so all processes will be enabled to set the foreground window.