96f4a9daef
This PR is a small start in a broader "Minimize to Tray" feature (#5727). This particular change is scoped only to the scenario when a quake window is minimized. Currently the only way to bring back the quake window when it's minimized is to press the global hotkey again. This gives another option - to press the terminal icon in the tray. Eventually though, minimize to tray will be available for any window, and I'd like more time to flesh out the general porpoise scenarios and context menus. Having just a bit in this PR also helps reviewers by keeping it small!
55 lines
1.6 KiB
C++
55 lines
1.6 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#include "pch.h"
|
|
#include "resource.h"
|
|
|
|
static int _GetActiveAppIconResource()
|
|
{
|
|
auto iconResource{ IDI_APPICON };
|
|
|
|
HIGHCONTRASTW hcInfo{};
|
|
hcInfo.cbSize = sizeof(hcInfo);
|
|
|
|
if (SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof(hcInfo), &hcInfo, 0))
|
|
{
|
|
if (WI_IsFlagSet(hcInfo.dwFlags, HCF_HIGHCONTRASTON))
|
|
{
|
|
iconResource = IDI_APPICON_HC_BLACK;
|
|
|
|
if (0x00FFFFFF == GetSysColor(COLOR_WINDOW)) // white window color == white high contrast
|
|
{
|
|
iconResource = IDI_APPICON_HC_WHITE;
|
|
}
|
|
}
|
|
}
|
|
|
|
return iconResource;
|
|
}
|
|
|
|
HANDLE GetActiveAppIconHandle(int size)
|
|
{
|
|
auto iconResource{ MAKEINTRESOURCEW(_GetActiveAppIconResource()) };
|
|
|
|
const auto smXIcon = size == ICON_SMALL ? SM_CXSMICON : SM_CXICON;
|
|
const auto smYIcon = size == ICON_SMALL ? SM_CYSMICON : SM_CYICON;
|
|
|
|
// These handles are loaded with LR_SHARED, so they are safe to "leak".
|
|
HANDLE hIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(smXIcon), GetSystemMetrics(smYIcon), LR_SHARED) };
|
|
LOG_LAST_ERROR_IF_NULL(hIcon);
|
|
|
|
return hIcon;
|
|
}
|
|
|
|
void UpdateWindowIconForActiveMetrics(HWND window)
|
|
{
|
|
if (auto smallIcon = GetActiveAppIconHandle(ICON_SMALL))
|
|
{
|
|
SendMessageW(window, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(smallIcon));
|
|
}
|
|
if (auto largeIcon = GetActiveAppIconHandle(ICON_BIG))
|
|
{
|
|
SendMessageW(window, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(largeIcon));
|
|
}
|
|
}
|