怎样才能得到EDIT控件的句柄?(80分)

  • 主题发起人 主题发起人 luyaong
  • 开始时间 开始时间
L

luyaong

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟有个想法,做个得到QQ密码的东西,当“OICQ用户登录”窗口出现就<br>用sendmessage发送wm_gettext消息,得到EDIT中的密码但前提是要如何<br>得到EDIT密码框的句柄?还有一问题,发送wm_gettext消息的时机,是拦截<br>“OICQ用户登录”窗口关闭消息好还是拦截“确定”按钮按下的消息好?
 
GetCursorPos<br>另外推销:[:)]<br>delphi.mychangshu.com<br>里面其他内我写的一个小软件,显示密码的,带源代码,现在好像稍微有点问题,服务器联不上了?<br>
 
edit1.Handle, &nbsp;通过EDIT的属性Handle可以得到。
 
这样来!可以得到所有窗口和控件的句柄,其余的你自己去做了。<br><br>procedure TForm1.GetMousePosHwndAndClassName(Sender: TPoint);<br>var<br>&nbsp; hWnd: THandle;<br>&nbsp; aName: array [0..255] of char;<br>begin<br>&nbsp; hWnd := WindowFromPoint(Sender);<br>&nbsp; Label1.Caption := 'Handle : ' + IntToStr(hWnd);<br>&nbsp; if boolean(GetClassName(hWnd, aName, 256)) then<br>&nbsp; &nbsp; Label2.Caption := 'ClassName : ' + string(aName)<br>&nbsp; else<br>&nbsp; &nbsp; Label2.Caption := 'ClassName : not found';<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; Form1.FormStyle := fsStayOnTop;<br>&nbsp; Timer1.Interval := 50;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; rPos: TPoint;<br>begin<br>&nbsp; if boolean(GetCursorPos(rPos)) then<br>&nbsp; &nbsp; GetMousePosHwndAndClassName(rPos);<br>end;
 
yes,<br>edit.handle
 
procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; pos : TPoint;<br>&nbsp; GetEditHwnd : HWND;<br>begin<br>&nbsp; GetCursorPos(pos);<br>&nbsp; GetEditHwnd := WindowFromPoint(pos);//得到鼠标所在位置控件的句柄<br>&nbsp; if GetEditHwnd &gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; //你要写的代码在这里<br>&nbsp; &nbsp; end;<br>end;
 
完整解决方案,连Win2000下的密码都跑不掉.自己加上那几个控件.使用时拖拉lblChk这个<br>label就行了.<br>procedure TFrmAbout.lblChkMouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>begin<br>&nbsp; if (Button=mbLeft) and (ssLeft in Shift) then<br>&nbsp; begin<br>&nbsp; &nbsp; Screen.Cursor:=crDrag;<br>&nbsp; &nbsp; lblPass.Caption:='ready';<br>&nbsp; end;<br>end;<br><br>procedure TFrmAbout.lblChkMouseUp(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>begin<br>&nbsp; Screen.Cursor:=crDefault;<br>&nbsp; lblPass.caption:=GetPassword;<br>&nbsp; lblPass.Hint:=lblPass.Caption;<br>end;<br><br>function TFrmAbout.GetPassWord: string;<br>var p:TPoint;<br>&nbsp; &nbsp; hWnd,PassChar: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; begin<br>&nbsp; &nbsp; PassChar:=SendMessage(hWnd,EM_GetPasswordChar,0,0);<br>&nbsp; &nbsp; if PassChar&lt;&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; PostMessage(hWnd,EM_SetPasswordChar,0,0);<br>&nbsp; &nbsp; &nbsp; Sleep(50);<br>&nbsp; &nbsp; &nbsp; SendMessage(hWnd,WM_GetText,1023,Integer(@buf[0]));<br>&nbsp; &nbsp; &nbsp; SendMessage(hWnd,EM_SetPasswordChar,wparam(PassChar),0);<br>&nbsp; &nbsp; end else<br>&nbsp; &nbsp; &nbsp; SendMessage(hWnd,WM_GetText,1023,Integer(@buf[0]));<br>&nbsp; end;<br>&nbsp; Result:=string(Buf);<br>end;
 
可能我说得不太详细,我的意思是类似木马的东西,不能靠WindowFromPoint()得到<br>控件句柄,好象要用个啥function遍历窗口中包含的所有控件,但我不会用?
 
FindWindow or &nbsp;FindWindowEx(not Supported on Windows NT)
 
这是老贴子里的,但我试了,只能改变form的标题<br>procedure TForm1.Button1Click(Sender: TObject);<br>&nbsp;function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>&nbsp; var<br>&nbsp; &nbsp; buffer: array[0..255] of Char;<br>&nbsp; begin<br>&nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; //得到目标窗口的控件<br>&nbsp; &nbsp; GetClassName(hwnd,buffer,256);<br>&nbsp; &nbsp; //找到发消息的目标窗口的目标控件<br>&nbsp; &nbsp; if StrPas(Buffer)='TEdit' 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;<br>var<br>&nbsp; Handle: Integer;<br>&nbsp; buffer: Array[0..1023] of Char;<br>begin<br>&nbsp; Handle := FindWindow(nil,'另个窗口名'); &nbsp;//就是窗口的Caption<br>&nbsp; if Handle&lt;&gt;0 then<br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; EnumChildWindows(Handle,@EnumChildWindowsProc,Integer(@Handle));<br>&nbsp; &nbsp; &nbsp;//如果找到就是Handle,如果没找到Handle,还是窗口<br>&nbsp; &nbsp; &nbsp;//下面这句是测试<br>&nbsp; &nbsp; &nbsp; SendMessage(Handle,WM_SETTEXT,0,Integer(pchar('Your String')));<br>&nbsp; &nbsp; end;<br>end;<br>&nbsp;<br>
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部