Hi,
and here i am throwing a "not the exact version" of my problem, but if this is been solved, my problem is done.

Lets suppose i am building a application in c++ that will simply display the content of a text file.
I absolutely can make the app take the name of the file(to be opened) as a command line argument from the command prompt.
But What I want to do is: When a person double-clicks the text file(extention .txt) on windows explorer; My program should run showing the content of the file.
Tell me how to proceed;
I can very well right-click on the .txt files and choose "Open with" and select my program. But the problem is, how do I make my program respond to such actions.?
Pl Help;

Recommended Answers

All 9 Replies

Well you can go into your Windows Explorer, Folder Options, File Types set the default program to your program name for the types you want opened with your program. If you can open the file by using "Open With", this should work for you.

Well you can go into your Windows Explorer, Folder Options, File Types set the default program to your program name for the types you want opened with your program. If you can open the file by using "Open With", this should work for you.

Well this i already know.
But my problem is to code my application so that it could respond to such actions.
I mean what code should I put on my app so that I can get the name of the file I have to open.

So you change the default program from notepad or whatever to your program, ofcourse this is all done in the registry. Which if you have a look through you will find that the extention .txt will trigger myapp.exe you can append a paramater on the end of that which represents the file name.

Chris

So shd I do this:

int main(int argc, char* argv[])
ifstream ofile;
ofile.open(argv[1]);
.
.
.
.

If edit my registry to make the Windows Explorer call my applicaiton for .txts, will the first argument be the file name from which the program has been called?

> will the first argument be the file name from which the program has been called?
Yes.
You can even use the registry to specify command line options if you wanted to.

You can even use the registry to specify command line options if you wanted to.

Kindly tell me how.....

Trying looking at how notepad is called from the registry command when you open a file, that tells you what to do for your application, if you apply some common sense.

> will the first argument be the file name from which the program has been called?
Yes.

I have a feeling you may get mixed up here, the FIRST would be argv[0] which ofcourse is the name of the application, once you set your registry then argv[1] will be equal to the text file that called it.

Chris

Thnk U;
return 1;
//I had done a lot of research before starting this thread;
//I dont ask Humans until I dont seriously find it on a Search Engine

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.