I wrote an application which will be able to open files of particular extension and show it to users. Now I want the users to be able to just double click the file and have it open with my application. I tried to set the "Always use the selected program..." option in the windows "Open With" dialog box, but do not know how to receive the file name 开发者_如何学编程that Windows sends to my application. How to do this?
Thanks...
The file name will be passed to your application as an argument. For example, in c#, you will get it like this:
static class Program
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
{
string filename = args[0];
}
}
If I understood well, you need something like:
~ Notepad test.txt
So, you need to make an optional argument in your application. If it exists open the file. If not, open a new file.
You should receive the filename in your application's startup parameters
Windows passes the filename as a startup parameter to your application. You will need to handle this in your WinMain or application entry point.
精彩评论