ShellExecuteEx调用word文件,关闭不了word (方法为刘麻子的方法)(50分)

H

happygb

Unregistered / Unconfirmed
GUEST, unregistred user!
看到刘麻子的一篇解答,在调用的程序执行完时,触发一个后续动作
var
ShellExInfo : ShellExecuteInfo;
begin
FillChar(ShellExInfo, SizeOf(ShellExInfo), 0);
with ShellExInfo do begin
cbSize := SizeOf(ShellExInfo);
fMask := see_Mask_NoCloseProcess;
Wnd := 0;
lpFile := PChar(fileName);
nShow := sw_ShowNormal;
end;
ShellExecuteEx(@ShellExInfo);
WaitForSingleObject(ShellExInfo.hProcess, INFINITE);//阻塞等待进程结束
//这里写入要做的事情。。。。。。
end;

但是这个执行exe程序是可行的,但是调用word之类的文件,当调用成功后,关闭word是就出现word死掉了,不知道这个问题怎么解决,请各位大侠指点一下!
 
如果刘麻子在的话,希望能来帮忙解决一下。
 
自己再顶一下吧
 
为什么不这样:
var
WordApp:variant;
...
WordApp:=createoleobject('word.application');

WordApp.Quit;
 
问题在于我不知道是WORD文件,说WORD文件只是举例
 
我系统中的一个函数,给你参考:

function WinExecAndWait32(Path: PChar; Visibility: Word;
Timeout: DWORD): integer;
var
WaitResult : integer;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
ExePath : string;
begin
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
with StartupInfo do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
{ you could pass sw_show or sw_hide as parameter: }
wShowWindow := visibility;
end;

ChDir(ExportPath); //要转到bat目录下才行

if CreateProcess(nil,path,nil, nil, False,
NORMAL_PRIORITY_CLASS, nil, nil,
StartupInfo, ProcessInfo) then
begin
if TimeOut = 0 then
WaitResult := WaitForSingleObject(ProcessInfo.hProcess, infinite) //------------ 该句起到等待的作用!!!!!!!!! --------------
else
WaitResult := WaitForSingleObject(ProcessInfo.hProcess, TimeOut);
{ timeout is in miliseconds or INFINITE if you want to wait forever }
result := WaitResult;
end
else
{ error occurs during CreateProcess see help for details }
result := GetLastError;
end;
 
谢谢,大家,这个问题我已经找到解决方法了,现在散分
 
顶部