0

I need a way to open a generic file with the default application for that file.

For example: if the file is an HTML file, then it will be opened with Internet Explorer; if the file is an image (JPG, BMP, etc.), then it will be opened with "Paint"; if the file is an MP3 file, then it will be opened with Windows Media Player.

How can I do this ? What function or API do I have to use ?

xRobot
  • 25,579
  • 69
  • 184
  • 304

2 Answers2

9

Use the ShellExecute function: http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx

EDIT: or ShellExecuteEx

ZippyV
  • 12,540
  • 3
  • 37
  • 52
1

Another solution is to use standard system function - http://www.cplusplus.com/reference/clibrary/cstdlib/system/ so you won't even need to depend on WinAPI.

E.g.: system("start <filename>");

asciz
  • 125
  • 1
  • 4