Repository: microsoft/terminal (language: cpp)

Issue:
After GUI Error Message keyboards events ignored?
### Windows Terminal version

1.18.1462.0

### Windows build number

10.0.19045.3324

### Other Software

_No response_

### Steps to reproduce

portable
admin
default settings WT

trouble:

under CMD/GIT BASH/FAR Manager

Try run command:

like:
start 123

where 123 - not existed file in %path%

Windows show _GUI_ error message: can't find 123. Check name and try again...                     
close message by Enter/Esc/AltF4 or mouse click on button OK
we return to WT and see what in console show message too: can't find file 123

AND now ... drumroll ...




### Expected Behavior

keyboard events work, i press any key and see results

### Actual Behavior

keybord not work, press any keys but nothing print... (keyboards events ignored?)
treatment method: click by mouse (any keys) inside WT window

the problem is 100% reproducible



Discussion / hints:
under 
Microsoft.WindowsTerminal_1.17.11461.0_x64.zip
same behavior
Yes, I can see the same issue in Terminal Version 1.17.11461.0. Seems like after the message is closed by clicking OK or clicking the close button, the focus is not returned to the WT rather we have to once click on it for the focus to return. 
Hmm, where is the focus? :) i alt-tab and alt-tab again (return to WT window) -not help...
I'm 99% sure I know what's going on here. 

The `MessageBox` is parented to the console HWND. But for the Terminal, that HWND is not the Terminal's HWND - it's a hidden "pseudo hwnd". So when the MessageBox gets dismissed, and it returns foreground to its parent - the window that gets foreground is NOT the Terminal's window. 

This is also probably **H**ard to solve. I'm not sure we get notified when we get foreground. And #13388 has some details on why yeeting foreground to the Terminal is hard. 
may be interest for someones how to workaround this trouble...
for example if use AutoHotkey v2.x [https://www.autohotkey.com/]

add script (aka Little Magic Spell) **at end file AutoHotkey64.ahk**:

```
;------------------------- Restore Focus Windows Terminal if Lost -----------------------------
Loop {
  Try {
       hwnd := WinWait("A")
       className := WinGetClass(hwnd)

    if className == "PseudoConsoleWindow"
    {
     if WinExist("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")
     WinActivate
    }

WinWaitNotActive hwnd
  }
}

```


Fix patch:
diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp
index 2bfe9d1dd96..e0b13ded48f 100644
--- a/src/cascadia/WindowsTerminal/IslandWindow.cpp
+++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp
@@ -510,6 +510,15 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize
         _HandleCreateWindow(wparam, lparam);
         return 0;
     }
+    case WM_ENABLE:
+    {
+        if (_interopWindowHandle != nullptr)
+        {
+            // send focus to the child window
+            SetFocus(_interopWindowHandle);
+        }
+        break;
+    }
     case WM_SETFOCUS:
     {
         if (_interopWindowHandle != nullptr)
diff --git a/src/interactivity/base/InteractivityFactory.cpp b/src/interactivity/base/InteractivityFactory.cpp
index 0af2cb76d11..862b4db514d 100644
--- a/src/interactivity/base/InteractivityFactory.cpp
+++ b/src/interactivity/base/InteractivityFactory.cpp
@@ -463,6 +463,7 @@ using namespace Microsoft::Console::Interactivity;
         {
             _WritePseudoWindowCallback((bool)wParam);
         }
+        return 0;
     }
     case WM_GETOBJECT:
     {
@@ -476,6 +477,15 @@ using namespace Microsoft::Console::Interactivity;
         }
         return 0;
     }
+    case WM_ACTIVATE:
+    {
+        if (const auto ownerHwnd{ ::GetAncestor(hWnd, GA_ROOTOWNER) })
+        {
+            SetFocus(ownerHwnd);
+            return 0;
+        }
+        break;
+    }
     }
     // If we get this far, call the default window proc
     return DefWindowProcW(hWnd, Message, wParam, lParam);


Test patch: