Rename HasFocus to IsForeground
... Better handling (with ugly code) of asynchronous showing/hiding of main window. To improve and clean up.