Buscar

Adicionar sua aplicação ao menu de contexto

Código

{Veja como criar um menu de contexto que abre sua aplicacão quando o usuario clica o botão direito sobre um arquivo.}

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;


 
 

Publicidade

Vote na dica




Quantidade de votos: 0 votos
Aceitação: 0%


Detalhes da dica

Categoria: Componentes
Adicionada dia: 05/01/06
Por: Joaquim Estevam De Araujo Neto
Visualizada: 4754 vezes

Planeta Delphi - Tudo sobre programação Delphi Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009