这是我在一个论坛的讨论稿,我想这些情况在实践java/j2me/code/ target=_blank>程序设计过程中会常碰到,所以就将这些讨论资料写了下来:
? 【程序编程相关:ado异步查询的解决方案 】
作者:e梦缘 【推荐阅读:Delphi控制Excel 】
【扩展信息:DBGrid使用全书(四) 】请问用什么方法可以运行一个外部的exe并返回它的handle?
winexec 返回不是该exe的handle shellexecute, shellexecuteex 也不是 createprocess 返回的是 process handle 到底要如何才可以返回与 getwindow 所返回的一样的 handle?re:
可以用findwindow()函数,它能够解决这个问题,它有两个参数:lpclassname:程序的类名;lpwindowname:程序窗体的标题.
例如:
procedure tform1.button1click(sender: tobject);
begin shellexecute(handle,open,notepad.exe,nil,nil,sw_shownormal); end;procedure tform1.button2click(sender: tobject);
var exehandle:thandle; begin //获得句柄 exehandle:=findwindow(notepad,nil);//);//返回句柄 //关闭程序 if exehandle<>0 then sendmessage(exehandle,wm_close,0,0) else application.messagebox(没有打开"记事本"程序!,提示, mb_iconinformation+mb_ok); end;?
findwindow() 方法不是我想要的,因为这里的lpwindowname 具有不确定性,没有办法准确地找到. 我希望能在执行这支外部程序里就可以得到它的 handle. 比如有没有办法,通过process handle得到它有 application handle 以及 mainform handlere:
您可以通过lpclassname:程序的类名来准确地找到.
exehandle:=findwindow(notepad,nil);//返回句柄
... 下一页