a.exe 加载了 b.dll(a和b都是delphi所写,其中b.dll被加载后show出一个窗体,窗体上有若干控件,Label,button,textbox等),现在有什么办法能枚举b.dll窗体的所有控件。

解决方案 »

  1.   

    用FindWindow找窗体,用EnumChildWindows找控件
      

  2.   

    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 ;
      

  3.   

    b.dll 里面写一个方法 或者 回调才行..不然没办法直接枚举
    sForm.ComponentCount
      

  4.   

    写个回调函数:
    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;