How can you open a file with the program associated with its file extension?

前端 未结 6 1545
半阙折子戏
半阙折子戏 2020-12-24 13:50

Is there a simple way to open a file by its associated program in windows? (like double clicking it in windows explorer but done automatically with my code)

For exam

6条回答
  •  爱一瞬间的悲伤
    2020-12-24 14:07

    You want to use the file to open as the file argument, not the parameter argument. No need to specify which program to use, ShellExecute will look it up for you.

    ShellExecute(0, 0, L"c:\\outfile.txt", 0, 0 , SW_SHOW );
    

    By leaving the verb as NULL (0) rather than L"open", you get the true default action for the file type - usually this is open but not always.

提交回复
热议问题