__int64 __fastcall ShouldAddWindowToTray(struct ITrayComponentHost *a1, HWND a2)
{
unsigned int v4; // ebx
char v5; // bp
HWND v6; // rdx
int v8; // [rsp+40h] [rbp+18h] BYREF
v4 = 0;
v8 = 0;
if ( (unsigned int)GetWindowBand(a2, &v8) )
{
v5 = byte_1801BA484[8 * v8];
if ( (GetPropW(a2, (LPCWSTR)0xA920) || v5)
&& (!(unsigned int)IsShellManagedWindow(a2)
|| ShellManagedWindowHelper::ShouldTreatShellManagedWindowAsNotShellManaged((ShellManagedWindowHelper *)a2, v6))
&& IsWindow(a2)
&& a2 != (HWND)(*(__int64 (__fastcall **)(struct ITrayComponentHost *))(*(_QWORD *)a1 + 656LL))(a1)
&& a2 != (HWND)(*(__int64 (__fastcall **)(struct ITrayComponentHost *))(*(_QWORD *)a1 + 664LL))(a1)
&& (GetClassWord(a2, -32) != g_SecondaryTaskbarAtom || !g_SecondaryTaskbarAtom) )
{
if ( IsWindowVisible(a2) )
return ShouldAddWindowToTrayHelper(a2);
}
}
return v4;
}
// 180040B50: variable 'v6' is possibly undefined
// 1801AE010: using guessed type __int64 __fastcall guard_dispatch_icall_thunk_10345483385596137414();
// 1801AF4A0: using guessed type __int64 __fastcall IsShellManagedWindow(_QWORD);
// 1801B0448: using guessed type __int64 __fastcall GetWindowBand(_QWORD, _QWORD);
// 1801BA484: using guessed type _BYTE byte_1801BA484[156];
// 18023288C: using guessed type unsigned __int16 g_SecondaryTaskbarAtom;
//----- (0000000180040B6C) ----------------------------------------------------
_BOOL8 __fastcall ShouldAddWindowToTrayHelper(HWND hWnd)
{
LONG WindowLongW; // ebx
if ( IsValidTabWindowForTray(hWnd)
&& ((WindowLongW = GetWindowLongW(hWnd, -20), !GetWindow(hWnd, 4u)) || (WindowLongW & 0x40000) != 0) )
{
return (WindowLongW & 0x80) == 0;
}
else
{
return 0LL;
}
}
//----- (0000000180040BCC) ----------------------------------------------------
// Hidden C++ exception states: #wind=6
bool __fastcall IsValidTabWindowForTray(HWND hwnd)
{
HANDLE PropW; // rsi
WCHAR *v3; // rbx
int v5; // eax
PROPERTYKEY v6; // [rsp+30h] [rbp-20h] BYREF
void *ppv; // [rsp+70h] [rbp+20h] BYREF
PCWSTR pszItem; // [rsp+78h] [rbp+28h] BYREF
__int64 v9; // [rsp+80h] [rbp+30h] BYREF
if ( !hwnd )
return 0;
PropW = GetPropW(hwnd, (LPCWSTR)0xA920);
ppv = 0LL;
v3 = 0LL;
pszItem = 0LL;
if ( PropW )
{
ppv = 0LL;
if ( SHGetPropertyStoreForWindow(hwnd, &GUID_886d8eeb_8cf2_4446_8d02_cdba1dbdcf99, &ppv) >= 0 )
{
wil::PropertyStoreHelper::PropertyStoreHelper((wil::PropertyStoreHelper *)&v9, (struct IPropertyStore *)ppv);
v6 = PKEY_AppUserModel_ID;
v5 = wil::PropertyStoreHelperBase<IPropertyStore>::GetString<_tagpropertykey>(&v9, (__int128 *)&v6, &pszItem);
v3 = (WCHAR *)pszItem;
if ( v5 >= 0 && pszItem )
{
pszItem = 0LL;
if ( SHCreateItemInKnownFolder(
&FOLDERID_AppsFolder,
0x4000u,
v3,
&GUID_7e9fb0d3_919f_4307_ab2e_9b1860310c93,
(void **)&pszItem) >= 0 )
{
wil::com_ptr_t<IPinnedList3,wil::err_exception_policy>::~com_ptr_t<IPinnedList3,wil::err_exception_policy>(&pszItem);
Microsoft::WRL::ComPtr<IVirtualDesktopNotificationService>::InternalRelease(&v9);
CoTaskMemFree(v3);
wil::com_ptr_t<IDataObject,wil::err_exception_policy>::~com_ptr_t<IDataObject,wil::err_exception_policy>(&ppv);
return 1;
}
wil::com_ptr_t<IPinnedList3,wil::err_exception_policy>::~com_ptr_t<IPinnedList3,wil::err_exception_policy>(&pszItem);
}
Microsoft::WRL::ComPtr<IVirtualDesktopNotificationService>::InternalRelease(&v9);
}
}
CoTaskMemFree(v3);
if ( ppv )
(*(void (__fastcall **)(void *))(*(_QWORD *)ppv + 16LL))(ppv);
return PropW == 0LL;
}
// 180044067: variable 'v5' is possibly undefined
// 1801AF4A0: using guessed type __int64 __fastcall IsShellManagedWindow(_QWORD);
// 1801B0448: using guessed type __int64 __fastcall GetWindowBand(_QWORD, _QWORD);
// 1801BA484: using guessed type _BYTE byte_1801BA484[156];
//----- (000000018004407C) ----------------------------------------------------
bool __fastcall ShellManagedWindowHelper::ShouldTreatShellManagedWindowAsNotShellManaged(
ShellManagedWindowHelper *this,
HWND a2)
{
return GetPropW((HWND)this, L"Microsoft.Windows.ShellManagedWindowAsNormalWindow") != 0LL;
}
The ShouldAddWindowToTray function determines whether a specific window (HWND a2) should be added to the taskbar (often referred to as the system tray) based on a series of checks and criteria. Here's a detailed breakdown of these criteria:
1. Window Band or Specific Property
-
Window Band Check: The function begins by calling GetWindowBand(a2, &v8). This retrieves the "band" or category of the window. If the window belongs to a recognized band (i.e., GetWindowBand returns a non-zero value), the function proceeds.
-
Specific Property Check: Alternatively, the window may have a specific property associated with it, identified by the property key 0xA920. This is checked using GetPropW(a2, (LPCWSTR)0xA920). Additionally, there's a check against a byte array byte_1801BA484 using the retrieved band index v8. If either the property exists or the corresponding byte value is non-zero, the window qualifies for further evaluation.
2. Shell Management Status
-
Shell-Managed Windows: Windows can be managed by the shell (i.e., the operating system's user interface manager). The function checks if the window is shell-managed using IsShellManagedWindow(a2).
-
Override Shell Management: If the window is shell-managed, the function uses ShellManagedWindowHelper::ShouldTreatShellManagedWindowAsNotShellManaged to determine if it should override this status and treat the window as not shell-managed. This allows certain shell-managed windows to bypass standard shell restrictions and be considered for the taskbar.
3. Window Validity and Uniqueness
-
Valid Window Handle: The window handle (a2) must refer to a valid window, verified by IsWindow(a2).
-
Exclusion of Specific Windows: The window should not be one of the internal windows managed by the tray component itself. This is ensured by comparing a2 against specific windows retrieved via the ITrayComponentHost interface (offsets 656 and 664 in the virtual table).
4. Class Identifier Verification
- Secondary Taskbar Exclusion: The function checks the window's class identifier using
GetClassWord(a2, -32). It ensures that this class identifier does not match the global g_SecondaryTaskbarAtom, unless g_SecondaryTaskbarAtom is undefined (zero). This prevents windows associated with secondary taskbar instances from being redundantly added.
5. Window Visibility
- Visible Windows Only: The window must be visible, as verified by
IsWindowVisible(a2). Hidden or minimized windows are excluded from being added to the taskbar.
6. Tab Window Validation
7. Final Decision
If all the above criteria are met, the function returns a non-zero value (typically 1), indicating that the window should be added to the taskbar. If any check fails, it returns 0, meaning the window should not be added.
Summary of Criteria
In summary, a window will be added to the taskbar only if:
- Belongs to a Recognized Band or Has a Specific Property: Ensures relevance.
- Is Not Shell-Managed or Overrides Shell Management: Allows flexibility in window management.
- Is a Valid and Unique Window: Prevents duplication and system window interference.
- Does Not Match Secondary Taskbar Identifiers: Maintains taskbar integrity.
- Is Visible: Only active windows are shown.
- Passes Tab Window Validation: Ensures appropriate window styles and application identity.
This comprehensive set of checks ensures that only appropriate and relevant windows are displayed on the taskbar, maintaining both functionality and user experience.