能具体说说怎样获得其它windows应用程序中的Edit等控件的句柄吗?(50分)

  • 主题发起人 主题发起人 wuyaobing
  • 开始时间 开始时间
W

wuyaobing

Unregistered / Unconfirmed
GUEST, unregistred user!
比如我要获得IE地址栏的句柄,在上面输入URL(用我自己的程序实现),怎样实现<br>呢?
 
&nbsp; 用 FindWindow(ClassName: pchar; WindowName: pchar)找出窗口的句柄,然后:<br>&nbsp; &nbsp; sendmessag(win_hwnd,win_close,0,0)//或是别的消息<br><br>
 
&gt;&gt;hsw<br>我不会找到控件的句柄,怎样找.IE的地址栏!看上面<br>做给我看看,好吗?你提到的我用过,但不能(我不会)对&lt;b&gt;具体某个控件&lt;/b&gt;发送消<br>息(不能得到它的句柄).无论它是否获得焦点,我的程序都一样可对它操作!
 
//writer by liguang<br>//in 2000-03-17 <br>unit ligwin1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; Label2: TLabel;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; control,KeyId:integer;<br>&nbsp; &nbsp; hotkeyid:ATOM;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; procedure WMHOTKEY(var Msg:TMessage);message WM_HOTKEY;<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; ThisUrl:PChar;<br><br>implementation<br><br>{$R *.DFM}<br><br><br>function EnumChildWindowsProc(H:HWnd;lparam:longint):Boolean;stdcall;<br>var<br>&nbsp; Buffer: array[0..10] of Char;<br>begin<br>&nbsp; Result:=True;<br>&nbsp; GetClassName(h,buffer,10);<br>&nbsp; if trim(StrPas(Buffer))='Edit' then<br>&nbsp; begin<br>&nbsp; &nbsp; SendMessage(h,WM_GETTEXT,249,Integer(ThisUrl));<br>&nbsp; &nbsp; Result:=False;<br>&nbsp; end;<br>end;<br><br>procedure TForm1.WMHOTKEY(var Msg:TMessage);<br>var<br>&nbsp;h:HWND;<br>&nbsp;buffer:array[0..256] of char;<br>&nbsp;temp:String;<br>begin<br>&nbsp;if (Msg.LParamHi=KeyId) and (Msg.LParamLo=control) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; Msg.Result:=1;<br>&nbsp; &nbsp; h:=GetForegroundWindow;<br>&nbsp; &nbsp; GetClassName(h,buffer,255);<br>&nbsp; &nbsp; if StrPas(buffer)='IEFrame' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;EnumChildWindows(h,@EnumChildWindowsProc,0);<br>&nbsp; &nbsp; &nbsp; &nbsp;GetWindowText(h,buffer,255);<br>&nbsp; &nbsp; &nbsp; &nbsp;buffer[Pos(' - ',buffer)]:=Char(0);<br>&nbsp; &nbsp; &nbsp; &nbsp;temp:='当前网页的URL是:'+ThisUrl+#13#10+'当前网页Title是:'+buffer;<br>&nbsp; &nbsp; &nbsp; &nbsp;MessageBox(h,PChar(temp),'提示信息',MB_OK)<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp;end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp;ThisUrl:=StrAlloc(250);<br>&nbsp;control:=MOD_CONTROL or MOD_SHIFT ;KeyId:=$43;<br>&nbsp;hotkeyid:=GlobalAddAtom('UserDefineHotKey')-$C000;<br>&nbsp;RegisterHotKey(Handle,hotkeyid,control,KeyId);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp;UnregisterHotKey(Handle,hotkeyid);<br>&nbsp;DeleteAtom(hotkeyid);<br>end;<br><br>end.<br>怎么样,给分吧!
 
我先试试,先谢了!
 
接受答案了.
 
后退
顶部