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

Code before:
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "icon.h"
#include "TrayIcon.h"
#include "CustomWindowMessages.h"

#include <ScopedResourceLoader.h>
#include <LibraryResources.h>

using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Microsoft::Terminal;

TrayIcon::TrayIcon(const HWND owningHwnd) :
    _owningHwnd{ owningHwnd }
{
    CreateTrayIcon();
}

TrayIcon::~TrayIcon()
{
    RemoveIconFromTray();
}

void TrayIcon::CreateWindowProcess()
{
    WNDCLASSW wc{};
    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);
}


Review comment (suggestion):
```suggestion
void TrayIcon::CreateWindow()
```

This is sufficient -- it's not a process, after all! :smile:

Code after:
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "icon.h"
#include "TrayIcon.h"
#include "CustomWindowMessages.h"

#include <ScopedResourceLoader.h>
#include <LibraryResources.h>

using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Microsoft::Terminal;

TrayIcon::TrayIcon(const HWND owningHwnd) :
    _owningHwnd{ owningHwnd }
{
    CreateTrayIcon();
}

TrayIcon::~TrayIcon()
{
    RemoveIconFromTray();
}

void TrayIcon::_CreateWindow()
{
    WNDCLASSW wc{};
    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);
}