如何找到焦点所在的控件的句柄(7分)

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

sy0116

Unregistered / Unconfirmed
GUEST, unregistred user!
如何找到焦点所在的控件的句柄?比如说目前焦点处于某程序的一个RICHEDIT上,按下热键之后自动找到这个RICHEDIT的句柄?我没分了
 
private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; procedure GetMousePosHwndAndClassName(Sender : TPoint);<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;<br>
 
鼠标不一定在要找的控件上
 
P:TPoint;<br>ChileHandle:THandle;<br><br>&nbsp; GetCursorPos(P);<br>&nbsp; ChildHandle:=WindowFromPoint(P);
 
楼上的能讲清楚一点吗
 
给我你的QQ号,我的304279282
 
我的77266693
 
这个问题很简单!
 
很简单是什么意思啊?到底该怎么办?
 
Form1.ActiveControl 指向的就是当前 FORM 上焦点所在的控件
 
要找的控件不在我自己的程序上,而是在其他的程序上
 
ActiveWindow是什么啊?
 
一个API而已 : getfocus,帖我以前写一程序部分代码出来:<br>&nbsp; &nbsp; &nbsp; f1,f2,f3:longint;<br>&nbsp; &nbsp; &nbsp; S:string;<br>&nbsp; &nbsp; &nbsp; S:='字';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //得到当前焦点控减句柄发消息<br>&nbsp; &nbsp; &nbsp; f1:=GetForegroundWindow;<br>&nbsp; &nbsp; &nbsp; f2:=GetWindowThreadProcessId(f1,nil);<br>&nbsp; &nbsp; &nbsp; AttachThreadInput(GetCurrentThreadId,f2,true);<br>&nbsp; &nbsp; &nbsp; f3:=getfocus;<br>&nbsp; &nbsp; &nbsp; AttachThreadInput(GetCurrentThreadId,f3,false);<br>&nbsp; &nbsp; &nbsp; if f3 = 0 then Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(f3, $0286,(ord(S[1]) shl 8) + ord(S[2]) , 0);<br>&nbsp; 完整代码在:(Delphi盒子上面也有的,不过正在弄服务器)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http://www.playicq.com/dispdocnew.php?id=14925
 
可以不用键盘钩子,用热键即可,相关例子在这里看:<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=2602343
 
还是刘麻子兄强,解决了,谢谢,可惜分太少了
 
接受答案了.
 
后退
顶部