Home >Backend Development >C++ >How Can C Registry Keys Associate File Extensions with Applications?

How Can C Registry Keys Associate File Extensions with Applications?

Susan Sarandon
Susan SarandonOriginal
2024-11-22 11:04:16205browse

How Can C   Registry Keys Associate File Extensions with Applications?

How to Associate File Extensions with Applications using C Registry Keys

Background

File extensions can be associated with specific applications, enabling them to be launched when a file with that extension is double-clicked. In C , this can be achieved by creating registry entries.

Creating the Registry Entries

To associate a file extension with an application, two registry entries are necessary:

  • ProgID: Represents the file type, defining properties like the icon and description.
  • File Name Extension: Links the extension to the ProgID.

The Registry::SetValue function can be used to set these values. Ensure the keys are created within the correct hive (HKEY_CURRENT_USERSoftwareClasses) for per-user settings, rather than HKEY_CLASSES_ROOT, which may result in precedence issues.

Example Code

Registry::SetValue(
    @"HKEY_CURRENT_USER\Software\Classes\blergcorp.blergapp.v1\shell\open\command",
    nullptr,
    @"c:\path\to\app.exe ""%1"""
);
Registry::SetValue(@ "HKEY_CURRENT_USER\Software\Classes\.blerg", nullptr, "blergcorp.blergapp.v1");

Registry Cleanup

Uninstalling an application does not automatically remove associated registry entries. However, a registry cleaner utility or manually deleting the keys can resolve this issue.

The above is the detailed content of How Can C Registry Keys Associate File Extensions with Applications?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn