...einen Menueeintrag zu einer Datei registrieren?
Autor: Steffen Schirmer
uses
Registry;
procedure AddFileMenue(FilePrefix, Menue, Command: string);
var
reg: TRegistry;
typ: string;
begin
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_CLASSES_ROOT;
OpenKey('.' + FilePrefix, True);
typ := ReadString('');
if typ = '' then
begin
typ := Fileprefix + 'file';
WriteString('', typ);
end;
CloseKey;
OpenKey(typ + '\shell\' + Menue + '\command', True);
WriteString('', command + ' "%1"');
CloseKey;
Free;
end;
end;
procedure DeleteFileMenue(Fileprefix, Menue: string);
var
reg: TRegistry;
typ: string;
begin
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_CLASSES_ROOT;
OpenKey('.' + Fileprefix, True);
typ := ReadString('');
CloseKey;
OpenKey(typ + '\shell', True);
DeleteKey(Menue);
CloseKey;
Free;
end;
end;
{ Example / Beispiel:}
procedure TForm1.Button1Click(Sender: TObject);
begin
{ Register the Menuepoint: }
AddFileMenue('rtf', 'Edit with Notepad', 'C:\Windows\system\notepad.exe');
{
If you now click with the right mousebutton on a *.rtf-file then
you can see a Menuepoint: "Edit with Notepad".
When Click on that point Notepad opens the file.
Wenn man nun mit der rechten Maustaste im Explorer auf eine *.rtf-Datei Clickt,
dann erscheint dort der Menuepunkt "Edit with Notepad".
Beim Clicken darauf, öffnet Notepad diese Datei.
}
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
{
Unregister the Menuepoint / Undo your changes in the Registry:
Löscht den Menuepunkt wieder aus der Registry:
}
DeleteFileMenue('rtf', 'Edit with Notepad');
end;
printed from
www.swissdelphicenter.ch
developers knowledge base