其他程序的监控(200分)

  • 主题发起人 主题发起人 HowCan
  • 开始时间 开始时间
H

HowCan

Unregistered / Unconfirmed
GUEST, unregistred user!
请问,如何监控其他程序指定的文本框的数据,就是其他程序运行时,我自己的程序在后台始终在监控,因为有多个,所以有点麻烦,因为网上的只能监控到第一个文本框,比如以下代码:<br>function GetLocalTextInfoTest(var ReturnEditHandle:Integer):String;<br>var AHandle, BHandle: Integer;<br> &nbsp; &nbsp;R:Boolean;<br> &nbsp; &nbsp;mbuffer: array[0..255] of Char;<br> &nbsp; &nbsp;ss:string; &nbsp;<br> &nbsp;function GetComponentHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br> &nbsp;var s,sssss:string;<br> &nbsp; &nbsp; &nbsp;i,j:integer;<br> &nbsp; &nbsp; &nbsp;buffer: array[0..255] of Char; <br> &nbsp;begin<br> &nbsp; &nbsp;j:=0;i:=22;<br> &nbsp; &nbsp;if DebugState then sssss:=Uppercase('.SCROLLBAR.')//'TEDIT'<br> &nbsp; &nbsp;else sssss:='.EDIT.';<br> &nbsp; &nbsp;Result := True;<br> &nbsp; &nbsp;//得到目标窗口的控件<br> &nbsp; &nbsp;j:=GetClassName(hwnd, buffer, 256);<br> &nbsp; &nbsp;//找到目标窗口的TButton类目标控件<br> &nbsp; &nbsp;s:=StrPas(Buffer);<br> &nbsp; &nbsp;if Pos(sssss,uppercase(s))&gt;0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)<br> &nbsp; &nbsp; &nbsp;Result:=False; &nbsp;//终止循环<br> &nbsp; &nbsp;end;<br> &nbsp;end; &nbsp; <br>begin<br> &nbsp;//取句柄<br> &nbsp;AHandle := FindWindow(nil, 'LabelPrint'); &nbsp;//就是窗口的Caption<br> &nbsp;//AHandle := FindWindow(nil, 其他系统'); &nbsp; //就是窗口的Caption<br> &nbsp;if AHandle&lt;&gt;0 then<br> &nbsp;begin<br> &nbsp; &nbsp;//在这里循环取到想要的句柄为止<br> &nbsp; &nbsp;R:=EnumChildWindows(AHandle, @GetComponentHandle, Integer(@BHandle));<br> &nbsp; &nbsp;if not R then begin<br> &nbsp; &nbsp; &nbsp;ReturnEditHandle:=BHandle;<br> &nbsp; &nbsp; &nbsp;SendMessage(BHandle,WM_GETTEXT,254,Integer(@mbuffer));<br> &nbsp; &nbsp; &nbsp;//GetWindowText(BHandle, mbuffer, 100);<br> &nbsp; &nbsp; &nbsp;ss:=StrPas(mBuffer);<br> &nbsp; &nbsp; &nbsp;Result:=ss;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;
 
为什么只能监控到一个文本框哦?你首先把其他程序窗体上的edit控件的句柄获取到,然后就轮循的发消息获取就是了啊,既然可以得到一个,那多个肯定没有问题嘛.
 
可以到这里来看看http://www.feiyang.net.cn/index.htm
 
好象有人提过,找找看
 
只要加上{$WRITEABLECONST ON}开关,然后加一个循环遍历一下就好了,刚好有一点经验,只是有点笨:<br>function GetLocalTextInfoTest(var ReturnEditHandle:Integer):String;<br>var AHandle, BHandle: Integer;<br> &nbsp; &nbsp;R:Boolean;<br> &nbsp; &nbsp;mbuffer: array[0..255] of Char;<br> &nbsp; &nbsp;ss:string; &nbsp;<br>{$WRITEABLECONST ON}<br> &nbsp;function GetComponentHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br> &nbsp;var s,sssss:string;<br> &nbsp; &nbsp; &nbsp;i,j,iStep:integer;<br> &nbsp; &nbsp; &nbsp;buffer: array[0..255] of Char; <br> &nbsp;const<br> &nbsp; &nbsp; &nbsp;jsq: Integer = 0;<br> &nbsp;begin<br> &nbsp; &nbsp;j:=0;i:=22;<br> &nbsp; &nbsp;iStep:=10; &nbsp;//这个数字你需要自己调整,一遍遍的试<br> &nbsp; &nbsp;if DebugState then sssss:=Uppercase('.SCROLLBAR.')//'TEDIT'<br> &nbsp; &nbsp;else sssss:='.EDIT.';<br> &nbsp; &nbsp;Result := True;<br> &nbsp; &nbsp;//得到目标窗口的控件<br> &nbsp; &nbsp;j:=GetClassName(hwnd, buffer, 256);<br> &nbsp; &nbsp;//找到目标窗口的TButton类目标控件<br> &nbsp; &nbsp;s:=StrPas(Buffer);<br> &nbsp; &nbsp;if Pos(sssss,uppercase(s))&gt;0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;if DebugState then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;inc(jsq);<br> &nbsp; &nbsp; &nbsp; &nbsp;if jsq=iStep then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;jsq:=0;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result:=False; &nbsp;//终止循环<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end else begin<br> &nbsp; &nbsp; &nbsp;PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)<br> &nbsp; &nbsp; &nbsp;Result:=False; &nbsp;//终止循环<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp;end; <br>{$WRITEABLECONST OFF} &nbsp;<br>begin<br> &nbsp;//取句柄<br> &nbsp;AHandle := FindWindow(nil, 'LabelPrint'); &nbsp;//就是窗口的Caption<br> &nbsp;//AHandle := FindWindow(nil, 其他系统'); &nbsp; //就是窗口的Caption<br> &nbsp;if AHandle&lt;&gt;0 then<br> &nbsp;begin<br> &nbsp; &nbsp;//在这里循环取到想要的句柄为止<br> &nbsp; &nbsp;R:=EnumChildWindows(AHandle, @GetComponentHandle, Integer(@BHandle));<br> &nbsp; &nbsp;if not R then begin<br> &nbsp; &nbsp; &nbsp;ReturnEditHandle:=BHandle;<br> &nbsp; &nbsp; &nbsp;SendMessage(BHandle,WM_GETTEXT,254,Integer(@mbuffer));<br> &nbsp; &nbsp; &nbsp;//GetWindowText(BHandle, mbuffer, 100);<br> &nbsp; &nbsp; &nbsp;ss:=StrPas(mBuffer);<br> &nbsp; &nbsp; &nbsp;Result:=ss;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;
 
delphi_delphi,为什么你给的网址有病毒?太哪个什么了吧!
 
谢谢dey-999的奇特代码,也谢谢cqwty了,至于delphi_delphi,麻烦你杀一下毒.
 
后退
顶部