如何枚举窗体的所有控件。欢迎讨论。
a.exe 加载了 b.dll(a和b都是delphi所写,其中b.dll被加载后show出一个窗体,窗体上有若干控件,Label,button,textbox等),现在有什么办法能枚举b.dll窗体的所有控件。
[解决办法]
用FindWindow找窗体,用EnumChildWindows找控件
[解决办法]
DLL 可能不行,不过直接在 delphi 内部,查找所有一个窗口的控件还是可以的
var I : Integer ; tmpControl : TControl ; tmpAction : TAction ; tmpMenuItem : TMenuItem ; tmpComponent : TComponent ; tmpBarItem : TdxNavBarItem ;begin For I:=0 To sForm.ComponentCount-1 Do Begin tmpComponent := sForm.Components[I] ; If tmpComponent Is TAction Then Begin tmpAction := tmpComponent As TAction ; //..自己处理代码 End else If tmpComponent Is TControl Then Begin TmpControl := tmpComponent As TControl ; //..自己处理代码 end else If tmpComponent Is TMenuItem Then Begin TmpMenuItem := tmpComponent As TMenuItem ; //..自己处理代码 End else If tmpComponent Is [xxx] Then Begin End ; End ;
[解决办法]
b.dll 里面写一个方法 或者 回调才行..不然没办法直接枚举
sForm.ComponentCount
[解决办法]
sForm 是 self
[解决办法]
1楼的方法应该可行。
[解决办法]
写个回调函数:
function EnumChildWndProc(AhWnd:LongInt;AlParam:lParam):boolean;stdcall;
var
WndClassName: array[0..254] of Char;
WndCaption: array[0..254] of Char;
begin
GetClassName(AhWnd,wndClassName,254);//类名
sendmessage(AhWnd,wm_gettext,255,longint(@WndCaption));//标题
mainForm.Memo1.Lines.Add('ClassName:'+string(WndClassName)+';'+'Caption:'+string(WndCaption));
result:=true;
end;