Home > Software engineering >  How to get the HWND of the taskbar MSTaskListWClass?
How to get the HWND of the taskbar MSTaskListWClass?

Time:08-16

How i could retrieve the MSTaskListWClass hWnd?

I mean the "Running applications" tool bar which shows the button of each window in the taskbar.

enter image description here

I have tried to get it with:

HWND mstask = FindWindow(L"MSTaskListWClass", NULL);
DWORD err = GetLastError();

But mstask return null, err outputs 0

CodePudding user response:

FindWindowW retrieves a handle to the top-level windows only. not for child windows. so need first search for parent window - "Shell_TrayWnd" and than use EnumChildWindows

BOOL CALLBACK EnumChild(HWND hwnd, LPARAM lParam)
{
    WCHAR name[32];
    if (GetClassNameW(hwnd, name, _countof(name)) && !wcscmp(name, L"MSTaskListWClass"))
    {
        *(HWND*)lParam = hwnd;
        return FALSE;
    }

    return TRUE;
}

HWND GetMSTaskListW()
{
    HWND hwnd = 0;
    if (HWND hWndParent = FindWindowW(L"Shell_TrayWnd", 0))
    {
        EnumChildWindows(hWndParent, EnumChild, (LPARAM)&hwnd);
    }

    return hwnd;
}
  • Related