File Batch-Opening

Started by
2 comments, last by raz0r 18 years, 1 month ago
How do I make it possible for my program to be assigned to a filetype. Example - when you instally WinRAR to your computer, it automatically sets it up so that whenever a file of that type is double-clicked, winrar.exe is executed, but how does WinRAR know which file to open? Is there a command line (argc / argv) thing that I'm missing here?
Advertisement
When you install WinRAR or other programs that takes over handling certain file extensions, one of the things it does is make changes to the registry. Let's say you want your program to handle the extension .myfile. First you would create a key HKEY_CLASSES_ROOT\.myfile and add a REG_SZ value with the name of your handler. This can be any string, but in practice you name it similarly to your application. In this case we'll call it MyFileApp. Then you create another key HKEY_CLASSES_ROOT\MyFileApp and give it a REG_SZ value that describes the handler. We could call it "My File Handler". Then you create a subkey of HKEY_CLASSES_ROOT\MyFileApp HKEY_CLASSES_ROOT\MyFileApp\open. This doesn't require a value, but does require a subkey HKEY_CLASSES_ROOT\MyFileApp HKEY_CLASSES_ROOT\MyFileApp\open\command. This you give a value equal to the command string for invoking your application. It might be C:\MyFolder\MyApp.exe "%1".
For clarification - where can I find code on how to add/modify registry values, and thank you, for help on the matter of how to do this. I do recall once browsing the registry out of boredom, and came across a registry path similar to this one, and thought "What does all this mean?". Well, now I know.
RegCreateKeyEx / RegSetValueEx...

Check out MSDN for more information if you're confused...

This topic is closed to new replies.

Advertisement