请教 如何才能调用一个程序的 子窗体的OnClick ( 积分: 100 )

  • 主题发起人 主题发起人 mt
  • 开始时间 开始时间
M

mt

Unregistered / Unconfirmed
GUEST, unregistred user!
我想掉用某个正在运行的程序的 OnClick 就是我在我的程序上按相应的按钮 那个程序就会执行相应OnClick 子程序 比如 掉用 TMainForm.EditStateClick <br>请大家给个实例 谢谢高手指导
 
我想掉用某个正在运行的程序的 OnClick 就是我在我的程序上按相应的按钮 那个程序就会执行相应OnClick 子程序 比如 掉用 TMainForm.EditStateClick <br>请大家给个实例 谢谢高手指导
 
var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>uses Unit2;<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> &nbsp;form2.Button1.Click;<br>end;<br><br>end.<br><br>//窗体2<br>unit Unit2;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp;TForm2 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form2: TForm2;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm2.Button1Click(Sender: TObject);<br>begin<br> &nbsp;showmessage('是这样的吗?');<br>end;<br><br>end.
 
不是的 我想掉用 的是另一个不是我们自己编的程序
 
yourControl.Click;
 
可以给正在运行的程序 的OnClick 按钮做个ShortCut(快捷键),<br>调用时发送相应地ShortCut(快捷键),呵呵,没试过,给个建议。。
 
100得全部给我哦,哈哈,帮你写出来,要用回调函数。<br>function EnumProc(hwnd:Thandle;lparam:lparam):boolean; Stdcall;<br>var<br> &nbsp; &nbsp;lpText,lpCaption &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:array[0..255] of char;<br><br>begin<br> &nbsp; &nbsp;Result := true;<br> &nbsp; &nbsp;GetClassName(hwnd,@lpText,255);//得到类名。<br> &nbsp; &nbsp;if LowerCase(lpText)=lowercase('tbutton') then<br>//这个用类别来查找。这里举例用TBUTTON<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;Hchild := hwnd;<br> &nbsp; &nbsp; &nbsp; &nbsp;GetWindowText(Hchild,lpCaption,100);<br> &nbsp; &nbsp; &nbsp; &nbsp;if trim(lpCaption)='按钮的CAPTION写在这里' then//在这边用CAPTION来查找<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := false//打到返回FALSE<br> &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := true;<br> &nbsp; &nbsp;end;<br>end;<br><br>function TForm1.GetEditHandle(WinCap:string):integer;<br>var<br> &nbsp; &nbsp;hParent &nbsp; &nbsp; &nbsp; &nbsp; :Thandle;<br> &nbsp; &nbsp;i &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :integer;<br>begin<br> &nbsp; &nbsp;Result := 0;<br> &nbsp; &nbsp;Hchild := 0;<br> &nbsp; &nbsp;hParent := FindWindow(nil,pchar(''));//窗体的名称写在这边<br> &nbsp; &nbsp;if hParent=0 then Exit;<br> &nbsp; &nbsp;EnumChildWindows(hParent,@EnumProc,0);//回调EnumProc<br> &nbsp; &nbsp;Result := Hchild;<br><br>end;<br>给分,为了争取进1000名,最近我真的见分就狂。哈哈。
 
忘记了,还要写一个东西就是发一个消息过去执行CLICK的事件。<br>SendMessage(Hchild,bm_click,0, 0);
 
还有另一招,哈哈,今天心情好,多贴了几下,。<br>var<br> H1,H2:THandle;<br>begin<br> &nbsp;H1:=FindWindow('TForm1','shenqw');<br> &nbsp;H2:=Findwindowex(H1,0,'TButton','Button1');<br> &nbsp;SendMessage(H2,bm_click,0,0);<br>end;
 
谢谢hzjone 还想请教一下 如果要点击菜单该如何去做
 
后退
顶部