下面这段代码在nt4上可以完全执行.但是在windows2000下抓取不到密码框内的内容 (100分)

  • 主题发起人 主题发起人 ajim
  • 开始时间 开始时间
A

ajim

Unregistered / Unconfirmed
GUEST, unregistred user!
原标题如下,为问问题我更改了标题:<br>为什么我的hook只能得到自己程序的标题?请给出解决方法.我不太了解windowsapi<br>希望高手能指点迷津.请不要告诉我用dll.我希望他能编译成一个文件<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, ExtCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; Edit2: TEdit;<br><br><br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; function GetText(H:HWND):string;<br>&nbsp; &nbsp; &nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>function tform1.GetText(H:HWND):string;<br>var<br>&nbsp; Text:Array[0..254] of char;<br>begin<br>&nbsp; GetWindowText(H,Text,255);<br>&nbsp; Result:=StrPas(Text);<br>end;<br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>H:HWND;<br>begin<br>h:=GetActiveWindow();<br>edit1.Text:=inttostr(h);<br>edit2.text:=gettext(h);<br>end;<br><br>end.<br>
 
GetActiveWindow是用来获得活动窗口的句柄的API,你的窗口是当前窗口,那就返回当前窗口<br>的句柄了!不知道你得到什么窗口的句柄,你可以用EnumWindows试试吧,它是用来枚举窗口列<br>表中的所有父窗口(顶级和所有窗口)。
 
这好像不叫HOOK吧。<br>你程序应该用EnumWindows或是FindWindowEx.
 
to 晶晶<br>当我激活其他窗口时.他显示id为0 这是为什么
 
id为0:如没有窗口处于活动状态,GetActiveWindow()返回零值;<br>GetActiveWindow对于桌面上其他的活动窗口是没有用的,至少我这么认为,GetActiveWindow<br>可以得到这个程序当前窗口的ID<br>
 
to晶晶,<br>你的说话不对<br>我看过其他demo<br>好好的在用呀
 
我自己解决了问题.但是又遇到了新的.下面这段代码在nt4上可以完全执行.但是在windows2000下抓取不到密码框内的内容<br>请高人看看看那里写错了<br>unit good;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ExtCtrls, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; &nbsp;hEdit : THandle;<br>implementation<br><br>{$R *.DFM}<br>&nbsp;function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean; stdcall;<br>//得到窗口(是一个MDIChild类型)中每个控件的 Text 内容(TEdit,TMaskEdit...),成功了。<br>var<br>&nbsp; buffer: array[0..255] of char;<br>&nbsp; s: string;<br>begin<br>&nbsp; Result := True;<br>&nbsp; GetClassName(hwnd, buffer, 256);<br>&nbsp; s := STRPAS(BUFFER);<br>&nbsp; if ((s &lt;&gt; 'TStaticText') and (s &lt;&gt; 'TGroupBox') and (s &lt;&gt; 'TPanel') and (s &lt;&gt; 'TStatusBar') and (s &lt;&gt; 'TButton')<br>&nbsp; &nbsp; &nbsp; &nbsp;and (s &lt;&gt; 'TBitBtn') and (s &lt;&gt; 'MDIClient') and (s &lt;&gt; 'TWjfDBGrid')) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; SetLength(s, 256);<br>&nbsp; &nbsp; &nbsp; SendMessage(hwnd, WM_GETTEXT, 256, LongInt(S));<br>&nbsp; &nbsp; &nbsp; form1.memo1.Lines.Add(s);<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; cursorpoint:TagPOINT;<br>&nbsp; windowhandle:hwnd;<br>&nbsp; textmaxlength:integer;<br>&nbsp; textcontent:array[0..100] of char;<br>&nbsp; returnlength:word;<br>begin<br>&nbsp; textmaxlength:=100;<br>&nbsp; Memo1.lines.clear;<br>&nbsp; if GetCursorPos(cursorpoint) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Memo1.Lines.Add(format('光标位置x=%d,y=%d',[cursorpoint.x,cursorpoint.y]));<br>&nbsp; &nbsp; &nbsp; windowhandle:=windowfrompoint(cursorpoint);<br>&nbsp; &nbsp; &nbsp; if windowhandle&lt;&gt;null then<br>&nbsp; &nbsp; &nbsp; &nbsp; Memo1.Lines.Add(format('光标处窗口名柄号为%d',[windowhandle]));<br>&nbsp; &nbsp; &nbsp; if iswindow(windowhandle) then<br>&nbsp; &nbsp; &nbsp; &nbsp; returnlength:=SendMessage(windowhandle,WM_GETTEXT,textmaxlength,lparam(@textcontent));<br>&nbsp; &nbsp; &nbsp; if returnlength&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Memo1.Lines.Add('读到窗口标题为:');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Memo1.Lines.Add(textcontent);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; EnumChildWindows(windowhandle, @EnumChildWindowsProc,0);<br>&nbsp; &nbsp; end;<br>end;<br><br><br><br>end.
 
returnlength:=SendMessage(windowhandle,WM_GETTEXT,textmaxlength,lparam(@textcontent));<br>改成<br>returnlength:=PostMessage(windowhandle,WM_GETTEXT,textmaxlength,lparam(@textcontent));
 
噢,错了,需要加一个post,呵呵。
 
在那句以前加入<br>&nbsp; &nbsp; PostMessage(windowhandle, EM_SETPASSWORDCHAR, longint(0), 0)<br>以后加入<br>&nbsp; &nbsp; &nbsp; PostMessage(hwnd, EM_SETPASSWORDCHAR, longint('*'), 0);<br>
 
有用吗?难道不需要进程介入?
 
Windows Team已经作出修改,获得密码只能由创建该窗口的代码完成。<br>你不要白费力气了。
 
可以获得的,同时可以显示出来的,xp下面都可以。
 
to yzhshi:<br>我好崇拜你。问一下 这个方法是你自己相处来的吗??
 
接受答案了.
 
呵呵,都是慢慢积攒起来的,以前也是不会呀,后来讨论问题的时候,别人粘贴上来的,我就学会了。就是这样。<br>知识是不断积累起来的。<br>要学会积攒知识!
 
后退
顶部