Repository: microsoft/terminal
File: src/interactivity/base/InteractivityFactory.cpp (C++)

Code before:
                // relative to the desktop. (there are other subtleties as well
                // as far as the difference between parent/child and owner/owned
                // windows). Evan K said we should do it this way, and he
                // definitely knows.
                //
                // GH#13066: Load-bearing: Make sure to set WS_POPUP. If you
                // don't, then GetAncestor(GetConsoleWindow(), GA_ROOTOWNER)
                // will return the console handle again, not the owning
                // terminal's handle. It's not entirely clear why, but WS_POPUP
                // is absolutely vital for this to work correctly.
                const auto windowStyle = WS_OVERLAPPEDWINDOW | WS_POPUP;
                const auto exStyles = WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_NOACTIVATE;

                // Attempt to create window.
                _pseudoConsoleWindowHwnd = hwnd = CreateWindowExW(exStyles,
                                                                  reinterpret_cast<LPCWSTR>(windowClassAtom),
                                                                  nullptr,
                                                                  windowStyle,
                                                                  0,
                                                                  0,
                                                                  0,
                                                                  0,
                                                                  owner,
                                                                  nullptr,
                                                                  nullptr,
                                                                  this);

                if (hwnd == nullptr)
                {
                    const auto gle = GetLastError();
                    status = NTSTATUS_FROM_WIN32(gle);
                }

                break;
            }
#ifdef BUILD_ONECORE_INTERACTIVITY
            case ApiLevel::OneCore:
                hwnd = 0;
                status = STATUS_SUCCESS;
                break;
#endif
            default:
                status = STATUS_INVALID_LEVEL;
                break;
            }
        }
        catch (...)
        {
            status = NTSTATUS_FROM_HRESULT(wil::ResultFromCaughtException());
        }
    }

Review comment (suggestion):
you can reduce the diffs here by assigning `_pseudoConsoleHwnd` to the value of `hwnd` later on line R437 :)

Code after:
    }

    // If we get this far, call the default window proc
    return DefWindowProcW(hWnd, Message, wParam, lParam);
}

// Method Description:
// - Per-object window procedure for pseudo console windows
// Arguments:
// - hWnd - Associated window handle from message
// - Message - ID of message in queue
// - wParam - Variable wParam depending on message type
// - lParam - Variable lParam depending on message type
// Return Value:
// - 0 if we processed this message. See details on how a WindowProc is implemented.
[[nodiscard]] LRESULT CALLBACK InteractivityFactory::PseudoWindowProc(_In_ HWND hWnd, _In_ UINT Message, _In_ WPARAM wParam, _In_ LPARAM lParam)
{
    switch (Message)
    {
    // NOTE: To the future reader, all window messages that are talked about but unused were tested
    //       during prototyping and didn't give quite the results needed to determine show/hide window
    //       state. The notes are left here for future expeditions into message queues.
    // case WM_QUERYOPEN:
    // It can be fun to toggle WM_QUERYOPEN but DefWindowProc returns TRUE.
    case WM_SIZE:
    {
        // Curiously, at least on Windows 10 (and rarely on Windows 11), if you
        // minimize the Terminal by clicking on the taskbar, then alt-tab to try
        // and restore the window, the Taskbar will decide to call
        // SwitchToWindow on us, the invisible, owned window of the main window.
        // When that happens, we'll get a WM_SIZE(SIZE_RESTORED, lParam=0). The
        // main window will NOT get a SwitchToWindow called. If we don't
        // actually inform the hosting process about this, then the main HWND
        // might stay hidden. Refer to GH#13589

        if (wParam == SIZE_RESTORED)
        {
            _WritePseudoWindowCallback(true);
        }

        if (wParam == SIZE_MINIMIZED)
        {
            _WritePseudoWindowCallback(false);
        }
        break;
    }
    // case WM_WINDOWPOSCHANGING:
    //     As long as user32 didn't eat the `ShowWindow` call because the window state requested
    //     matches the existing WS_VISIBLE state of the HWND... we should hear from it in WM_WINDOWPOSCHANGING.
    //     WM_WINDOWPOSCHANGING can tell us a bunch through the flags fields.
    //     We can also check IsIconic/IsZoomed on the HWND during the message