Home >Backend Development >C++ >How to Programmatically Create File-Extension Associations in C ?
Creating File-Extension Associations in C
When a user double-clicks a file associated with a specific application, the operating system launches that application and passes the filename as an argument. This association is established through registry entries.
Registry Configuration
To register a file extension with an application in C , you need to create two registry keys:
Steps:
Create ProgID:
HKEY_CURRENT_USER\Software\Classes\<ProgID>
Associate Extension with ProgID:
HKEY_CURRENT_USER\Software\Classes\.<Extension>
Set the value to the ProgID.
Example:
To associate the .blerg extension with the blergcorp.blergapp.v1 file type, create the following registry keys:
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"
Programmatic Approach:
Use the SetValue function in C to set these registry values. If the keys or values don't exist, they will be automatically created.
Considerations:
Conclusion:
By creating the appropriate registry entries, you can associate file extensions with your C application, enabling users to open associated files directly through your application.
The above is the detailed content of How to Programmatically Create File-Extension Associations in C ?. For more information, please follow other related articles on the PHP Chinese website!