关于监视指定程序(无源代码)某个窗口几个控件中的内容(100分)

  • 主题发起人 主题发起人 shaken
  • 开始时间 开始时间
S

shaken

Unregistered / Unconfirmed
GUEST, unregistred user!
当在该部分控件输入任何数字时都可以弹出窗口提示该控件的内容。最好有源代码!谢谢!
 
即哪个控件获得焦点时,给予提示,失去焦点时,给予输入的内容提示。
 
好像每个控件都是有一个HANDLE的吧
 
但是每次的handle都不同,并且程序的几个控件都没有caption的。<br>哪位高手帮我解决这个问题,给分500。
 
那要看你要监视的控件是哪一类的,如果有hanlde则可以做到,如果没有handle则做不到的
 
有handle的[:(]
 
获取编辑框中显示出来的字符<br>function EditVisibleText(mEdit: TEdit): string;<br>var<br>&nbsp; X, Y, L: Integer;<br>&nbsp; S: string;<br>begin<br>&nbsp; result := '';<br>&nbsp; if not Assigned(mEdit) then Exit;<br>&nbsp; with mEdit do try<br>&nbsp; &nbsp; S := Text;<br>&nbsp; &nbsp; L := Length(S);<br>&nbsp; &nbsp; X := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(2, 2));<br>&nbsp; &nbsp; X := X and $0000FFFF;<br>&nbsp; &nbsp; Y := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(ClientWidth - 4, 2));<br>&nbsp; &nbsp; Y := Y and $0000FFFF;<br>&nbsp; &nbsp; for X := X to Y - 1 do if (Y &gt;= 0) and (X &lt; L) then<br>&nbsp; &nbsp; &nbsp; result := result + S[X + 1];<br>&nbsp; except<br>&nbsp; &nbsp; result := '';<br>&nbsp; end;<br>end; { EditVisibleText }<br><br><br><br>function MemoVisibleText(mMem TMemo; mStrings: TStrings): Boolean;<br>var<br>&nbsp; I, X, Y: Integer;<br>&nbsp; L, H, W: Integer;<br>&nbsp; S: string;<br>&nbsp; T: string;<br>begin<br>&nbsp; result := False;<br>&nbsp; if (not Assigned(mMemo)) or (not Assigned(mStrings)) then Exit;<br>&nbsp; with TControlCanvas.Create do try<br>&nbsp; &nbsp; Control := mMemo;<br>&nbsp; &nbsp; H := TextHeight('|');<br>&nbsp; finally<br>&nbsp; &nbsp; Free;<br>&nbsp; end;<br>&nbsp; mStrings.Clear;<br>&nbsp; with mMemo do try<br>&nbsp; &nbsp; S := Text;<br>&nbsp; &nbsp; L := Length(S);<br>&nbsp; &nbsp; W := ClientWidth;<br>&nbsp; &nbsp; for I := 0 to (ClientHeight div H) - 1 do begin<br>&nbsp; &nbsp; &nbsp; X := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(3, I * H + 2));<br>&nbsp; &nbsp; &nbsp; X := X and $0000FFFF;<br>&nbsp; &nbsp; &nbsp; Y := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(5, I * H + 2));<br>&nbsp; &nbsp; &nbsp; Y := Y and $0000FFFF;<br>&nbsp; &nbsp; &nbsp; if Abs(Y - X) &gt; 1 then Inc(X);<br>&nbsp; &nbsp; &nbsp; if not ((X = 0) or ((X &lt; L) and (S[X - 1] in [#13, #10]))) then Inc(X);<br>&nbsp; &nbsp; &nbsp; Y := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(W - 2, I * H + 2));<br>&nbsp; &nbsp; &nbsp; Y := Y and $0000FFFF;<br>&nbsp; &nbsp; &nbsp; T := '';<br>&nbsp; &nbsp; &nbsp; for X := X to Y - 1 do if (Y &gt;= 0) and (X &lt; L) then<br>&nbsp; &nbsp; &nbsp; &nbsp; T := T + S[X + 1];<br>&nbsp; &nbsp; &nbsp; mStrings.Add(T);<br>&nbsp; &nbsp; end;<br>&nbsp; except<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; result := True;<br>end; { MemoVisibleText }<br>////////end Source<br><br><br><br>////////begin Demo<br><br><br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; MemoVisibleText(Memo1, Memo2.Lines);<br>end;<br><br><br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; Caption := EditVisibleText(Edit1);<br>end;<br>////////end Demo<br><br>
 
可以用WH_CBT类型的钩子解决<br>控件失去焦点时,控件的文本(在这里可以通过GetClassName只判断具有文本的控件)<br>或标题会被记录到文件中<br>控件失去焦点时,不知你需要者样的提示,hwnd(wparam)是得到焦点得控件的句柄<br>unit Unit1;<br><br>interface<br>uses<br>&nbsp; SysUtils,Classes,Windows,Messages,Forms;<br><br><br>function HookProc(ncode:integer;wparam:wparam;lparam:lparam):LRESULT;stdcall;<br>procedure EnableHook;stdcall;export;<br>procedure DisableHook;stdcall;export;<br><br>var hhk:Cardinal; &nbsp; &nbsp;<br>implementation<br><br>function HookProc(ncode:integer;wparam:wparam;lparam:lparam):LRESULT;stdcall;<br>var<br>&nbsp; &nbsp; buffer:pchar;<br>&nbsp; &nbsp; tf:textfile;<br>begin<br>&nbsp; &nbsp; &nbsp;if ncode=HCBT_SETFOCUS then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; GetMem(buffer,64);<br>&nbsp; &nbsp; &nbsp; &nbsp; sendmessage(hwnd(lparam),WM_GETTEXT,64,integer(buffer));<br><br>&nbsp; &nbsp; &nbsp; &nbsp; assignfile(tf,'e:/debug.txt');<br>&nbsp; &nbsp; &nbsp; &nbsp; if not fileexists('e:/debug.txt') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rewrite(tf)<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;append(tf);<br>&nbsp; &nbsp; &nbsp; &nbsp; writeln(tf,'Control Lost Focus,Text:'+buffer);<br>&nbsp; &nbsp; &nbsp; &nbsp; closefile(tf);<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;result:=0;<br>end;<br><br>procedure EnableHook;stdcall;export;<br>var hwnd,ThreadID:Cardinal;<br>begin<br>&nbsp; &nbsp; &nbsp;hwnd:=Findwindow(nil,'Form_Server');<br>&nbsp; &nbsp; &nbsp;ThreadID:=GetWindowThreadProcessId(hwnd,nil);<br>&nbsp; &nbsp; &nbsp;if hhk=0 then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; hhk:=SetWindowsHookEx(WH_CBT,@HookProc,hinstance,ThreadID);<br>&nbsp; &nbsp; &nbsp;end;<br>end;<br><br>procedure DisableHook;stdcall;export;<br>begin<br>&nbsp; &nbsp; &nbsp;if hhk&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; UnHookWindowsHookEx(hhk);<br>&nbsp; &nbsp; &nbsp; &nbsp; hhk:=0;<br>&nbsp; &nbsp; &nbsp;end;<br><br>end;<br><br>end.<br>&nbsp;
 
使用勾子。
 
后退
顶部