I've written a log parser, with some generous and insightful help from the SO community:
Keeping the UI responsive while parsing a very large logfile
Now, I'd like to be able to right click one of these logs, select "MyNewLogParser" from "Open With.." and see it open in my new program.
This would require me to
- Change something about my XP installation to show my program in the dropdown list
- Change the program so that it knows to open the selected file and run t开发者_开发问答he parsing.
What do you call these things, and how is it done? I don't know what to search for...
To open the selected file, you need to implement command-line parameters. Take a look at your Program.cs
file and the Main
function.
You want its signature to look something like this:
static void Main(string[] args)
{
}
The args
array will be the array of command-line params passed to your application. So if you ran MyNewLogParser myLog.txt
, the contents of args[0]
would be myLog.txt
.
For the OpenWith... menu, you'll need to modify the registry. Search for the "OpenWith" key in Regedit and you'll find it. On my machine (Windows 7), it's in
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
. I'm not sure on the exact details of how it works, but Google should be able to help you out from there.
If you don't want to do it programmatically, I'm pretty sure there's some menu item that allows you to select the application that will open a file. Don't recall what it is on XP, though. Alternatively, you can associate a file extension with your application through a tab in the Folder Options dialog, so that double-clicking it opens your application.
Assuming that your file logs have specific file extension, you need to add OpenWithList
keys in the registry. See this MSDN page for more information:
http://msdn.microsoft.com/en-us/library/bb166549%28VS.80%29.aspx
精彩评论