如何取得另一程序EDIT输入框的内容,请富翁赐教。。 (100分)

  • 主题发起人 主题发起人 yexiaoming
  • 开始时间 开始时间
Y

yexiaoming

Unregistered / Unconfirmed
GUEST, unregistred user!
注:[red]目标程序是另一程序[/red]<br>查找论坛的资料一般都是如下的程序段,但我的目标程序中有很多EDIT框,如何取得指定<br>的EDIT框的内容或者遍历所有的输入框呢?主要是如何取得多个不同EDIT的handle<br><br>设A窗口句柄为ahandle<br>程序如下:<br>var str:pchar;<br>hedit:hwnd;<br>begin<br>hedit:=findwindowex(ahandle,0,'tedit',nil);//取得A窗口下文本框的句柄,类型为tedit<br>getmem(str,255);//分配内存<br>getwindowtext(hedit,str,255);//取得内容<br>label1.caption:=strpas(str);//内容显示在label1中<br>FREEMEM(str);//释放内存<br>设置内容为<br>SendMessage(hedit, WM_SETTEXT,4//长度, LPARAM(pchar("good")));
 
遍历所有的edit<br>for i:=0 to Form2.ComponentCount-1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if uppercase(form2.Components.ClassName)='TEDIT' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showmessage('是edit编辑框')<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else showmessage(form2.Components.Name);<br>&nbsp; &nbsp; end;
 
以前的小程序,用这个回调API(EnumChildWindows)可以解决你的问题:<br>下面是小例子:<br>function GetCtrlHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>var<br>&nbsp; Buffer : array [0..255] of Char;<br>&nbsp; Buffer1: array [0..255] of Char;<br>&nbsp; Buffer2: array [0..255] of Char;<br>begin<br>&nbsp; Result := true;<br>&nbsp; GetClassName(hwnd,Buffer,256);<br>&nbsp; GetWindowText(hwnd,Buffer1,100);<br>&nbsp; if StrPas(Buffer) = 'Edit' then<br>&nbsp; &nbsp; LastEditHandle := hwnd;<br>&nbsp; if StrPas(Buffer) = 'TFlatButton' then<br>&nbsp; Begin<br>&nbsp; &nbsp; GetWindowText(hwnd,Buffer2,100);<br>&nbsp; &nbsp; if Buffer2 = '发言(&amp;S)' then<br>&nbsp; &nbsp; &nbsp; SendHandle := hwnd;<br>&nbsp; end;<br>&nbsp; PInteger(lparam)^ := hwnd;<br>&nbsp; if Trim(StrPas(Buffer)) = '' then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := false;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; form1.Show(IntToStr(hwnd),StrPas(Buffer1),StrPas(Buffer));<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; Button1.Enabled := false;<br>// &nbsp;WinHandle := FindWindow(nil,'幻灵游侠 beta 测试版');<br>// &nbsp; &nbsp;WinHandle := FindWindow(nil,'幻灵游侠');<br>&nbsp; WinHandle := FindWindow(nil,'聊天');<br>&nbsp; if WinHandle = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('没有打开幻灵吧?找不到这个窗体');<br>&nbsp; &nbsp; Button1.Enabled := true;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; List1.Clear;<br>&nbsp; whichList := 1;<br>&nbsp; EnumChildWindows(WinHandle,@GetCtrlHandle,Integer(@WinHandle));<br>&nbsp; Button1.Enabled := true;<br>end;
 
得到光标指向的输入框的文本值<br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var p:TPoint;<br>&nbsp; &nbsp; hWnd:integer;<br>&nbsp; &nbsp; buf:array[0..1023] of char;<br>begin<br>&nbsp; GetCursorPos(p);<br>&nbsp; hWnd:=WindowFromPoint(p);<br>&nbsp; if hWnd&lt;&gt;0 then<br>&nbsp; &nbsp;SendMessage(hWnd,WM_GETTEXT,1023,Integer(@buf[0]));<br>&nbsp; edit3.Text:=GetPass;<br>&nbsp; end;<br>end;<br>
 
用"getwindowtextlength"和"getwindowtext"可以取得别的程序窗口中如:“button”和<br>“label”中的caption内容,但是如果用它取得别的程序中"edit"中的内容时,确显示为空<br>,(但是,如果edit是本程序中的edit就可以取得它的text)。<br>是什么原因?<br>怎么解决?谢谢!
 
这个不会,关注
 
多人接受答案了。
 
后退
顶部