1

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.

8
  • 1
    You want to associate the file types … Commented May 30, 2020 at 14:12
  • 1
    For C++ I can help you, by recommending one of these good C++ books. Commented May 30, 2020 at 14:12
  • 1
    For 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/ Commented 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. Commented May 30, 2020 at 14:51
  • 1
    You 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. Commented May 30, 2020 at 15:45

1 Answer 1

3

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:

enter image description here

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:

https://www.howtogeek.com/howto/windows-vista/add-any-application-to-the-desktop-right-click-menu-in-vista/

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 ;)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.