Código
Procedure AddContextMenu;
type extns = (wav, png, bmp, jpg);
const ext_names: array[extns] of string = ('.wav', '.png', '.bmp', '.jpg');
var ext: extns;
reg: TRegistry;
name: string;
command: string;
AppPath: String;
MenuTitle:String;
begin
AppPath := Application.ExeName; { Diretorio e Nome da aplicação }
MenuTitle := 'Minha Aplicação'; { Titulo do Menu }
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
{Build the command string we want to store}
command := '"' + AppPath + '" "%1"';
{Loop over extensions we can handle}
for ext := wav to jpg do begin
{See if this extension is already known in HKEY_CLASSES_ROOT}
if reg.OpenKeyReadOnly ('\' + ext_names [ext]) then begin
name := reg.ReadString (''); {Get the name of this type}
if name <> '' then Begin
{If not blank, open this type's shell key, but don't create it}
if reg.OpenKey('\' + name + '\shell', False) then Begin
{Try to create a new key called "APTprocess". Note that for Delphi5 we
need to set the access explicitly}
reg.Access := KEY_READ or KEY_WRITE;
if reg.OpenKey(MenuTitle, True) then begin
{The default value will be displayed in the context menu}
reg.WriteString('', MenuTitle);
{So now open the command key, creating it if required}
reg.Access := KEY_READ or KEY_WRITE;
if reg.OpenKey('command', True) then Begin
{and write the command string as the default value}
reg.WriteString('', command);
End;
end;
End;
End;
end;
end;
reg.Free;
end;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009