本人是VC初学者,想在一个消息中调用一个可执行程序,比如双击按钮或单击按钮,或在菜单项中单击后执行一个可执行程序,怎么编码才能执行那个程序,请各位兄弟姐妹帮帮忙!!!!!!!!!

解决方案 »

  1.   

    两种方法:
    ShellExecuteEx
    CreateProcessHANDLE RunApplication(LPCTSTR szAppName)
    {
    SHELLEXECUTEINFO ExecuteInfo;
    ExecuteInfo.cbSize = sizeof( ExecuteInfo );
    ExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
    ExecuteInfo.hwnd = NULL;
    ExecuteInfo.lpVerb = _T("open");
    ExecuteInfo.lpFile = szAppName;
    ExecuteInfo.lpParameters = NULL;
    ExecuteInfo.lpDirectory = NULL;
    ExecuteInfo.nShow = SW_SHOWMAXIMIZED; BOOL bResult = ShellExecuteEx( &ExecuteInfo ); if( !bResult && (int)ExecuteInfo.hInstApp <= 32 )
    {
    return NULL;
    }
    return ExecuteInfo.hProcess;}BOOL m_result=CreateProcess(
    strPath,// pointer to name of executable module
             theApp.m_ProgramRunPara.GetAt(index),  // pointer to command line string
    NULL,  // process security attributes
             NULL, // thread security attributes
             FALSE,  // handle inheritance flag
             0, // creation flags
             NULL,  // pointer to new environment block
             NULL,   // pointer to current directory name
             NULL,  // pointer to STARTUPINFO
             &ProcessInformation );  // pointer to PROCESS_INFORMATION
      

  2.   

    WinExec
    The WinExec function runs the specified application. This function is provided for compatibility with 16-bit Windows. Win32-based applications should use the CreateProcess function. UINT WinExec(
      LPCSTR lpCmdLine,  // address of command line
      UINT uCmdShow      // window style for new application
    );
      

  3.   

    比如你要执行  c:\asd.execonst char* aaa="c:\\asd.exe";
    PROCESS_INFORMATION pi;
    STARTUPINFO si;
    memset(&si,0,sizeof(si));
    si.cb=sizeof(si);
    si.wShowWindow=SW_SHOW;
    si.dwFlags=STARTF_USESHOWWINDOW;
    CreateProcess(NULL,(LPSTR)aaa,NULL,NULL, FALSE,NORMAL_PRIORITY_CLASS|CREATE_NEW_CONSOLE,
    NULL,NULL,&si,&pi);
      

  4.   

    你需要什么中文解释啊?msdn都是英文的!而且调用API本身也没什么解释的啊!
      

  5.   

    HANDLE RunApplication(LPCTSTR szAppName);这个函数,你只要传递要执行的应用程序的完整路径就行了。比如:RunApplication("c:\\WINNT\\notepad.exe");
      

  6.   

    用下面这个函数也很简单:
    ShellExecute(
        HWND hwnd,     //父窗口句柄,可谓NULL
        LPCTSTR lpVerb,  //操作
        LPCTSTR lpFile,  //文件名,程序名
        LPCTSTR lpParameters, //参数
        LPCTSTR lpDirectory,  //目录
        INT nShowCmd  //显示方式
    );
    你看一下这个文章:http://www.vckbase.com/document/viewdoc.asp?id=416