Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Register filetype in windows registry

Posted on 1999-06-30
5
Medium Priority
?
530 Views
Last Modified: 2008-11-21
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)
0
Comment
Question by:jonassondaniel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
TMiller earned 200 total points
ID: 1385397
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
 

Author Comment

by:jonassondaniel
ID: 1385398
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
 
LVL 10

Expert Comment

by:Lischke
ID: 1385399
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
 

Author Comment

by:jonassondaniel
ID: 1385400
Thank you!
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1385401
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question