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

Code before:
    wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
    wc.hInstance = wil::GetModuleInstanceHandle();
    wc.lpszClassName = L"TRAY_ICON_HOSTING_WINDOW_CLASS";
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = &TrayIcon::_WindowProc;
    wc.hIcon = static_cast<HICON>(GetActiveAppIconHandle(true));
    RegisterClass(&wc);

    _trayIconHwnd = wil::unique_hwnd(CreateWindowW(wc.lpszClassName,
                                                   wc.lpszClassName,
                                                   WS_DISABLED,
                                                   CW_USEDEFAULT,
                                                   CW_USEDEFAULT,
                                                   CW_USEDEFAULT,
                                                   CW_USEDEFAULT,
                                                   HWND_MESSAGE,
                                                   nullptr,
                                                   wc.hInstance,
                                                   nullptr));

    WINRT_VERIFY(_trayIconHwnd);
}

LRESULT CALLBACK TrayIcon::_WindowProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept
{
    return DefWindowProc(window, message, wparam, lparam);
}

// Method Description:
// - Creates and adds an icon to the notification tray.
// If an icon already exists, update the HWND associated
// to the icon with this window's HWND.
// Arguments:
// - <unused>
// Return Value:
// - <none>
void TrayIcon::CreateTrayIcon()
{
    if (!_trayIconHwnd)
    {
        // Creating a disabled, non visible window just so we can set it
        // as the foreground window when showing the context menu.
        // This is done so that the context menu can be dismissed
        // when clicking outside of it.
        CreateWindowProcess();
    }

    NOTIFYICONDATA nid{};
    nid.cbSize = sizeof(NOTIFYICONDATA);

    // This HWND will receive the callbacks sent by the tray icon.

Review comment (suggestion):
I think you can actually just literally set, `lpfnWndProc = DefWindowProcW` above! No need for all this ^^

Code after:
    wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
    wc.hInstance = wil::GetModuleInstanceHandle();
    wc.lpszClassName = L"TRAY_ICON_HOSTING_WINDOW_CLASS";
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = DefWindowProcW;
    wc.hIcon = static_cast<HICON>(GetActiveAppIconHandle(true));
    RegisterClass(&wc);

    _trayIconHwnd = wil::unique_hwnd(CreateWindowW(wc.lpszClassName,
                                                   wc.lpszClassName,
                                                   WS_DISABLED,
                                                   CW_USEDEFAULT,
                                                   CW_USEDEFAULT,
                                                   CW_USEDEFAULT,
                                                   CW_USEDEFAULT,
                                                   HWND_MESSAGE,
                                                   nullptr,
                                                   wc.hInstance,
                                                   nullptr));

    WINRT_VERIFY(_trayIconHwnd);
}

// Method Description:
// - Creates and adds an icon to the notification tray.
// If an icon already exists, update the HWND associated
// to the icon with this window's HWND.
// Arguments:
// - <unused>
// Return Value:
// - <none>
void TrayIcon::CreateTrayIcon()
{
    if (!_trayIconHwnd)
    {
        // Creating a disabled, non visible window just so we can set it
        // as the foreground window when showing the context menu.
        // This is done so that the context menu can be dismissed
        // when clicking outside of it.
        _CreateWindow();
    }

    NOTIFYICONDATA nid{};
    nid.cbSize = sizeof(NOTIFYICONDATA);

    // This HWND will receive the callbacks sent by the tray icon.
    nid.hWnd = _owningHwnd;

    // App-defined identifier of the icon. The HWND and ID are used
    // to identify which icon to operate on when calling Shell_NotifyIcon.
    // Multiple icons can be associated with one HWND, but here we're only