我用
WinExec("Notepad.exe report.txt", SW_SHOW);
可以启动记事本来显示report.txt文件但是用
WinExec("wordpad.exe report.wri", SW_SHOW);
却没有反应!

WinExec("word.exe report.wri", SW_SHOW);
也没有反应!我错在哪里?
因为我的程序需要在不同的环境下使用,所以启动外部程序就没有包含路径了,是这个地方的问题?

解决方案 »

  1.   

    我错在哪里?
    因为我的程序需要在不同的环境下使用,所以启动外部程序就没有包含路径了,是这个地方的问题?是这个地方的问题
    MSDN的解释为:
    If the name of the executable file in the lpCmdLine parameter does not contain a directory path, the system searches for the executable file in this sequence: 
    1、The directory from which the application loaded. 
    The current directory. 
    2、The Windows system directory. TheGetSystemDirectory function retrieves the path of this directory. 
    3、The Windows directory. TheGetWindowsDirectory function retrieves the path of this directory. 
    4、The directories listed in the PATH environment variable. 
      

  2.   

    use this WinExec("write.exe report.wri",SW_SHOW);
      

  3.   

    write.exe  在系统目录下面,所以不用自己搜索
      

  4.   

    ShellExecute(NULL, "open", "d:\\abraca.wri", "", NULL, SW_SHOW);
      

  5.   

    当然d:\\abraca.wri要存在,否则先建立一个空文件即可
      

  6.   

    wordpad.exe, write.exe都是写字板程序
    Win2000中都可以直接
    WinExec("write.exe report.wri",SW_SHOW);
    WinExec("wordpad.exe report.wri",SW_SHOW);
    来运行
      

  7.   

    wordpad 不在标准的搜索路径范围内,所以启动失败write是一个stub,通过 write 可以间接的启动 wordpad我说的那个 ShellExecute 也是一个办法第三个办法是查注册表,wordpad 是一个注册的程序,可以找到它的 open,print等动作对应的命令,命令字串里包含了 wordpad 的路径