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

Code before:
    auto it = std::find_if(_systemMenuItems.begin(), _systemMenuItems.end(), [&itemLabel](const std::pair<UINT, SystemMenuItemInfo>& elem) {
        return elem.second.label == itemLabel;
    });
    if (it == _systemMenuItems.end())
    {
        return;
    }

    if (LOG_LAST_ERROR_IF(!DeleteMenu(systemMenu, it->first, MF_BYCOMMAND)))
    {
        return;
    }
    _systemMenuItems.erase(it->first);
}

void IslandWindow::UseMica(const bool newValue, const double /*titlebarOpacity*/)
{
    // This block of code enables Mica for our window. By all accounts, this
    // version of the code will only work on Windows 11, SV2. There's a slightly
    // different API surface for enabling Mica on Windows 11 22000.0.
    //
    // This API was only publicly supported as of Windows 11 SV2, 22621. Before
    // that version, this API will just return an error and do nothing silently.

    const int attribute = newValue ? DWMSBT_MAINWINDOW : DWMSBT_NONE;
    LOG_IF_FAILED(DwmSetWindowAttribute(GetHandle(), DWMWA_SYSTEMBACKDROP_TYPE, &attribute, sizeof(attribute)));
}

// Method Description:
// - This method is called when the window receives the WM_NCCREATE message.
// Return Value:
// - The value returned from the window proc.
[[nodiscard]] LRESULT IslandWindow::OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept
{
    const auto ret = BaseWindow::OnNcCreate(wParam, lParam);
    if (!ret)
    {
        return FALSE;
    }

    // This is a hack to make the window borders dark instead of light.
    // It must be done before WM_NCPAINT so that the borders are rendered with
    // the correct theme.
    // For more information, see GH#6620.
    LOG_IF_FAILED(TerminalTrySetDarkTheme(_window.get(), true));

    return TRUE;
}


Review comment (bug):
we're gonna log this on every windows 10 machine, and probably get smacked with a "garrulous event" bug

Code after:
    auto itemCount = GetMenuItemCount(systemMenu);
    if (LOG_LAST_ERROR_IF(itemCount == -1))
    {
        return;
    }

    auto it = std::find_if(_systemMenuItems.begin(), _systemMenuItems.end(), [&itemLabel](const std::pair<UINT, SystemMenuItemInfo>& elem) {
        return elem.second.label == itemLabel;
    });
    if (it == _systemMenuItems.end())
    {
        return;
    }

    if (LOG_LAST_ERROR_IF(!DeleteMenu(systemMenu, it->first, MF_BYCOMMAND)))
    {
        return;
    }
    _systemMenuItems.erase(it->first);
}

void IslandWindow::UseMica(const bool newValue, const double /*titlebarOpacity*/)
{
    // This block of code enables Mica for our window. By all accounts, this
    // version of the code will only work on Windows 11, SV2. There's a slightly
    // different API surface for enabling Mica on Windows 11 22000.0.
    //
    // This API was only publicly supported as of Windows 11 SV2, 22621. Before
    // that version, this API will just return an error and do nothing silently.

    const int attribute = newValue ? DWMSBT_MAINWINDOW : DWMSBT_NONE;
    std::ignore = DwmSetWindowAttribute(GetHandle(), DWMWA_SYSTEMBACKDROP_TYPE, &attribute, sizeof(attribute));
}

// Method Description:
// - This method is called when the window receives the WM_NCCREATE message.
// Return Value:
// - The value returned from the window proc.
[[nodiscard]] LRESULT IslandWindow::OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept
{
    const auto ret = BaseWindow::OnNcCreate(wParam, lParam);
    if (!ret)
    {
        return FALSE;
    }

    // This is a hack to make the window borders dark instead of light.
    // It must be done before WM_NCPAINT so that the borders are rendered with
    // the correct theme.
    // For more information, see GH#6620.
    //