|
发表于 2015-2-7 17:44:27
|
显示全部楼层
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{//枚举子窗口的回调函数
setlocale(LC_ALL,"chs");
count++;
TCHAR lpWinTitle[256],lpClassName[256];
::GetWindowTextW(hwnd,(LPWSTR)lpWinTitle,256-1); //获得窗口caption
::GetClassNameW(hwnd,(LPWSTR)lpClassName,256-1); //获得窗口类名
if (wcsicmp((LPWSTR)lpWinTitle,L"")!=NULL && wcsicmp((LPWSTR)lpClassName,L"")!=NULL) //过滤掉没有名子和类名的窗口
{
fwprintf(fp,_T("\n"));
for (int i=1;i<=count;i++) fprintf(fp," ");
fwprintf(fp,_T("-0xX:'%ws':'%ws'"),hwnd,lpWinTitle,lpClassName);
if(wcsicmp(lpClassName,L"SysListView32")==NULL)
ShowListView(hwnd);
EnumChildWindows(hwnd,EnumChildProc,0); //递归枚举子窗口
}
count--;
return TRUE ;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lparam)
{//枚举窗口的回调函数
setlocale(LC_ALL,"chs");
count = 1;
TCHAR lpWinTitle[256],lpClassName[256];
::GetWindowTextW(hwnd,lpWinTitle,256-1); //获得窗口caption
::GetClassNameW(hwnd,lpClassName,256-1); //获得窗口类名
if (wcsicmp(lpWinTitle,L"")!=NULL && wcsicmp(lpClassName,L"")!=NULL) //过滤掉没有名子和类名的窗口
{
fwprintf(fp,_T("\n*-0xX:'%ws':'%ws'"),hwnd,lpWinTitle,lpClassName);
EnumChildWindows(hwnd,EnumChildProc,0); //继续枚举子窗口,传递给回调函数该子窗口的句柄
}
return TRUE ;
}
int main()
{
setlocale(LC_ALL,"chs");
::EnumWindows(EnumWindowsProc,0); //枚举桌面的窗口,每找到一个窗口,调用一次回调函数,传递给回调函数该窗口的句柄
system("pause");
return 0;
}
|
|