Repository: microsoft/terminal
File: src/cascadia/WindowsTerminal/IslandWindow.cpp (C++)

Code before:
        {
            search->second.callback();
        }
        break;
    }
    case WM_SETTINGCHANGE:
    {
        // Currently, we only support checking when the OS theme changes. In
        // that case, wParam is 0. Re-evaluate when we decide to reload env vars
        // (GH#1125)
        if (wparam == 0 && lparam != 0)
        {
            const std::wstring param{ (wchar_t*)lparam };
            // ImmersiveColorSet seems to be the notification that the OS theme
            // changed. If that happens, let the app know, so it can hot-reload
            // themes, color schemes that might depend on the OS theme
            if (param == L"ImmersiveColorSet")
            {
                bool updateSettings = false;

                // GH#15732: Don't update the settings, unless the theme
                // _actually_ changed. ImmersiveColorSet gets sent more often
                // than just on a theme change. It notably gets sent when the PC
                // is locked, or the UAC prompt opens.
                auto isCurrentlyDark = Theme::IsSystemInDarkTheme();
                if (isCurrentlyDark != _currentSystemThemeIsDark)
                {
                    _currentSystemThemeIsDark = isCurrentlyDark;
                    updateSettings = true;
                }

                bool isCurrentlyHighContrast = []() {
                    HIGHCONTRAST hc = { 0 };
                    hc.cbSize = sizeof(HIGHCONTRAST);
                    if (SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(hc), &hc, 0))
                    {
                        return (bool)(hc.dwFlags & HCF_HIGHCONTRASTON);
                    }
                    return false;
                }();

                if (isCurrentlyHighContrast != _currentHighContrastModeState)
                {
                    _currentHighContrastModeState = isCurrentlyHighContrast;
                    updateSettings = true;
                }

                if (updateSettings)
                {
                    UpdateSettingsRequested.raise(_currentHighContrastModeState);
                }

Review comment (suggestion):
I can't comment on the line above, but...
```cpp
const std::wstring param{ (wchar_t*)lparam };
```

No! 😄 The right way:
```cpp
if (wcscmp((const wchar_t*)param, L"ImmersiveColorSet") == 0)
```

`std::wstring` is an owned string. Generally speaking: If you don't write to it, you don't need to own it. In other words, a `wstring_view` should be used here.

However, we're dealing with a C API here (Win32 API) and with C strings in particular, so why use C++ at all? There's no need for that: https://en.cppreference.com/w/c/string/wide#String_examination

Code after:
// - Called when the window is minimized to the taskbar.
void IslandWindow::OnMinimize()
{
    // TODO GH#1989 Stop rendering island content when the app is minimized.
    if (_minimizeToNotificationArea)
    {
        HideWindow();
    }
}

// Method Description:
// - Called when the window is restored from having been minimized.
void IslandWindow::OnRestore()
{
    // TODO GH#1989 Stop rendering island content when the app is minimized.
}

void IslandWindow::SetContent(winrt::Windows::UI::Xaml::UIElement content)
{
    _rootGrid.Children().Clear();
    _rootGrid.Children().Append(content);
}

// Method Description:
// - Get the dimensions of our non-client area, as a rect where each component
//   represents that side.
// - The .left will be a negative number, to represent that the actual side of
//   the non-client area is outside the border of our window. It's roughly 8px (
//   * DPI scaling) to the left of the visible border.
// - The .right component will be positive, indicating that the nonclient border
//   is in the positive-x direction from the edge of our client area.
// - This will also include our titlebar! It's in the nonclient area for us.
// Arguments:
// - dpi: the scaling that we should use to calculate the border sizes.
// Return Value:
// - a til::rect whose components represent the margins of the nonclient area,
//   relative to the client area.
til::rect IslandWindow::GetNonClientFrame(const UINT dpi) const noexcept
{
    const auto windowStyle = static_cast<DWORD>(GetWindowLong(_window.get(), GWL_STYLE));
    RECT islandFrame{};

    // If we failed to get the correct window size for whatever reason, log
    // the error and go on. We'll use whatever the control proposed as the
    // size of our window, which will be at least close.
    LOG_IF_WIN32_BOOL_FALSE(AdjustWindowRectExForDpi(&islandFrame, windowStyle, false, 0, dpi));
    return til::rect{ islandFrame };
}

// Method Description:
// - Gets the difference between window and client area size.