Skip to content

Commit

Permalink
Make better
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Oct 20, 2020
1 parent 5c89698 commit d7c6690
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
13 changes: 9 additions & 4 deletions .github/actions/spell-check/dictionary/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ ACCESSDENIED
alignof
bitfield
bitfields
COLORPROPERTY
CLASSNOTAVAILABLE
COLORPROPERTY
CXICON
CYICON
environstrings
EXPCMDFLAGS
EXPCMDSTATE
fullkbd
futex
GETDESKWALLPAPER
GETHIGHCONTRAST
Hashtable
HIGHCONTRASTON
HIGHCONTRASTW
href
IAsync
IBind
Expand All @@ -24,8 +30,8 @@ IExplorer
IMap
IObject
IStorage
llabs
LCID
llabs
lround
LSHIFT
NCHITTEST
Expand All @@ -45,14 +51,13 @@ RSHIFT
rx
serializer
SIZENS
GETDESKWALLPAPER
UPDATEINIFILE
spsc
STDCPP
strchr
syscall
tmp
tx
UPDATEINIFILE
userenv
wcstoui
XDocument
Expand Down
27 changes: 22 additions & 5 deletions src/cascadia/WindowsTerminal/icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ static wchar_t* _GetActiveAppIcon()
if (WI_IsFlagSet(hcInfo.dwFlags, HCF_HIGHCONTRASTON))
{
WI_SetFlag(iconClass, IconClass::Variant_HC);
WI_UpdateFlag(iconClass, IconClass::Variant_HC_White, wcsstr(hcInfo.lpszDefaultScheme, L"White") != nullptr);

if (hcInfo.lpszDefaultScheme)
{
const std::wstring_view theme{ hcInfo.lpszDefaultScheme };
WI_UpdateFlag(iconClass, IconClass::Variant_HC_White, theme.find(L"White") != std::wstring_view::npos);
}
}
}

Expand All @@ -69,8 +74,20 @@ static wchar_t* _GetActiveAppIcon()
void UpdateWindowIconForActiveMetrics(HWND window)
{
auto iconResource{ _GetActiveAppIcon() };
HANDLE smallIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR) };
HANDLE largeIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR) };
SendMessageW(window, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(smallIcon));
SendMessageW(window, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(largeIcon));

// These handles are loaded with LR_SHARED, so they are safe to "leak".
HANDLE smallIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED) };
LOG_LAST_ERROR_IF_NULL(smallIcon);

HANDLE largeIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_SHARED) };
LOG_LAST_ERROR_IF_NULL(largeIcon);

if (smallIcon)
{
SendMessageW(window, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(smallIcon));
}
if (largeIcon)
{
SendMessageW(window, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(largeIcon));
}
}

0 comments on commit d7c6690

Please sign in to comment.