Windows 桌面各个窗口的获取


/*

 shellwindow.h

 sdragonx 2015-02-12 12:23:16

*/
#ifndef SHELLWINDOW_H_20150212122316
#define SHELLWINDOW_H_20150212122316


#include 


const static PTCHAR CLASS_NAME_TASKMAN = TEXT("Shell_TrayWnd");
const static PTCHAR CLASS_NAME_PROGMAN = TEXT("Progman");
const static PTCHAR CLASS_NAME_SHELL   = TEXT("SHELLDLL_DefView");
const static PTCHAR CLASS_NAME_SYSLIST = TEXT("SysListView32");
const static PTCHAR CLASS_NAME_WORKERW = TEXT("WorkerW");


//GetDesktopWindow取得的窗口是绝对的父亲,在spy++中所有窗口都是它的子孙,
//由Windows环境子系统进程CSRSS.exe创建。窗口类名#32769


//任务栏
HWND GetTaskmanWindow()
{
return FindWindow(CLASS_NAME_TASKMAN, NULL);
}


//GetShellWindow(),取得的窗口是个顶层窗口,由explorer.exe创建。窗口类名Progman。
//如果没有外壳进程存在,这个函数返回NULL。
HWND GetProgmanWindow()
{
//return FindWindow(CLASS_NAME_PROGMAN, NULL);
return ::GetShellWindow();
}


//菜单层
HWND GetShellViewWindow()
{
HWND hProgmanWindow = GetProgmanWindow();
HWND hShellWindow = NULL;
HWND hWorkerW = NULL;


hShellWindow = FindWindowEx(hProgmanWindow, NULL, CLASS_NAME_SHELL, NULL);
if(hShellWindow)
{
return hShellWindow;
}


while(!hShellWindow)
{
hWorkerW = FindWindowEx(NULL, hWorkerW, CLASS_NAME_WORKERW, NULL);
if(!hWorkerW)
break;
hShellWindow = FindWindowEx(hWorkerW, NULL, CLASS_NAME_SHELL, NULL);
}
return hShellWindow;
}


//图标层
HWND GetSysListWindow()
{
return FindWindowEx(GetShellViewWindow(), NULL, CLASS_NAME_SYSLIST, NULL);
}


//获得动态壁纸层
//这个会返回false,因为win8的桌面层次不稳定
//纯色 xp结构
//普通  Progman
//    WorkerW\SHELLDLL_DefView\SysListView32
//Win8.1在幻灯片模式下,才有这个动态壁纸层
HWND GetDesktopWallpaperWindow()
{
    HWND hProgmanWindow = GetProgmanWindow();
    HWND hWorkerW = FindWindow(CLASS_NAME_WORKERW, NULL);
    while(hWorkerW)
    {
        if(GetParent(hWorkerW) == hProgmanWindow)
            break;
        hWorkerW = FindWindowEx(NULL, hWorkerW, CLASS_NAME_WORKERW, NULL);
    }


    return hWorkerW;
}
#endif //SHELLWINDOW_H_20150212122316

文章发布于 2015-02-16 00:56:44 CSDN,现转博客园。