c++ – How do I tell the OS to open a graphics file from C ++?

Question:

I cannot open the graphic file. Tried this first:

#define FNAME "D:/Scream297and396.jpg"              
...            
int main() { char fname [50] =FNAME;        
FILE *fout;            
fout = fopen(FNAME,"r");           
return 0; }

… but when you run this program nothing happens, the file does not open. More precisely, apparently, it still opens, but to read the file data itself with the same program.

I need to open the file not for the program , but for the user , in the default way in the operating system. In this case, the file D:/Scream297and396.jpg should open in the image viewer set for *.jpg .

How to do it?

Answer:

I suppose you want something like this:

ShellExecute(handle, "open", "D:\\Scream297and396.jpg", nullptr, nullptr, SW_SHOWNORMAL);

Read more about ShellExecute capabilities on MSDN

Scroll to Top