另一个执行程序中有三个edit如何分别取出并确定是那一个

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit2: TEdit;
        Edit3: TEdit;
        Memo1: TMemo;
        Memo2: TMemo;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        
        function mygettext(hwnd:THandle):string;
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      cnt : Integer = 0;
      function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall;
      function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall;implementation{$R *.dfm}function TForm1.mygettext(hwnd:THandle):string;
    var
      buf:pchar;
      len:Longint;
    begin
     Len:=Longint(SendMessage(hWnd,WM_GETTEXTLENGTH ,0,0));
     if len>0 then
      begin//1
       try
        getmem(buf,len);
        SendMessage(hWnd,WM_GETTEXT,Len+1,Int64(buf));
        Result:=strpas(buf);
       finally
        freemem(buf);
       end;
      end;//1
    end;function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;
    var
     WindowCaption:array[0..254] of Char;
    begin
     GetWindowText(Hwnd,WindowCaption,255);
     Form1.Memo1.Lines.Add(WindowCaption);
     if StrPas(WindowCaption)='登入游戏' then
    // if StrPas(WindowCaption)='' then
     begin
       cnt := 0;
       EnumChildWindows(Hwnd,@EnumChildProc,0);
       Result := False;
       Exit;
     end;
     Result := True;
    end;function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;
    var
     WindowCaption,WindowClass:array[0..254] of Char;
    begin
     GetClassName(Hwnd,WindowClass,255);
     Form1.Memo2.Lines.Add(WindowClass);
     if Pos('EDIT',UpperCase(StrPas(WindowClass))) > 0 then
     begin
       Inc(cnt);
       SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(IntToStr(cnt))));
       if Form1.mygettext(Hwnd)='1' then
        begin//2
          SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(Form1.Edit3.Text)));
        end;//2
       if Form1.mygettext(Hwnd)='2' then
        begin//2
          SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(Form1.Edit2.Text)));
        end;//2
     end;
     Result := True;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    memo1.Clear ;
    memo2.Clear ;
    Enumwindows(@EnumWindowsProc,0);end;end.