递归方式+FindWindow 遍历窗口句柄。查找已知句柄下的所有句柄。按节点方式保存

//使用软件为C++builder

GW_CHILD GW_HWNDNEXT
//int HandCount 定义的全局变量
//HWND Handled[1024]    //定义的全局变量
//DebugInfo(AnsiString str) //自定义的字符串显示函数

//递归函数
void __fastcall TForm1::Gethh(HWND hendle)
{
        HWND Group[1024];
        HWND hh = GetWindow(hendle,GW_CHILD);
        int count = 0;
        if(hh != NULL)
        {
          int i=0;                    
          Group[i] = hh;
          do
          {
            Handled[HandCount++] = Group[i];
            Group[i+1] = GetWindow(Group[i],GW_HWNDNEXT);
            DebugInfo("Group["+AnsiString(i)+"] Hendle is 0x"+IntToHex((__int32)Group[i],8));
            count = i+1;
          }while(i++,NULL != Group[i]);
        }
        else        为了区别分支点,用以下隔开
        {
          Handled[HandCount++] = NULL;  //为了区别分支点,用NULL隔开
          DebugInfo("");        
        }
        for(int j=0;j
    
    
     
     Lines->Add("Handled["+AnsiString(i)+"] is 0x"+IntToHex((__int32)Handled[i],8));
        }
}
//---------------------------------------------------------------------------

    
    

GW_CHILD GW_HWNDNEXT
//int HandCount 定义的全局变量
//HWND Handled[1024]    //定义的全局变量
//DebugInfo(AnsiString str) //自定义的字符串显示函数
//递归函数
void __fastcall TForm1::Gethh(HWND hendle)
{
        HWND Group[1024];
        HWND hh = GetWindow(hendle,GW_CHILD);
        int count = 0;
        if(hh != NULL)
        {
          int i=0;                   
          Group[i] = hh;
          do
          {
            Handled[HandCount++] = Group[i];
            Group[i+1] = GetWindow(Group[i],GW_HWNDNEXT);
            DebugInfo("Group["+AnsiString(i)+"] Hendle is 0x"+IntToHex((__int32)Group[i],8));
            count = i+1;
          }while(i++,NULL != Group[i]);
        }
        else        为了区别分支点,用以下隔开
        {
          Handled[HandCount++] = NULL;  //为了区别分支点,用NULL隔开
          DebugInfo("");       
        }
        for(int j=0;j<count;j++)
        {
          Gethh(Group[j]);
        }
}
void __fastcall TForm1::Button6Click(TObject *Sender)   //举例
{
        HandCount=0;    //初始化全局变量
        //HWND hh1 = FindWindowA("#32769 (??)",NULL);     //"Cypress USB Console");
        HWND hh1 = FindWindowA(NULL,"Cypress USB Console"); //获取一个窗口句柄
        Gethh(hh1); //调用递归函数得到所有句柄
        for(int i=0;i<HandCount;i++)
        {
          Report->Lines->Add("Handled["+AnsiString(i)+"] is 0x"+IntToHex((__int32)Handled[i],8));
        }
}
//---------------------------------------------------------------------------
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值