Foreground Vs Active window

The active window (the result of GetActiveWindow()) is the window attached to the calling thread that gets input. The foreground window (the result of of GetForegroundWindow()) is the window that’s currently getting input regardless of its relationship to the calling thread. The active window is essentially localized to your application; the foreground window is global to the system.

For example, if a window belonging to another process is the foreground, calling GetActiveWindow() from within your own process will return NULL.

I believe that it’s true that being the foreground window implies being the active window, but the converse is not true. Also note that in modern Windows, applications generally cannot use SetForegroundWindow() to steal focus from another process (unless that process has explicitly given permission via AllowSetForegroundWindow).

Leave a Comment