查找窗口句柄

来源:互联网 发布:陕西软件行业天网 编辑:程序博客网 时间:2024/05/16 05:54
wchar_t buf[MAX_SIZE];
HWND pParent =  ::GetDesktopWindow(); //(HWND)0x001205A8;
HWND pchild = ::GetWindow(pParent,GW_CHILD);
bool b = false;

while (IsWindow(pchild))
{
::GetWindowText(pchild,buf,MAX_SIZE);

if (pchild)
{
if (wcscmp(_T("multiple"),buf) == 0)
{
pchild = ::GetWindow(pchild,GW_CHILD);
m_Dis += buf;


::GetClassName(pchild,buf,MAX_SIZE);
m_className += buf;


b = true;
continue;
}

}

if (b)
{
m_Dis += buf;


::GetClassName(pchild,buf,MAX_SIZE);
m_className += buf;
}






pchild = ::GetWindow(pchild,GW_HWNDNEXT);



}




void TraversalHnadleOfWindow(const wchar_t *pName)
{

HWND pParent =  (HWND)0x000709EE;//::GetDesktopWindow(); 
CString strlog;
SearchHandl(strlog,pParent);
}


static void SearchHandl(CString &strlog,HWND hchild)
{
if (!hchild) return;


hchild = ::GetWindow(hchild,GW_CHILD);

SearchHandl(strlog,hchild);


wchar_t buf[MAX_PATH];
const wchar_t Log[] = L"E:\\findcon.txt";
WriteLog(xu::CStrToStr(Log).c_str(),"--------------level--------------\n",true);


while (::IsWindow(hchild)){
::GetWindowText(hchild,buf,MAX_PATH);
strlog = "cText: ";
strlog += buf;
::GetClassName(hchild,buf,MAX_PATH);
strlog += " cName: ";
strlog += buf;
strlog += "\n";
WriteLog(xu::CStrToStr(Log).c_str(),xu::CStrToStr(strlog).c_str(),true);
hchild = ::GetWindow(hchild,GW_HWNDNEXT);
}
}