如果你还是想用ShellExecute,又想在程序外面检测程序状态,则需要使用 ShellExecuteEx。例如:
m_localFilePath="C:/DocExc006926.doc";
SHELLEXECUTEINFO ShExecInfo ;
memset(&ShExecInfo,0,sizeof(SHELLEXECUTEINFO));
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = "open";
ShExecInfo.lpFile =(LPCTSTR)m_localFilePath;
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_NORMAL;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
DWORD exCode;
GetExitCodeProcess(ShExecInfo.hProcess,&exCode);
while(exCode==STILL_ACTIVE)
{
Sleep(10);
MSG msg;
memset(&msg,0,sizeof(MSG));
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GetExitCodeProcess(ShExecInfo.hProcess,&exCode);
} 备注: 以上代码为VC代码 。。。
http://www.mini188.com/showtopic-136.aspx