查找句柄(50分)

  • 主题发起人 主题发起人 一生骄傲
  • 开始时间 开始时间

一生骄傲

Unregistered / Unconfirmed
GUEST, unregistred user!
请问我怎样才能找到别的程序中一个编辑框和按钮的句柄?例如QQ中发送消息的那个编辑框<br>和发送消息的按钮。谢谢
 
跟踪主窗口的标题或 className<br>找到主窗口后,子控件就好办了。可以枚举或再根据 classname 确定。<br><br>可以先用 Spy++ 或 WinSight 之类的跟踪一下主窗口的ClassName<br>总之,你得首先把这个软件的主窗口特征找出来。<br>
 
直接方法没有, 不过可以得到当前鼠标位置窗口的句柄. (注此方法我没有试过, 理论上可行)<br>vasr<br>&nbsp; vhandle:hwnd;//密码窗口句柄<br>p:tpoint; //鼠标指针<br>begin<br>getcursorpos(p); //查鼠标坐标<br>vhandle:= WindowFromPoint(p); //返回句柄<br>
 
哎,又想偷密码。
 
看看一下代码:<br>function CalBack(aa: Hwnd; bb: LPARAM): Boolean; stdcall;<br>var<br>&nbsp; &nbsp;aClassName, ComponetName: array[0..255] of Char;<br>begin<br>&nbsp; Result:=True;<br>&nbsp; GetClassName(aa, aClassName, 255); &nbsp; &nbsp; //依次得到子窗体所有控件类名<br>&nbsp; GetWindowText(aa, ComponetName, 255); &nbsp;//依次得到子窗体所有控件标题<br>// &nbsp;ShowMessage(aClassName);<br>// '(&amp;S)保存MPEG文件'<br>// '(&amp;L)装入VCD文件'<br>// '(&amp;S)停止转换'<br>// '(&amp;B)开始转换'<br>&nbsp; with FrmMain do<br>&nbsp; begin<br>&nbsp; &nbsp; if (StrComp(ComponetName, PChar('(&amp;B)开始转换')) = 0) and (aa &lt;&gt; 0) then<br>&nbsp; &nbsp; &nbsp; hwndBtnStart := aa;<br>&nbsp; &nbsp; if (StrComp(aClassName, PChar('TEdit')) = 0) and (aa &lt;&gt; 0) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Inc(p_nEditNum);<br>&nbsp; &nbsp; &nbsp; case p_nEditNum of<br>&nbsp; &nbsp; &nbsp; &nbsp; 1: hwndEdtGetVcd := aa;<br>&nbsp; &nbsp; &nbsp; &nbsp; 2: hwndEdtSaveMpeg := aa;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; if (StrComp(aClassName, PChar('TProgressBar')) = 0) and (aa &lt;&gt; 0) then<br>&nbsp; &nbsp; &nbsp; hwndPrgrsbr := aa;<br>&nbsp; end;<br>end;<br><br><br>// 以下是注册句柄<br>&nbsp; { find the exist game window }<br>&nbsp; HWndRuningApp := FindWindow(nil, PChar('VCD转换成为MPEG'));<br>&nbsp; if HWndRuningApp &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; EnumChildWindows(HWndRuningApp, @CalBack, 0);<br>&nbsp; &nbsp; SetActiveWindow(HWndRuningApp);<br>&nbsp; &nbsp; btnFindMpeg.Enabled := True;<br>&nbsp; &nbsp; btnChoseSaveDir.Enabled := True;<br>&nbsp; &nbsp; btnVcd2Mpeg.Enabled := True;<br>&nbsp; end;<br>
 
to:yeath<br>&nbsp; &nbsp;我没有那意思,并且也没那水平。希望不要误会。
 
用FindWindow找到窗口句柄,用FindWindowEx找到控件句柄。<br>for example:<br><br>procedure TMessage.Button5Click(Sender: TObject);<br>var<br>&nbsp; hwnd: Integer;<br>begin<br><br>&nbsp; hwnd := FindWindow(nil,pchar(edit1.text));<br>&nbsp; if hwnd&lt;&gt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; hwnd := FindWindowEx(hwnd,0,'TButton',pchar(edit3.text));<br>&nbsp; &nbsp; if hwnd=0 then showmessage('没找到按钮!');<br>&nbsp; &nbsp; SendMessage(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,0);<br>&nbsp; &nbsp; SendMessage(hwnd,WM_LBUTTONUP,MK_LBUTTON,0);<br><br>&nbsp; end<br>&nbsp; else showmessage('没找到窗口!');<br><br>end;
 
按钮的 ClassName 不一定就是 TButton!<br>这是 Delphi 按钮的类名。
 
jsxjd说得对,应该先用spy++看一下类名,如果不是Delphi写的,Button的类名可能就是button。
 
哈哈,这也没关系啊,我以前也做过这么一个,现在没了,格式 化了。
 
多人接受答案了。
 
后退
顶部