I want to understand under what conditions a process can set the foreground window using the Win32 function SetForegroundWindow. I tried reading its documentation and it says under Remarks:
A process can set the foreground window only if one of the following conditions is true:
- The process is the foreground process.
- The process was started by the foreground process.
- The process received the last input event.
- There is no foreground process.
- The process is being debugged.
- The foreground process is not a Modern Application or the Start Screen.
- The foreground is not locked (see
LockSetForegroundWindow).- The foreground lock time-out has expired (see
SPI_GETFOREGROUNDLOCKTIMEOUTinSystemParametersInfo).- No menus are active.
It seems to me that this cannot be accurate, as it would mean that all of these bullets would have to be false to restrict setting the foreground window, but the last four seem to be normally true (depending on your use of "modern" applications). So as written, setting the foreground window would almost never be restricted. Whereas experimentally it seems that having a menu active in another process' window is sufficient to block setting the foreground window, even if e.g. the foreground process is not a Modern Application (condition 6 is true).
What would be a more accurate way to express when a process can set the foreground window based on the listed conditions?