简体   繁体   English

如何使用可执行文件打开文本文件?

[英]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.

相关问题 如何在MVC应用程序中打开文本文件? - How Can I open the Text file in my MVC application? 如何打开相对于我的MVC项目的文本文件? - How can I open a text file relative to my MVC project? 如何包含保存在可执行文件中的文本文件中? - How can I include saving in a text file in executable file? 如何在不使用OpenFileDialog的情况下打开特定的文本文件? - How can I open a specific text file without using OpenFileDialog? 如何将C#项目更新为可执行文件/应用程序? - How can I update my C# project as an executable file/application? 如何在不增加可执行文件大小的情况下将图像添加到桌面应用程序? - How can I add images to my desktop application without increasing the executable file size too much? 如何使用可执行文件打开文件? - How to open a file with an executable already open? 如何直接在浏览器中打开 pdf 文件? - How can I open a pdf file directly in my browser? 我如何确定用OpenFileDialog打开的文本文件只是常规文本文件还是html内容? - How can i be sure if a text file i open with OpenFileDialog is just regular text file or html content? 发布期间,如何自动将类库中的自定义配置文件包含到可执行项目中? - How can I automatically include a custom configuration file from my class library into my executable project during release?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM