var ShExecInfo:SHELLEXECUTEINFO;
ExitCodeLong:Dword;
begin
ShExecInfo.cbSize:= sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask:= SEE_MASK_NOCLOSEPROCESS;
//ShExecInfo.Wnd:= HWND;
ShExecInfo.lpVerb:= nil;
ShExecInfo.lpFile:=PwideChar(exename);
ShExecInfo.lpParameters:=Pwidechar(FileName);
ShExecInfo.lpDirectory:= nil;
ShExecInfo.nShow:=SW_SHOW;
ShExecInfo.hInstApp :=0;
ShellExecuteEx(@ShExecInfo);
GetExitCodeProcess(ShExecInfo.hProcess, ExitCodeLong);
while ExitCodeLong = STATUS_PENDING do
begin
GetExitCodeProcess(ShExecInfo.hProcess, ExitCodeLong);
Application.ProcessMessages;
sleep(100);
end;
CloseHandle(ShExecInfo.hProcess);
showmessage('close');由于word打开多个文档只有一个winword.exe进程,如果当前没有word打开,第一个打开的文档是可以判断的,但第二个就判断不了了
ExitCodeLong:Dword;
begin
ShExecInfo.cbSize:= sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask:= SEE_MASK_NOCLOSEPROCESS;
//ShExecInfo.Wnd:= HWND;
ShExecInfo.lpVerb:= nil;
ShExecInfo.lpFile:=PwideChar(exename);
ShExecInfo.lpParameters:=Pwidechar(FileName);
ShExecInfo.lpDirectory:= nil;
ShExecInfo.nShow:=SW_SHOW;
ShExecInfo.hInstApp :=0;
ShellExecuteEx(@ShExecInfo);
GetExitCodeProcess(ShExecInfo.hProcess, ExitCodeLong);
while ExitCodeLong = STATUS_PENDING do
begin
GetExitCodeProcess(ShExecInfo.hProcess, ExitCodeLong);
Application.ProcessMessages;
sleep(100);
end;
CloseHandle(ShExecInfo.hProcess);
showmessage('close');由于word打开多个文档只有一个winword.exe进程,如果当前没有word打开,第一个打开的文档是可以判断的,但第二个就判断不了了
判断关闭好像没什么好的办法,毕竟关闭是word自己的事情了,跟你的程序无关,看看能不能截到什么消息之类的。