实现shellexecute and wait(100分)

  • 主题发起人 主题发起人 Adnil
  • 开始时间 开始时间
A

Adnil

Unregistered / Unconfirmed
GUEST, unregistred user!
ShellExecute(Handle,'open',pchar(a.doc),'','',Sw_show);<br><br>现在是函数执行后立即返回,我希望等待程序结束后才返回。<br><br>请教高手。
 
function WinExecAndWait32(FileName:String; Visibility :integer):integer;<br>var<br>&nbsp; zAppName:array[0..512] of char;<br>&nbsp; zCurDir:array[0..255] of char;<br>&nbsp; WorkDir:String;<br>&nbsp; StartupInfo:TStartupInfo;<br>&nbsp; ProcessInfo:TProcessInformation;<br>begin<br>&nbsp; StrPCopy(zAppName,FileName);<br>&nbsp; GetDir(0,WorkDir);<br>&nbsp; StrPCopy(zCurDir,WorkDir);<br>&nbsp; FillChar(StartupInfo,Sizeof(StartupInfo),#0);<br>&nbsp; StartupInfo.cb := Sizeof(StartupInfo);<br>&nbsp; StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br>&nbsp; StartupInfo.wShowWindow := Visibility;<br>&nbsp; if not CreateProcess(nil,<br>&nbsp; &nbsp; zAppName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ pointer to command line string }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to process security attributes }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to thread security attributes }<br>&nbsp; &nbsp; false, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { handle inheritance flag }<br>&nbsp; &nbsp; CREATE_NEW_CONSOLE or &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ creation flags }<br>&nbsp; &nbsp; NORMAL_PRIORITY_CLASS,<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to new environment block }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to current directory name }<br>&nbsp; &nbsp; StartupInfo, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to STARTUPINFO }<br>&nbsp; &nbsp; ProcessInfo) then Result :=DWORD(-1) { pointer to PROCESS_INF }<br>&nbsp; else begin<br>&nbsp; &nbsp; WaitforSingleObject(ProcessInfo.hProcess,INFINITE);<br>&nbsp; &nbsp; GetExitCodeProcess(ProcessInfo.hProcess,DWORD(Result));<br>&nbsp; end;<br>end;
 
function WinExecAndWait32(FileName:String; Visibility :integer):integer;<br><br>这个函数我也知道,但是要传执行文件的参数,shellexecute的功能被弱化了。<br><br>我现在只想传执行的操作,例如传入<br>'open', 'a.txt' -&gt;自动调用notepad<br>'open', 'http://delphibbs.com' -&gt; 自动调用ie或者opera什么的打开站点<br>'print', 'xxx.htm' -&gt; 打印xxx.htm<br><br>能明白我的意思吗?
 
原先不打算再说话了,看到贴主还没给分,那就说一句吧,呵呵[:D][:D]<br>看看我在这个帖子中的回答吧,http://www.delphibbs.com/delphibbs/dispq.asp?lid=1846348
 
小笨苯,你看清楼上的我说的了吗? 我不调用执行文件。
 
仔细执行了一下,小笨苯的可以满足需求,接受答案了!
 
后退
顶部