--Aweay的代碼:
int WndCount=0;
String GetWndClass(HWND hwnd);
HWND parentwnd=NULL;
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam) //其實這就是核心的部分
//構造TreeView樹
{
TTreeNode* parentnode=(TTreeNode*)lParam;
HWND pawnd=parentnode-> Data;
if(GetParent(hwnd)==pawnd) //關鍵在這裡,表單的父必須是直系(這一句話真是太關鍵了,點醒了我,向Aweay致敬)
{
WndCount++;
TTreeNode* node=frmnet-> treeWnd-> Items-> AddChildObject(parentnode,GetWndClass(hwnd),hwnd);
node-> ImageIndex=0;
node-> StateIndex=0;
EnumChildWindows(hwnd,(WNDENUMPROC)EnumChildProc,(LPARAM)node);
}
return true;
}
void __fastcall Tfrmnet::GetChildWnd(HWND hwnd)
{
//TODO: Add your source code here
treeWnd-> Items-> BeginUpdate();
treeWnd-> Items-> Clear();
treeWnd-> Items-> EndUpdate();
WndCount=0;
TTreeNode* node=treeWnd-> Items-> AddObject(NULL,GetWndClass(hwnd),hwnd);
EnumChildWindows(hwnd,(WNDENUMPROC)EnumChildProc,(LPARAM)node);
treeWnd-> FullExpand();
sbmain-> SimpleText=String(WndCount)+ " Child Window[s] ";
}