Author: Tomas Rutkauskas
How do I create a file association for my win32 application (Update for
98/ME/NT5(2000)/ME) ?
Answer:
In Win32, create a new registry entry under the HKEY_CLASSES_ROOT root key that
points to the file extension, the command line to invoke, and the icon to display.
Update:
Windows will execute '\shell\open\command' from the KEY pointed in (Default) value.
So you can :
Clear Default value of extention key with itself ex: .jpg -> .jpg. This make
windows use '\shell\open\command' from the proper KEY. (As shown in example)
Create enother key like "MyProgExt" with '\shell\open\command' and point any
extension you need to it. This way the extension key default value will be:
MyProgExt.
Example:
1 uses Registry,
2 3 procedure TForm1.FileFormatAssociations;
4 var5 reg: TRegistry;
6 FileExt: string;
7 begin8 reg := TRegistry.Create;
9 reg.RootKey := HKEY_CLASSES_ROOT;
10 reg.LazyWrite := false;
11 12 FileExt := '.jpg';
13 14 //Clear Key - This is important !!!15 reg.OpenKey(FileExt, true);
16 reg.WriteString('', FileExt);
17 reg.CloseKey;
18 19 //Invoke the program passing the file name as the first parameter20 reg.OpenKey(FileExt + '\shell\open\command', true);
21 reg.WriteString('', Application.ExeName + ' "%1"');
22 reg.CloseKey;
23 24 //Use the first icon in the executable to display25 reg.OpenKey(FileExt + '\DefaultIcon', true);
26 reg.WriteString('', Application.ExeName + ',0');
27 reg.CloseKey;
28 29 reg.free;
30 end;