-3

What I want to do is a program like notepad. I want that all the ".txt" files, when I double click on them, open with my program instead of notepad. But I don't have any clue how to do this. So, in resume, I want:

Make my program predeterminate for .txt extension files Make a program that open "automatically? " that file. Like when I open a test.txt file, and the notepad show the content of that file.

If you have any doubt, or I didn't explained very well, please ask!

  • 1
    Google is your friend: http://windows.microsoft.com/en-gb/windows/change-default-programs#1TC=windows-7 – Chris Kitching Mar 11 '16 at 03:36
  • The title of your question is misleading, I thought you wanted to your program to accept a file as a parameter, which you would just have to do: `int main(int argc, char* argv[]) {}`. And then manipulate argv to your will. – ranu Mar 11 '16 at 12:40
  • 1
    Possible duplicate: http://stackoverflow.com/questions/316204/how-to-set-an-application-as-the-default-program-of-opening-a-certain-type-of-fi – ranu Mar 11 '16 at 12:42
  • No answer is ok. I already know how to make my program the predeterminate for an file extension. What I want now is how to make the program itself. For example, a file that open a .txt file and show the content, in a way that when I open a text file, it opens with MY program (which will show the content of the file). Sorry, I don't speak english very well and it's hard to explain. – Gaston Fontenla Nuñez Mar 12 '16 at 03:11
  • after you set your program as default for text file (manually or programmatically), when you open a .txt file it'll open your program instead of notepad. What else do you want? – phuclv Mar 12 '16 at 03:29
  • I want to know how to do that program in C++, purely C++, no Visual C++. Something like this, but in C++: http://stackoverflow.com/questions/11714904/how-to-make-windows-autoview-a-file-with-my-program-and-how-to-make-the-program?rq=1 – Gaston Fontenla Nuñez Mar 12 '16 at 11:51
  • What do you mean by "purely C++"? Visual C++ is **not** a language. It's an IDE. Your question has already been answered in the other question. Just change the registry or call some APIs in your program – phuclv Mar 13 '16 at 14:02
  • Well, no, it wasn't answered yet. – Gaston Fontenla Nuñez Mar 13 '16 at 19:45

2 Answers2

0

This can be done by changing your OS setting. For example: Right Click -> Open With -> Choose default program, then select a direction to your execute.

I don't think you can implement it into your program.

dvnguyen
  • 2,954
  • 17
  • 24
  • 1
    You can write your program to alter the registry and set the default program. – user4581301 Mar 11 '16 at 05:57
  • No answer is ok. I already know how to make my program the predeterminate for an file extension. What I want now is how to make the program itself. For example, a file that open a .txt file and show the content, in a way that when I open a text file, it opens with MY program (which will show the content of the file). Sorry, I don't speak english very well and it's hard to explain – Gaston Fontenla Nuñez Mar 12 '16 at 03:11
  • @GastonFontenlaNuñez you want a file that opens your program with the text file? write a `.bat` file with content `your_program %1` that's all – phuclv Mar 12 '16 at 03:33
  • I want a program that opens a file, by clicking the file itself, not the program! So, when I click my file to open it, it'll be open using my program. Oh god I'm so bad explaining things XD – Gaston Fontenla Nuñez Mar 12 '16 at 11:44
  • Something like this. But in C++: http://stackoverflow.com/questions/11714904/how-to-make-windows-autoview-a-file-with-my-program-and-how-to-make-the-program?rq=1 – Gaston Fontenla Nuñez Mar 12 '16 at 11:50
0

I think this will get you started: http://www.codeproject.com/Articles/12474/How-To-Make-A-Very-Simple-Text-Editor-Using-MFC-in

Freitags
  • 330
  • 1
  • 10
  • 1
    Something like that, but in C++ using console. Also, I don't need such things like the dialog for choosing a file, and for saving, etc. Just open and view the file. – Gaston Fontenla Nuñez Mar 12 '16 at 11:49
  • Something like this but in C++: http://stackoverflow.com/questions/11714904/how-to-make-windows-autoview-a-file-with-my-program-and-how-to-make-the-program?rq=1 – Gaston Fontenla Nuñez Mar 12 '16 at 11:50