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
Release: 2024-11-22 11:04:16
Original
202 people have browsed it

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");
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template