[英]How can I open a text file with my executable?
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#).
我想在 C++ 或 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.
*希望我对我正在尝试做的事情足够清楚。
I'm just gonna to answer your Question for C#.我只是要回答你关于 C# 的问题。 If you still need C++ support you can tell me.
如果您仍然需要 C++ 支持,您可以告诉我。
Option 1 - Drop down:选项 1 - 下拉:
So if you for example create a Console-Application in C# (Visual Studio), it will look like this:因此,例如,如果您在 C# (Visual Studio) 中创建一个控制台应用程序,它将如下所示:
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.如图所示:该程序接受 Arguments(
args
字符串数组) 如果您将文件拖放到 your.exe 上,您拖放的文件的文件路径将保存在args
字符串数组中。 Now you can read the file (for example with the File-Class).现在您可以读取文件(例如使用 File-Class)。
Option 2 - Right Click -> Open with my Program:选项 2 - 右键单击 -> 使用我的程序打开:
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".为此,您只需在
HKEY_CLASSES_ROOT\Directory\Background\shell
(Windows 注册表)中添加一个新条目,即可将您的程序注册为“右键单击菜单程序”。 Here is a detailed How-To:这是详细的操作方法:
https://www.howtogeek.com/howto/windows-vista/add-any-application-to-the-desktop-right-click-menu-in-vista/ 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
).将程序添加到 Windows 注册表后,您可以按照选项 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.编辑:对不起,没有真正阅读评论:D,但我想您的问题已得到解答。 I will let this stay here for future readers which dont read the comments either;)
我会让它留在这里,以供将来不阅读评论的读者使用;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.