Search code examples
file-extensionwindows-explorer

How can I set a file association from a custom file type to a program


Let's say I make a custom file that actually corresponds to what my program can read called "Bacon.dek". I can access it, modify it, etc. normally from my program, with only a few problems staying alive (fixing them at a relatively correct speed, too).

Now, what I wanna do (and try to fix rather quickly once done), is actually choosing my file from Windows Explorer, right-clicking on it, and choose "Open with..." and choose my application.

Or simply set my application as the default application to simply double-click it and it would open in my app? Like, I double-click "Bacon.dek", and it opens "Eggs.exe", reading "Bacon.dek"?


Solution

  • Basically you have to do this -

    In registry add these keys

    [HKEY_CURRENT_USER\Software\Classes\dekEditor\shell\open\command]<br/>
    @="c:\path\to\app.exe \"%1\""<br/>
    [HKEY_CURRENT_USER\Software\Classes\.dek]<br/>
    @="dekEditor"<br/>
    

    This is a 2 step task.First you associate your extension .dek with dekEditor (2nd entry) and then specify it in Classes(1st entry).

    Answer taken from: Create registry entry to associate file extension with application in C++

    MSDN Article.