Delphi - база знаний

       

Как зарегистрировать свой пункт в меню для моего типа файлов?


Как зарегистрировать свой пункт в меню для моего типа файлов?





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

Взято с сайта



Содержание раздела