我写了一个多线程的程序,希望当其中一个线程运行结束时,也能同时结束另一个线程的程序。我试了好多方法,都不行,请各位大哥帮帮小弟,谢谢了?int main()
{
DWORD dwThreadID;
hMutex=CreateMutex(NULL,true,NULL);
HANDLE MyThread=::CreateThread(NULL,0,ThreadProc,0,0,&dwThreadID); ReleaseMutex(hMutex);
CloseHandle(MyThread); while(1)
{
if(MyThread)
{
AfxMessageBox("结束这个线程的程序");
}
else
{
AfxMessageBox("安装程序正在继续");
}
}
         return 0;
}
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
    STARTUPINFO si;
    si.wShowWindow = SW_HIDE; 
    PROCESS_INFORMATION pi;    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );    // Start the child process. 
    if( !CreateProcess( NULL,   // No module name (use command line). 
        "mpsetup10.exe  /q",    // 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.
    ) 
    {
        AfxMessageBox( "CreateProcess failed." );
    }    // Wait until child process exits.

    dwRet = WaitForSingleObject( pi.hProcess, INFINITE );
if(dwRet!=WAIT_FAILED)

AfxMessageBox("安装完毕");
CString str;
str.Format("%d",dwRet);
AfxMessageBox(str);
return   0;   
}   CloseHandle( pi.hProcess );
ReleaseMutex(hMutex);
return 1;
}