If its window cannot become the current active window, then the parent window of this window is tried, and so on, until a top-level window is reached.
Activating a window sends a Deactivate event to the old current active window, and an Activate event to the new one.
When the application is iconified, the current active window is deactivated. When the application is uniconified, then the current active window is reactivated again.