用ShellExecute打开Prg文件时,出现Prg文件找不到的告警,确定后又正常执行。怎么办?(100分)

H

HookBoy

Unregistered / Unconfirmed
GUEST, unregistred user!
ShellExecute( handle, 'open', 'E:/Program Files/Microsoft Visual Studio/Vfp98/VFP6.EXE',<br>&nbsp; &nbsp; 'D:/aqb/ysb.prg', 'D:/aqb', SW_NORMAL);<br>出现了Prg文件找不到的告警。<br><br>ShellExecute( handle,'open','E:/Program Files/Microsoft Visual Studio/Vfp98/VFP6.EXE','','',SW_NORMAL);<br>正常打开FoxPro.<br><br>ShellExecute( handle, 'open', 'D:/aqb/ysb.prg', nil,nil, SW_NORMAL);<br>出现了Prg文件找不到的告警。<br><br>但当先打开FoxPro,再执行ShellExecute( handle, 'open', 'D:/aqb/ysb.prg', nil,nil, SW_NORMAL);又是正常的<br>怎么办?<br><br><br><br>
 
好象是简单的问题,怎么没有睬?
 
ShellExecute( handle, 'open', 'E:/Program Files/Microsoft Visual Studio/Vfp98/VFP6.EXE',<br>&nbsp; &nbsp; 'D:/aqb/ysb.prg', '', SW_NORMAL);<br>这样就行了
 
naughtboy:<br>很对,我也做出来了。<br>但是我无法找到这个句柄,以便能够 SendMessage 或是 SetForegroundWindow<br>如能回答,立刻上分
 
我采用了别人写的一个函数,想得到刚打开的THandle,<br>可是发现并不如我所愿,实事上并没有找到这个句柄。<br><br>function MyWinExec(const CmdLine: string; CmdShow: DWord): THandle;<br>var<br>&nbsp; SI :TStartupInfo;<br>&nbsp; PI :TProcessInformation;<br>begin<br>&nbsp; FillChar(si,SizeOf(si),0);<br>&nbsp; si.cb:=SizeOf(si);<br>&nbsp; si.dwFlags:=STARTF_USESHOWWINDOW;<br>&nbsp; si.wShowWindow:=CmdShow;<br>&nbsp; if CreateProcess(nil,PChar(CmdLine),nil,nil,false,0,nil,nil,si,pi) then<br>&nbsp; &nbsp; Result:=pi.hProcess<br>&nbsp; else<br>&nbsp; &nbsp; Result:=0;<br>end;<br><br>我的调用<br>var<br>&nbsp; s:string;<br>begin<br>&nbsp; ppp := MyWinExec('C:/WINNT/system32/notepad.exe', SW_Show );<br>&nbsp; GetWindowText( ppp, PChar(s), Length (s));<br>&nbsp; ShowMessage( s )<br>end;<br>结果没能得到notepad的窗口标题。<br>怎么回事?
 
你直接双击那个prg文件,是否能够打开?如果出错,那么你使用ShellExecute是不行的。<br>如果不出错,你可以考虑使用CreateProcess调用试验一下。<br>或者在文件件选项中的文件类型,找到prg类型,看他的默认使用Foxpro打开的参数是什么,按照他的加上试验一下。
 
我是能打开的,只是找不到这个Handle
 
// 我是能打开的,只是找不到这个Handle<br><br>&nbsp;我在你的另一个帖子里已经给你回答了:<br><br>&nbsp; &nbsp;http://www.delphibbs.com/delphibbs/dispq.asp?lid=1393406<br><br>
 
你的文件路径里有空格,所以这样[:D]
 
呵呵,无忌 兄提醒得好,如果文件路径里面有空格要加双引号:<br><br>ShellExecute( handle, 'open', '"E:/Program Files/Microsoft Visual Studio/Vfp98/VFP6.EXE"',<br>&nbsp; 'D:/aqb/ysb.prg', 'D:/aqb', SW_NORMAL);<br>
 
不妨在讨论一下,如果要打开的文件路径中含有空格该怎么办?<br>比如:<br>ShellExecute( handle, 'open', '"E:/Program Files/Microsoft Visual Studio/Vfp98/VFP6.EXE"',<br>&nbsp; &nbsp;'C:/My Document/aqb',nil, SW_NORMAL);<br>或者,FileName中存的是要打开的文件名,但有可能含空格,有可能没有.如果有空格会带来错误。<br>ShellExecute( handle, 'open', '"E:/Program Files/Microsoft Visual Studio/Vfp98/VFP6.EXE"',<br>&nbsp; ,Pchar(FileName),nil, SW_NORMAL);<br><br>
 
pi.hProcess 是实例句柄,不是主窗口句柄!!!!!
 
function GetAssociation(const DocFileName: string): string;<br>var<br>&nbsp; FileClass: string;<br>&nbsp; Reg: TRegistry;<br>begin<br>&nbsp; Result := '';<br>&nbsp; Reg := TRegistry.Create(KEY_EXECUTE);<br>&nbsp; Reg.RootKey := HKEY_CLASSES_ROOT;<br>&nbsp; FileClass := '';<br>&nbsp; if Reg.OpenKeyReadOnly(ExtractFileExt(DocFileName)) then<br>&nbsp; begin<br>&nbsp; &nbsp; FileClass := Reg.ReadString('');<br>&nbsp; &nbsp; Reg.CloseKey;<br>&nbsp; end;<br>&nbsp; if FileClass &lt;&gt; '' then<br>&nbsp; begin<br>&nbsp; &nbsp; if Reg.OpenKeyReadOnly(FileClass + '/Shell/Open/Command') then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := Reg.ReadString('');<br>&nbsp; &nbsp; &nbsp; Reg.CloseKey;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; Reg.Free;<br>end;<br><br>function ShellExecutePrg( PrgFileName:string ):boolean;<br>var<br>&nbsp; VFPPathAndName:string;<br>&nbsp; handle: Hwnd;<br>begin<br>&nbsp; &nbsp; VFPPathAndName:=GetAssociation( PrgFileName );<br>&nbsp; &nbsp; VFPPathAndName:=FastReplace( VFPPathAndName, '"', '', false);<br>&nbsp; &nbsp; VFPPathAndName:=FastReplace( VFPPathAndName, ' -SHELL', '', false);<br><br>&nbsp; &nbsp; ShellExecute( handle, 'open', PChar( VFPPathAndName ), PChar(PrgFileName),<br>&nbsp; &nbsp; &nbsp; &nbsp;'', SW_SHOWNORMAL );<br>end;<br><br>调用ShellExecutePrg( 'd:/mm/aa.prg' );<br><br>
 
接受答案了.
 
顶部