Skip to main content
gamedev.net
🔒 Locked

Open with...??

Started by Farraj Feb 13, 2007 at 5:14 AM 1 replies 900+ views
Original Post
Farraj
Farraj
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.
Sagito
Sagito
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...
http://sagito.wordpress.com
Endurion
Endurion
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.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.