Register filetype in windows registry

I've made a program that handles some image formats. How do I associate these image formats with my program (in the registry)? (when I click an image file in explorer I want my program to start)
jonassondanielAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
TMillerConnect With a Mentor Commented:
Assuming your new file type is qwe, add in the registery under HKEY_CLASSES_ROOT\.qwe and in the default value enter something like qwefile, then open another registry  key called qwefile, in the default value enter a nice friendly name like "My new QWE File type", and open an "Shell" key and under it an "Open" key and under it a "Command" key, and the default value of the "Command" should be the fullpath to your viewer of qwe files. Goodluck
0
 
jonassondanielAuthor Commented:
Thanks, I think I get the general idea.. ..but you don't happen to have some example code? It would be really great if you did!
0
 
LischkeCommented:
I used the following code to register my own file types (in this case *.l):

var Key, SubKey: HKEY;
    Disposition: Integer;
    Entry,
    Association: String;

begin
  :
  Association := '"' + Application.ExeName + '" "%1"';
  // lexer file (*.l)
  if FileCheckBox2.Checked then
  begin
    if RegCreateKeyEx(HKEY_CLASSES_ROOT, '.l', 0, nil, REG_OPTION_NON_VOLATILE,
                      KEY_ALL_ACCESS, nil, Key, @Disposition) = ERROR_SUCCESS then
    begin
      Entry := 'DCG.LexerFile';
      RegSetValueEx(Key, '', 0, REG_SZ, PChar(Entry), Length(Entry));
      RegCloseKey(Key);
    end;
    if RegCreateKeyEx(HKEY_CLASSES_ROOT, 'DCG.LexerFile', 0, nil, REG_OPTION_NON_VOLATILE,
                      KEY_ALL_ACCESS, nil, Key, @Disposition) = ERROR_SUCCESS then
    begin
      Entry := 'DCG Lexical Description';
      RegSetValueEx(Key, '', 0, REG_SZ, PChar(Entry), Length(Entry));
      if RegCreateKeyEx(Key, 'DefaultIcon', 0, nil, REG_OPTION_NON_VOLATILE,
                        KEY_ALL_ACCESS, nil, SubKey, @Disposition) = ERROR_SUCCESS then
      begin
        Entry := Application.ExeName + ', 2';
        RegSetValueEx(SubKey, '', 0, REG_SZ, PChar(Entry), Length(Entry));
        RegCloseKey(SubKey);
      end;
      if RegCreateKeyEx(Key, 'Shell\open\command', 0, nil, REG_OPTION_NON_VOLATILE,
                        KEY_ALL_ACCESS, nil, SubKey, @Disposition) = ERROR_SUCCESS then
      begin
        RegSetValueEx(SubKey, '', 0, REG_SZ, PChar(Association), Length(Association));
        RegCloseKey(SubKey);
      end;
      RegCloseKey(Key);
    end;
  end;
  :
end;

1) A key is created under HKEY_CLASSES_ROOT with name '.l'
2) It's default value (without a name) becomes 'DCG.LexerFile' (which is just a string to be used to identify the next key)
3) A key is created with name 'DCG.LexerFile' (just the string entered in the default value in step 2).
4) The default value is set to the description of the file type (this one is shown in the explorer)
5) A subkey is created with name 'DefaultIcon' which gets as default entry a path to the aplication along with an index of which icon is actually to be used
6) Another subkey is created (actually a chain of subkeys in one call, as only the last one is really needed)
7) This key gets as default entry the command line to start the application with the file when the user double-clicked it (note the format of the string, as it prevents Windows from sending short names)

Ciao, Mike
0
 
jonassondanielAuthor Commented:
Thank you!
0
 
LischkeCommented:
I knew this would happen. Why have I supplied the answer, I'm bloody dumb!!!

jonassondaniel, have you looked where you gave the answer??? Sometimes E-E makes me ill.

Ciao, Mike


0
All Courses

From novice to tech pro — start learning today.