请问如何实现点击别的程序中toolbar 上的某个按键(button)? ( 积分: 100 )

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

laoyou

Unregistered / Unconfirmed
GUEST, unregistred user!
我的思路是:<br>1. &nbsp;找到此程序中 toolbar 的 handle,(用什么 api 函数?)<br>2. &nbsp;列出此 toolbar 上的 button 的 id ,好像这些 button 是没有 handle 的,<br> &nbsp; &nbsp;然后用某个 api 函数给此 toolbar 发消息,让其实现点击某个按钮,<br> &nbsp; &nbsp;如何实现?多谢了!
 
我的思路是:<br>1. &nbsp;找到此程序中 toolbar 的 handle,(用什么 api 函数?)<br>2. &nbsp;列出此 toolbar 上的 button 的 id ,好像这些 button 是没有 handle 的,<br> &nbsp; &nbsp;然后用某个 api 函数给此 toolbar 发消息,让其实现点击某个按钮,<br> &nbsp; &nbsp;如何实现?多谢了!
 
TOOLBAR得HANDLE,名称不可以吗?<br>发送鼠标点击消息吧,
 
转贴:(可能对你有帮助)<br>=============<br>其实这个程序主要的内容不是如何发qq信息<br>而是如何找到某一个正在运行的应用程序窗口上任意一个控件的句柄<br>我的方法是(以一个button为例)<br>用FindWindow找到窗体的句柄后<br>根据按钮的类别,循环找这个窗体上的每个'Button',然后用GetWindowText和Button的Caption比较,就可以找到想要的按钮句柄了<br><br>下面贴出我的程序,望大家批评指教<br>其中部分代码参考大富翁上某一帖子(忘了是哪个了)<br><br>To wjiachun:在下只想和大家交流交流,没敢要分<br>何况。。。这东西那么“土”。。。。 <br><br>unit OicqSendForm;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> &nbsp;StdCtrls, Buttons, ExtCtrls;<br><br>type<br> &nbsp;TfrmMain = class(TForm)<br> &nbsp; &nbsp;memText: TMemo;<br> &nbsp; &nbsp;edtTime: TEdit;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;Bevel1: TBevel;<br> &nbsp; &nbsp;Label2: TLabel;<br> &nbsp; &nbsp;bbtnStart: TBitBtn;<br> &nbsp; &nbsp;bbtnEnd: TBitBtn;<br> &nbsp; &nbsp;bbtnHelp: TBitBtn;<br> &nbsp; &nbsp;Timer: TTimer;<br> &nbsp; &nbsp;procedure bbtnStartClick(Sender: TObject);<br> &nbsp; &nbsp;procedure bbtnEndClick(Sender: TObject);<br> &nbsp; &nbsp;procedure TimerTimer(Sender: TObject);<br> &nbsp; &nbsp;procedure bbtnHelpClick(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;FTextHandle: HWND; &nbsp; //qq消息输入框句柄<br> &nbsp; &nbsp;FButtonHandle: HWND; //发送按钮输入框<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;frmMain: TfrmMain;<br><br>implementation<br><br><br>//这个函数取当前qq发送窗口上“送讯息”的按钮的句柄<br>//function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>function GetButtonHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>var<br> &nbsp;buffer: array[0..255] of Char;<br> &nbsp;buffer1: array[0..255] of Char;<br>begin<br> &nbsp;Result := True;<br> &nbsp;//得到目标窗口的控件<br> &nbsp;GetClassName(hwnd,buffer,256);<br> &nbsp;//找到发消息的目标窗口的目标控件<br> &nbsp;if StrPas(Buffer)='Button' then<br> &nbsp;begin<br> &nbsp; &nbsp;GetWindowText(hwnd,buffer1,100);<br> &nbsp; &nbsp;if buffer1 = '送讯息(&amp;S)' 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>end;//end of function<br><br>//这个函数取当前qq发送窗口上消息框句柄<br>//function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>function GetEditHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>var<br> &nbsp;buffer: array[0..255] of Char;<br> &nbsp;buffer1: array[0..255] of Char;<br>begin<br> &nbsp;Result := True;<br> &nbsp;//得到目标窗口的控件<br> &nbsp;GetClassName(hwnd,buffer,256);<br> &nbsp;//找到发消息的目标窗口的目标控件<br> &nbsp;if StrPas(Buffer)='Edit' then<br> &nbsp;begin<br> &nbsp; &nbsp;GetWindowText(hwnd,buffer1,100);<br> &nbsp; &nbsp;PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)<br> &nbsp; &nbsp;Result:=False; &nbsp;//终止循环<br> &nbsp;end;<br>end;//end of function<br><br>{$R *.DFM}<br><br>procedure TfrmMain.bbtnStartClick(Sender: TObject);<br>var<br> &nbsp;Handle: Integer;<br> &nbsp;tmpHandle: Integer;<br>begin<br> &nbsp;{取句柄}<br> &nbsp;Handle := FindWindow(nil,'对话模式'); &nbsp;//就是窗口的Caption<br> &nbsp;if Handle&lt;&gt;0 then<br> &nbsp;begin<br> &nbsp; &nbsp;tmpHandle := Handle;<br> &nbsp; &nbsp;//在这里循环取到想要的句柄为止<br> &nbsp; &nbsp;//取发送按钮的,FButtonHandle<br> &nbsp; &nbsp;EnumChildWindows(Handle,@GetButtonHandle,Integer(@Handle));<br> &nbsp; &nbsp;FButtonHandle := Handle;<br><br> &nbsp; &nbsp;//取消息输入框的,FTextHandle<br> &nbsp; &nbsp;EnumChildWindows(tmpHandle,@GetEditHandle,Integer(@tmpHandle));<br> &nbsp; &nbsp;FTextHandle := tmpHandle;<br><br> &nbsp; &nbsp;Timer.Interval := StrToInt(edtTime.Text);<br> &nbsp; &nbsp;Timer.Enabled := true;<br> &nbsp;end;//end of if<br><br>end;<br><br>procedure TfrmMain.bbtnEndClick(Sender: TObject);<br>begin<br> &nbsp;Timer.Enabled := false;//关闭定时器<br>end;<br><br>procedure TfrmMain.TimerTimer(Sender: TObject);<br>begin<br> &nbsp;{定时发送}<br> &nbsp;//设发送文本<br> &nbsp;SendMessage(FTextHandle,WM_SETTEXT,0,Integer(pchar(memText.Text)));<br><br> &nbsp;//发送按钮<br> &nbsp;//SendMessage(FButtonHandle,BN_CLICKED,0,0);<br> &nbsp;SendMessage(FButtonHandle,WM_LBUTTONDOWN,0,0);<br> &nbsp;SendMessage(FButtonHandle,WM_LBUTTONUP,0,0);<br>end;<br><br>procedure TfrmMain.bbtnHelpClick(Sender: TObject);<br>var<br> &nbsp;sHelp: String;<br>begin<br> &nbsp;//帮助<br> &nbsp;sHelp := '打开要发送的对象窗口'+#13+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '选择对话模式后点[开始]!';<br> &nbsp;ShowMessage(sHelp); &nbsp; &nbsp; &nbsp; &nbsp; <br><br>end;<br><br>end.
 

Similar threads

回复
0
查看
992
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部