I want to right-click on a text file and "Open With..." it with my own program, but I can't find any information on how to do that. I want to make my program in C++ or with WinForms (C#). I want to open that file and to use my program as an interpreter on a small "homemade programming language", so I want to pass the data from the file directly to my program. Can anyone help me? *hope I'm clear enough on what I'm trying to do.
-
1You want to associate the file types … – ChrisMM May 30 '20 at 14:12
-
1For C++ I can help you, by recommending one of these [good C++ books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Eljay May 30 '20 at 14:12
-
1For c++ you want to handle command line arguments. the file name will be passed as the first argument to your c++ application when using the Open With from Explorer. [https://www.geeksforgeeks.org/command-line-arguments-in-c-cpp/](https://www.geeksforgeeks.org/command-line-arguments-in-c-cpp/) – drescherjm May 30 '20 at 14:28
-
Thanks for quick answer but I already found how to do that. Only needed to add string[] args in the main function and from there the things are easy. – Paul T. May 30 '20 at 14:51
-
1You must prefer a single language for a single question. Either C++ or C#, both are different languages. In the other hand, you need to show your efforts what you've done so far. – Rohan Bari May 30 '20 at 15:45
-
@PaulT. : If you use c#, this link may be useful: https://stackoverflow.com/questions/2681878/associate-file-extension-with-application – D J May 31 '20 at 07:05
-
@PaulT. : Have a look at this too : https://stackoverflow.com/questions/212906/script-to-associate-an-extension-to-a-program#212921 – D J May 31 '20 at 07:05
-
Ok, sorry I'm a new user. And also thanks. – Paul T. Jun 03 '20 at 14:25
1 Answers
I'm just gonna to answer your Question for C#. If you still need C++ support you can tell me.
Option 1 - Drop down:
So if you for example create a Console-Application in C# (Visual Studio), it will look like this:
As you can see in the Picture: the Program accepts Arguments (args
String Array)
If you drag & drop your file on your .exe, the filepath of the file you dropped will be saved in the args
String Array. Now you can read the file (for example with the File-Class).
Option 2 - Right Click -> Open with my Program:
For that, you can simply add a new entry in HKEY_CLASSES_ROOT\Directory\Background\shell
(Windows Registry) to register you Program as a "Right Click Menu Program".
Here is a detailed How-To:
After you added your Program to the Windows Registry you can proceed as shown in Option 1 (args
).
Any more questions? Let me know.
Greets Bennet
EDIT: Sorry, didnt really read the comments :D but i guess your Question is answered. I will let this stay here for future readers which dont read the comments either ;)

- 56
- 9