GetForegroundWindow function
returns a handle to the foreground window
(the window with which the user is currently working).
$hwnd = GetForegroundWindow();
Handle of window being in foreground.
The system assigns a slightly higher priority to the
thread that creates the foreground window
than it does to other threads. This is a simple wrapper around
Win32 function.