• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

how to add an option in the right click menu

hello, i have a program that encrypt a file u select (with opendialog1)  but i would like to add an option to the explorer menu u get when u right click a file or folder.
i found this already:

procedure TForm1.Button1Click(Sender: TObject);  
procedure InstalaMenuContextual( Extension,Comando,CaptionMenu  :string);
   var
     Registro : TRegistry;
     Nombre   : string;
   begin
     Registro := TRegistry.Create;
     try
       Registro.RootKey := HKEY_CLASSES_ROOT;
       if Registro.OpenKeyReadOnly('\.' + Extension) then
       begin
         Nombre := Registro.ReadString('');
         if Nombre <> '' then
           if Registro.OpenKey('\' + Nombre + '\shell', False) then
             Registro.Access := KEY_READ or KEY_WRITE;
         if Registro.OpenKey('APTprocess', True) then
         begin
           Registro.WriteString('', CaptionMenu);
           Registro.Access := KEY_READ or KEY_WRITE;
           if Registro.OpenKey('command', True) then
             Registro.WriteString('','"'+Comando+'" "%1"');
         end;
       end else Raise Exception.create('Lo siento, la extension no es conocida por Windows');
     finally
       Registro.Free;
     end;
   end;

begin

   InstalaMenuContextual( 'TST',
                          Application.ExeName,
                          'blabla');
end;

but this only will work for that extension, not for all files and of course it only calls my program, i also need my program to handle the files selected automatically.
i need to encrypt those files i select, so i would need my program to take those parameters.
like an antivirus software, u choose a bunch of files then click the option in the right click menu and it scans all the files u selected.
and if a folder is selected, it will encrypt all files in the folder.
just like an antivirus would do.

so ill be waiting for some code or hints.
0
manganzon
Asked:
manganzon
1 Solution
 
heretoreadCommented:
This will register for all file types,

procedure RegisterMenu;
var
  Reg:TRegistry;
begin
  Reg:= TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  Reg.OpenKey('*\shell\Program...\command', True);
  Reg.WriteString('', '"'+ParamStr(0)+'" "%1"');
  Reg.Free;
end;

procedure UnRegisterMenu;
var
  Reg:TRegistry;
begin
  Reg:= TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  Reg.OpenKey('*\shell', true);
  Reg.DeleteKey('Program...');
  Reg.Free;
end;

But note, If you select multiple files then use the explorer menu, explorer will open your program for each file selected.

have a look at contmenu.dpr in the Program Files\Borland\Delphi\Demos\ActiveX\ShellExt folder. Thats a better way to make an explorer menu.
0
 
pilotzCommented:
i think this could help you: http://windowsxp.mvps.org/context_folders.htm
0
 
manganzonAuthor Commented:
sorry, i got busy with another project but anyway, the main problem is to handle the files u select before u click on the explorer button.
so if i have a function: encrypt(file);
it will just use that function to deal with all the files that were selected in explorer before my application was called.
how can get the name(s) of the file(s) selected in order to process them afterwards.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
D-MasterCommented:
you should  check the params of your app and execute function according to the params..

let assume your app name is ENCRYPT.exe the params may look like this
c\>ENCRYPT.exe -e somefile.txt

paramstr[0] is your app name {ENCRYPT.exe}
paramstr[1] is the parameter for encryption {-e}
paramstr[2] is the filename {somefile.txt}

just from mind...try it
0
 
manganzonAuthor Commented:
yea i already knew i had to use paramstr(1) for the file to be encrypted, but what if there are many files selected?
0
 
D-MasterCommented:
windows will treat each selected file as it is the only one selected.... and run you program as many times as the number of the selected files...so make you program to prevent more than one instance....then you'll see all the selected files opened in one instance....

0
 
manganzonAuthor Commented:
good enough.
:D
0
 
D-MasterCommented:
;-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now