一个比较简单的问题!谢谢!:)(50分)

  • 主题发起人 主题发起人 tgangt2004
  • 开始时间 开始时间
T

tgangt2004

Unregistered / Unconfirmed
GUEST, unregistred user!
一个比较简单的问题!谢谢!:)<br>我在程序中用shellexecute打开了一个程序,我如何才能知道,这个程序已经被我关闭了呢?最好能有个小例子,谢谢!
 
来自:刘麻子, 时间:2004-6-6 17:24:57, ID:2648462<br>这个问题我也遇到过,最后还好,解决了。看我代码。<br>&nbsp;TOpenFile &nbsp;= Class(TThread) &nbsp; //打开硬盘上的一个文件<br>&nbsp; &nbsp;fileName:string; &nbsp; &nbsp; &nbsp;//完整路径+文件名 &nbsp; <br>&nbsp; &nbsp;Constructor &nbsp;Create(fName:string);<br>&nbsp; &nbsp;Procedure &nbsp; &nbsp;Execute ; Override; //线程体<br>&nbsp;end;<br>Constructor TOpenFile.Create(fName);<br>begin<br>&nbsp; inherited create(true);<br>&nbsp; fileName &nbsp; := fName;<br>&nbsp; FreeOnTerminate:=True; //自动释放<br>&nbsp; Resume; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//恢复运行<br>end;<br><br>Procedure TOpenFile.Execute;<br>var<br>&nbsp; ShellExInfo : &nbsp;ShellExecuteInfo;<br>begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; FillChar(ShellExInfo, SizeOf(ShellExInfo), 0);<br>&nbsp; with ShellExInfo do begin<br>&nbsp; &nbsp; &nbsp;cbSize := SizeOf(ShellExInfo);<br>&nbsp; &nbsp; &nbsp;fMask &nbsp;:= see_Mask_NoCloseProcess;<br>&nbsp; &nbsp; &nbsp;Wnd &nbsp; &nbsp;:= 0;<br>&nbsp; &nbsp; &nbsp;lpFile := PChar(fileName);<br>&nbsp; &nbsp; &nbsp;nShow &nbsp;:= sw_ShowNormal;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;ShellExecuteEx(@ShellExInfo);<br>&nbsp; &nbsp;WaitForSingleObject(ShellExInfo.hProcess, INFINITE);//阻塞等待进程结束<br>//这里写入要做的事情。。。。。。<br>&nbsp;end;<br>end;<br>//============<br>要用的时候直接这样写: TOpenFile.Create('文件名'); &nbsp; &nbsp;
 
是的,主要是 WaitForSingleObject
 
谢谢两位高手,本人好久没碰DELPHI,想问一下,下面一段应该放在哪程序的哪个位子上!<br>TOpenFile &nbsp;= Class(TThread) &nbsp; //打开硬盘上的一个文件<br>&nbsp; &nbsp;fileName:string; &nbsp; &nbsp; &nbsp;//完整路径+文件名<br>&nbsp; &nbsp;Constructor &nbsp;Create(fName:string);<br>&nbsp; &nbsp;Procedure &nbsp; &nbsp;Execute ; Override; //线程体<br>&nbsp;end;<br><br>第二个想问的是,这个程序能在WIN98里用吗?<br>谢谢!:)
 
谢谢两位,我已经知道怎么用了!:)
 
后退
顶部