Quantcast
Channel: C++博客-所有随笔
Viewing all articles
Browse latest Browse all 7881

获取桌面窗口句柄

$
0
0
HWND FindDesktopIconWnd()
{
    HWND hWndDesktop = NULL;
    HWND hProgMan = ::FindWindow(L"Progman", NULL);
    if (hProgMan)
    {
        HWND hShellDefView = ::FindWindowEx(hProgMan, NULL, L"SHELLDLL_DefView", NULL);
        if (hShellDefView) hWndDesktop = ::FindWindowEx(hShellDefView, NULL, L"SysListView32", NULL);
    }
    if (hWndDesktop) return hWndDesktop;

    HWND hwndWorkerW = NULL;
    HWND hShellDefView = NULL;
    HWND hwndDesktop = NULL;
    while (hwndDesktop == NULL)//必须存在桌面窗口层次  
    {
        hwndWorkerW = ::FindWindowEx(0, hwndWorkerW, L"WorkerW", NULL);//获得WorkerW类的窗口  
        if (hwndWorkerW == NULL) break;//未知错误

        hShellDefView = ::FindWindowEx(hwndWorkerW, NULL, L"SHELLDLL_DefView", NULL);
        if (hShellDefView == NULL) continue;

        hwndDesktop = hShellDefView;
        //hwndDesktop = ::FindWindowEx(hShellDefView, NULL, L"SysListView32", NULL);
        //hwndDesktop = ::FindWindowEx(hwndDesktop, NULL, L"SysHeader32", NULL);
    }

    return hwndDesktop;
}

bukebushuo 2014-06-26 22:46 发表评论

Viewing all articles
Browse latest Browse all 7881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>