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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TMillerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.