CreateProcess函数的原型如下所示:
BOOL CreateProcess(
  LPCTSTR lpApplicationName,                 // name of executable module
  LPTSTR lpCommandLine,                      // command line string
  LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
  LPSECURITY_ATTRIBUTES lpThreadAttributes,  // SD
  BOOL bInheritHandles,                      // handle inheritance option
  DWORD dwCreationFlags,                     // creation flags
  LPVOID lpEnvironment,                      // new environment block
  LPCTSTR lpCurrentDirectory,                // current directory name
  LPSTARTUPINFO lpStartupInfo,               // startup information
  LPPROCESS_INFORMATION lpProcessInformation // process information
);其中最后一个参数的结构体如下所示:
typedef struct _PROCESS_INFORMATION { 
    HANDLE hProcess; 
    HANDLE hThread; 
    DWORD dwProcessId; 
    DWORD dwThreadId; 
} PROCESS_INFORMATION; 调用CreateProcess创建一个新进程时,该参数保存了该进程的信息(进程的句柄和ID等),应用程序可以通过这些信息来通信或者控制。下面是一个MSDN中的小例子,希望能对您有所帮助。void main( VOID )
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );    // 创建子进程
    if( !CreateProcess( NULL, // No module name (use command line). 
        "MyChildProcess", // Command line. 
        NULL,             // Process handle not inheritable. 
        NULL,             // Thread handle not inheritable. 
        FALSE,            // Set handle inheritance to FALSE. 
        0,                // No creation flags. 
        NULL,             // Use parent's environment block. 
        NULL,             // Use parent's starting directory. 
        &si,              // Pointer to STARTUPINFO structure.
        &pi )             // Pointer to PROCESS_INFORMATION structure.
    ) 
    {
        ErrorExit( "CreateProcess failed." );
    }    // 等待子进程退出
    WaitForSingleObject( pi.hProcess, INFINITE );    // 关闭句柄
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
}
 - 微软全球技术中心 VC技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。

解决方案 »

  1.   

    同意 acptvc(微软全球技术中心 VC技术支持) 不过需要注意的是:ShellExecute 或 CreateProcess 创建的是进程,而非线程。
      

  2.   

    你这个是多进程的问题啊,我看题目还以为是多线程呢。
    DWORD WaitForSingleObject(
      HANDLE hHandle,        // handle to object
      DWORD dwMilliseconds   // time-out interval
    );
    ---hHandle 
    [in] Handle to the object. For a list of the object types whose handles can be specified, see the following Res section. 
    If this handle is closed while the wait is still pending, the function's behavior is undefined
    --dwMilliseconds 
    [in] Specifies the time-out interval, in milliseconds. The function returns if the interval elapses, even if the object's state is nonsignaled. If dwMilliseconds is zero, the function tests the object's state and returns immediately. If dwMilliseconds is INFINITE, the function's time-out interval never elapses
      

  3.   

    多谢大家!
    有没有用ShellExecute的例子?