////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;jLines->Add("Handled["+AnsiString(i)+"] is 0x"+IntToHex((__int32)Handled[i],8));
}
}
//---------------------------------------------------------------------------
//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]);
}
}
{
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));
}
}
//---------------------------------------------------------------------------