Your basic process overview is in this MSDN article . The key parts are at the bottom of the list:
A progID (essentially a file type registry key) is what contains important file type properties, such as an icon, description, and context menu items, including the application used to double-click a file. Many extensions may have the same file type. This mapping is performed in the next step:
- Register the file name extension for the file type
Here you set the registry value for your extension by setting the extension file type to ProgID, which you created in the previous step.
The minimum amount of work required to open a file in your application is to install / create two registry keys. In this example .reg file, I create a file type ( blergcorp.blergapp.v1 ) and associate the file extension ( blergcorp.blergapp.v1 ) with it.
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Classes\blergcorp.blergapp.v1\shell\open\command] @="c:\path\to\app.exe \"%1\"" [HKEY_CURRENT_USER\Software\Classes\.blerg] @="blergcorp.blergapp.v1"
Now you probably want to do this programmatically. To be absolutely kosher, you can check for the presence of these keys and change the behavior of your program accordingly, especially if you take control of some general file extension. However, the goal can be achieved by setting these two keys using the SetValue function.
I'm not sure about the exact syntax of C ++, but in C # the syntax looks something like this:
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Classes\blergcorp.blergapp.v1\shell\open\command", null, @"c:\path\to\app.exe \"%1\""); Registry.SetValue(@"HKEY_CURRENT_USER\Software\Classes\.blerg", null, "blergcorp.blergapp.v1");
Of course, you can manually open each nested key, manually create a ProgID and an additional extension key, and then set the key value, but the nice SetValue function of SetValue is that if the keys or values ββdo not exist, they will be created automatically., Very useful.
Now a short word about which hive to use. Many examples of file matching on the Internet, including on MSDN, show that these keys are set to HKEY_CLASSES_ROOT . I do not recommend doing this. This bush is a unified virtual view of HKEY_LOCAL_MACHINE\Software\Classes (system defaults) and HKEY_CURRENT_USER\Software\Classes (individual user settings), and entries in any subsection in the bush are redirected to the same key in HKEY_LOCAL_MACHINE\Software\Classes . Now there is no direct problem with this, but you may run into this problem: if you write in HKCR (redirected to HKLM), and the user specified the same keys with different values ββin HKCU, the HKCU values ββwill take precedence. Therefore, your entries will be successful, but you will not see any changes, because the HKEY_CURRENT_USER settings take precedence over the HKEY_LOCAL_MACHINE settings.
Therefore, you should take this into account when developing your application. Now, on the other hand, you can only write to HKEY_CURRENT_USER , as my examples show. However, this file association option will only be downloaded for the current user, and if your application has been installed for all users, it will not start when this other user opens the file in Windows.
This should be a worthy tutorial for what you want to do. For further reading, I suggest
And see also my similar answer to a similar question:
- Associating file extensions with a program