比如我想用程序打开一个 test.txt文件,用notepad.exe打开,怎么写代码呢?

解决方案 »

  1.   

    CString str = "路径";
    ShellExecute(NULL, "open", str, NULL, NULL, SW_SHOWNORMAL);//打开指定的文件
    这段代码可以在程序里打开文件 具体看ShellExecute函数参数吧
      

  2.   

    System("notepad.exe test.txt");
      

  3.   

    不用在前面加上 cmd.exe /c吗?
      

  4.   

    STARTUPINFO si;
        PROCESS_INFORMATION pi;    ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );    // Start the child process. 
        if( !CreateProcess(_T("C:\\Windows\\System32\\Notepad.exe"),   // No module name (use command line). 
            TEXT("C:\\Test.txt"), // 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.

        {
            printf( "CreateProcess failed (%d).\n", GetLastError() );
            return;
        }
      

  5.   

    CString commandLine = "cmd /C " + GetCurrentPath() + "**.exe ***";
    if (!CreateProcess(commandLine)
    {
    return false;
    }
      

  6.   

    用那么麻烦吗,直接用批处理命令 start notepad.exe
    建一个txt写入start notepad.exe,把扩展名改为bat,运行就行了。
      

  7.   


    不用,另外,我写错了,不是System,是system#include <stdlib.h>System("notepad.exe c:\\test.txt");system:Execute a command.