如何调用其它exe程序,并将其窗体置顶 ( 积分: 100 )

  • 主题发起人 主题发起人 x_shm@yahoo.com
  • 开始时间 开始时间
X

x_shm@yahoo.com

Unregistered / Unconfirmed
GUEST, unregistred user!
我用delphi写了一个程序A,在A中要调用程序B.B没有源码.也不知是谁写的.<br>我希望:<br>1.在A中可以打开B,关闭B.<br>2.无论如何操作A,B始终显示在A窗体的前面.<br>对于问题1:打开,我用的winexec('B.exe',sw_show);//OK,成功打开;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;关闭,不知如何.<br>对于问题2:我尝试:<br> &nbsp; &nbsp; &nbsp;(1)改变winexec(p1,p2)函数据的第二个参数p2,试了很多,也不行.<br> &nbsp; &nbsp; &nbsp;(2)定义变量 hand:Thandle; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hand:=findwindow('','B的窗体标题文字');//第一个参数设为''空,因为我不知该窗体的类名是什么.<br>         SetWindowPos(hand, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); //设置顶层.<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //这种方法也不行.<br> &nbsp; &nbsp; &nbsp; (2) 定义变量 hand:Thandle;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;winexec('B.exe',sw_show);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hand:=GetActiveWindow();<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetWindowPos(hand, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); //设置顶层.<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//这种方法也是不行.取得的hand是A的句柄.<br>没办法了.请各位指点
 
我用delphi写了一个程序A,在A中要调用程序B.B没有源码.也不知是谁写的.<br>我希望:<br>1.在A中可以打开B,关闭B.<br>2.无论如何操作A,B始终显示在A窗体的前面.<br>对于问题1:打开,我用的winexec('B.exe',sw_show);//OK,成功打开;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;关闭,不知如何.<br>对于问题2:我尝试:<br> &nbsp; &nbsp; &nbsp;(1)改变winexec(p1,p2)函数据的第二个参数p2,试了很多,也不行.<br> &nbsp; &nbsp; &nbsp;(2)定义变量 hand:Thandle; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hand:=findwindow('','B的窗体标题文字');//第一个参数设为''空,因为我不知该窗体的类名是什么.<br>         SetWindowPos(hand, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); //设置顶层.<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //这种方法也不行.<br> &nbsp; &nbsp; &nbsp; (2) 定义变量 hand:Thandle;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;winexec('B.exe',sw_show);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hand:=GetActiveWindow();<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetWindowPos(hand, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); //设置顶层.<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//这种方法也是不行.取得的hand是A的句柄.<br>没办法了.请各位指点
 
我有个在里面的代码<br><br>var<br> &nbsp; &nbsp;hand : THandle;<br>begin<br> &nbsp;SHELLEXECUTE(Form1.handle, 'Open', 'c:/winnt/System32/calc.exe', nil, nil, SW_NORMAL);<br> &nbsp;Sleep(100);<br> &nbsp;hand := FindWindow(nil, PChar('计算器'));<br> &nbsp;Windows.SetParent(hand,self.Handle);<br> &nbsp;MoveWindow(hand,top,left,0,0,true);
 
找游戏外挂方面的资料一阅就明白了,spy++是必备工具。
 
后退
顶部