简体   繁体   English

如何获取任务栏MSTaskListWClass的HWND?

[英]How to get the HWND of the taskbar MSTaskListWClass?

How i could retrieve the MSTaskListWClass hWnd ?我怎样才能检索MSTaskListWClass hWnd

I mean the "Running applications" tool bar which shows the button of each window in the taskbar.我的意思是“运行应用程序”工具栏,它在任务栏中显示每个 window 的按钮。

在此处输入图像描述

I have tried to get it with:我试图通过以下方式获得它:

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

But mstask return null, err outputs 0但是mstask返回null, err输出0

FindWindowW retrieves a handle to the top-level windows only. FindWindowW仅检索顶级 windows 的句柄。 not for child windows.不适用于儿童 windows。 so need first search for parent window - "Shell_TrayWnd" and than use EnumChildWindows所以需要首先搜索父 window -“Shell_TrayWnd”,然后使用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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM