新建一基于对话框的工程,在窗口上放置一按钮,点击该按钮后就执行 C:\Test.exe
请问在该按钮的单击事件中如何编写才能实现?谢谢!

解决方案 »

  1.   

    m_sPath = "c:\\Test.exe";
    ShellExecute(NULL, "open", m_sPath, NULL, NULL, SW_SHOWNORMAL);
      

  2.   

    一般来说简单的有3种:
    1.
    m_fPath = "c:\\sample.exe";
    WinExec(m_fPath, SW_SHOW);
    2.
    就是上面zhangyilan(数字通信)说的。你可以查看一下MSDN,很清楚。
    3.
    创建一个进程,可以进行严格的控制
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    if (!CreateProcess("c:\\sample.exe",//the full file name
    NULL,              //command line NULL,  //Process handle not inheritable. 
    NULL,  //Thread handle not inheritable.
             NULL,  //Set handle inheritance to FALSE.
             NULL,  //the 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
       )
        MessageBox(NULL, "CreateProcess failed.", "Error!", MB_OK |              MB_ICONERROR);

    // Wait until child process exits.
    WaitForSingleObject(pi.hProcess, INFINITE); //time-out interval// Close process and thread handles. 
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);不过我看,你现在只需要第一种就可以了,最简单方便。不过创建新的进程是一个好的方法,可以随心所欲地做你想做的,多看一下MSDN,很快就明白了。