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– ChrisMM2020-05-30 14:12:09 +00:00Commented May 30, 2020 at 14:12
-
1For C++ I can help you, by recommending one of these good C++ books.Eljay– Eljay2020-05-30 14:12:10 +00:00Commented May 30, 2020 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/drescherjm– drescherjm2020-05-30 14:28:45 +00:00Commented May 30, 2020 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.– Paul T.2020-05-30 14:51:34 +00:00Commented May 30, 2020 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– Rohan Bari2020-05-30 15:45:35 +00:00Commented May 30, 2020 at 15:45
1 Answer
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 ;)
