Hey guys i am interested in knowing how to let my C++ open images. Like set the location on the image in C++ and when i click it, it opens image viewer. Also would like to know if i can do the same thing with music. Like put a list of songs in the C++ program and when the user clicks on it, it opens itunes or windows media player. Just need someone to point me in the right direction on what to look for and what library to use

Not sure if its clear what you want to do. Do you want to write a C++ program where it takes a file path to a image or music and opens the file using appropriate application like ms-paint for images or windows media player for music? Or do you want the C++ program to take in a filePath like a music and play it using your own functions and code?

Not sure if its clear what you want to do. Do you want to write a C++ program where it takes a file path to a image or music and opens the file using appropriate application like ms-paint for images or windows media player for music? Or do you want the C++ program to take in a filePath like a music and play it using your own functions and code?

the first part. It takes a file path to a image or music and open it in the appropriate application.

What OS are you running for? Does it need to be portable or just a simple home application?

Windows OS. Its a project actually. So its going to be portable, im using visual studio 2010

Windows OS. Its a project actually. So its going to be portable, im using visual studio 2010

If thats the case, then you will need a way to create a new process and run a needed application. You can use boost libraries to create new process( I think its portable ), and when creating the new process , you will need to make sure the correct application gets opened.

On a easier note, maybe something tedious like this:

#ifdef _WIN32
 #include <cstdlib>
 #define SystemCmd System
 #define TextFileEditor "notepad"
#elseif defined ___linux
 #define SystemCmd system
 #define TextFileEditor "gedit"
#endif

#include <string>
using namespace std;

int main(int argv, char *argv[]){
   if(argv > 1){
       const char *filePath = argv[1];
       if(isTextFile( filePath) ){
          string textFileCmd = "./" + TextFileEditor + " " + filePath;
          SystemCmd( textFileCmd );
       }
       //else if...
   }

  return 0;
}

But note that SystemCmd is not a good way to go about it, because of security issues and its blocking nature. See system for windows for an example.

That code doesnt run. Its giving me some error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.