Jump to content
  • Advertisement
Sign in to follow this  
Farraj

Open with...??

This topic is 4150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Let me state this example first: Usually when want to open a data file (e.g. a word file or a bmp file) on your desktop you double-click (or just click for some ppl) on it. The program -that reads the data file- starts and the file is auto-loaded. How is this done?? I made a small mesh viewer that reads a few known types of 3D files. I usually load the files by adding their names and locations in a 'load.txt' file (very simple viewer -_-). Is there a way that I can just duoble-click on a file and the viewer would just start by it self loading the file at the same time?? I'm guessing that you would use the 'Open with...' option to indecate what program to run the files. But how can I setup/program the viewer so it can get the file name and loaded it?? Is this even possiable with a cousule application or is it only done on a window application?? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

If you associate a file extension with your program (and assuming you are programming in Windows and C++), when you double-click a data file, it's path is sent as argument to your main() function. So, you can use the data path provided by the OS to open your file and start reading it. I used it under console, but I think you can do something very similar to that under a Windows App Program.

A simple example:

int _tmain(int argc, _TCHAR* argv[])
{
cout << "Number of arguments: " << argc << endl;

for (int i = 0; i < argc; i++)
{
cout << argv << endl;
}
return 0;
}





Hope that helped...

Share this post


Link to post
Share on other sites
This is done with the registry. You need to

A) have the file extension registered (see HKEY_CLASSES_ROOT). The extensions are registered with the . in front. The default value of the key holds the name of the real key.

B) The real key has two sub keys "open" and "openwith". Best to look at existing entries to see how it's done.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!