Quote
"Bert" <i...@prinsoft.webprovider.com> wrote in message news:9041DC7AFPrinSoft@212.187.36.58...
> Not specialy a Delphi question, but.....
> My Delphi-application creates files and I want them associated with that
> application (in the registry), but I don't know how to do that. Maybe one
> of you can help me?
-----------------------------------------------------------------------
This solution is brought to you by Joe Hecht's TExcellent products,
solving Form.Print and bitmap printing problems. Joe Hecht's TExcellent
products can be found at: www.code4sale.com/joehecht/index.htm
-----------------------------------------------------------------------
Q) How do I create a file association for my application?
A) 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. Under Win16, simply
file extension and the command line to invoke in the [Extensions] sections of Win.ini.
Example:
uses
Registry, {For Win32}
IniFiles; {For Win16}
{For Win32}
procedure TForm1.Button1Click(Sender: TObject);
var
reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
reg.LazyWrite := false;
{Add Program Support}
reg.OpenKey('.bor\shell\open\command',
true);
{Invoke the program passing the file name as the first parameter}
reg.WriteString('',
'C:\Program Files\Borland\Delphi 3\Project1.exe %1');
{Add Icon Display}
reg.CloseKey;
reg.OpenKey('.bor\DefaultIcon',
true);
{Use the first icon in the executable to display}
reg.WriteString('',
'C:\Program Files\Borland\Delphi 3\Project1.exe,0');
reg.CloseKey;
reg.free;
end;
{For Win16}
procedure TForm1.Button2Click(Sender: TObject);
var
WinIni : TIniFile;
WinIniFileName : array[0..MAX_PATH] of char;
s : array[0..64] of char;
begin
GetWindowsDirectory(WinIniFileName, sizeof(WinIniFileName));
StrCat(WinIniFileName, '\win.ini');
WinIni := TIniFile.Create(WinIniFileName);
WinIni.WriteString('Extensions',
'bor',
'C:\PROGRA~1\BORLAND\DELPHI~1\PROJECT1.EXE ^.bor');
WinIni.Free;
StrCopy(S, 'Extensions');
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@S));
end;