查找窗口句柄

这段代码展示了如何遍历查找Windows子窗口的句柄,从桌面窗口开始,递归获取每个子窗口的文本和类名,并将这些信息写入日志文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值