我的到一个窗体的句柄 怎样遍历该窗体的控件
或怎样得到另一个窗体上Edit文本框中的内容

解决方案 »

  1.   

    先用 FindControl 得到該窗口的實例, 強制轉為TForm, 然後, 就可用
    Form.ComponentCount;
    Components[i]
    來查詢得到你想要的!
      

  2.   

    我想遍历其他程序窗体上的控件procedure TForm1.Button2Click(Sender: TObject);
    var
      hParent: HWND;
      i:integer;
    begin
      hParent := FindWindow(nil, 'MyForm');
      for i:=0 to TForm(hParent).ControlCount-1 do
        if TForm(hParent).Controls[i] is TEdit then
      memo1.Lines.Add(TEdit(TForm(hParent).Controls[i]).Text);
    end;不行耶????
      

  3.   

    var
      TheForm: TForm;
      TheEditText: string;
    begin
      TheForm := FindControl(Handle: HWnd): TWinControl;
      for i := 0 to TheForm.ComponentCount do
      begin
        if TheForm.Components[i] is TEdit then //是EDIT
        begin
          TheEditText := TEdit(TheForm.Components[i]).Text;  //得到内容
        end;
      end;
      

  4.   

    TForm(hParent) 就有問題了, 你實際運行試試
      

  5.   

    //×××好像有问题耶×××
    var
      TheForm: TForm;
      TheEditText: string;
    begin
      TheForm := FindControl(Handle: HWnd): TWinControl;  //×××好像有问题耶×××
      for i := 0 to TheForm.ComponentCount do
      begin
        if TheForm.Components[i] is TEdit then //是EDIT
        begin
          TheEditText := TEdit(TheForm.Components[i]).Text;  //得到内容
        end;
      end;
      

  6.   

    大家注意一下,你们可能没看清楼主的意思,要遍历的窗体对我们的程序来说是不可见的(不能直接访问其内存),对吧,楼主?
    var
    hCurrentWindow:HWND;
    szText: array[0..255] of char;
    buffer: array[0..255] of char;
    begin
    hCurrentWindow := GetWindow(yourHandle, GW_HWNDFIRST);//yourhandle 你得到的窗体句柄
      while hCurrentWindow <> 0 do
      begin
        GetClassName(hCurrentWindow, @szText, 255);
        if Strpas(@szText) = 'TEdit' then
        begin
          GetWindowText(hCurrentWindow, @szText, 255);
           EnumChildWindows(hCurrentWindow,@EnumChildWindowsProc,Integer(@buffer[0]));
           showmessage(StrPas(buffer));
        end;
        hCurrentWindow:=GetWindow(hCurrentWindow,GW_HWNDNEXT);
      end;
    end;
    方案绝对可行,你自己调试一下。