Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - How to use explorer context for your tool
  FAQ FAQ  Forum Search   Register Register  Login Login

How to use explorer context for your tool

 Post Reply Post Reply
Author
Message
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Topic: How to use explorer context for your tool
    Posted: 17 Nov 12 at 1:29PM
Hi!


I can answer regarding Delphi/Pascal.
First i give you the needed functions and at the end you'll find code how to use it.

Don't forget ShlObj and Registry in the usage section.


function RegisterFileAssociation( FileAssocInfo : TFileAssocInfo):boolean;

  {-----------------------------------------------------}
  function IsEmptyString(const S: string): boolean;
  begin
  Result := ( S = '' );
  end;
  {-----------------------------------------------------}
  function AssebleOpenCmd(OpenCmd, AppPath:string):string;
  begin
    OpenCmd := Trim(OpenCmd);
    if not IsEmptyString(OpenCmd) then OpenCmd := OpenCmd + ' ';
    Result := AppPath + ' ' + OpenCmd + '%1';
  end;
  {-----------------------------------------------------}

var
S : string;
begin

  Result := False;

  with  FileAssocInfo do
  begin
    if IsEmptyString(AppPath) then Exit;
    if IsEmptyString(Extension) then Exit;
    if Length(Extension) > 3 then raise Exception.Create('Too long extension');
    if IsEmptyString(Key) then Exit;
    if IsEmptyString(Description) then Exit;
    if AddLocalMenu and IsEmptyString(MenuString) then Exit;

    Extension := '.' + Extension;


    { write... }
    with TRegIniFile.Create('') do
    try
      RootKey := HKEY_CLASSES_ROOT;

      { write the extension - the Key points to description registy key}
      WriteString(Extension, '', Key);

      { write the description key }
      WriteString(Key, '', Description);

      { write the default icon if defined }
      if not IsEmptyString(Icon) then WriteString(Key + '\DefaultIcon','',Icon);

      { write the OpenCmd - association }
      OpenCmd := AssebleOpenCmd(OpenCmd, AppPath);
      WriteString(Key + '\shell\open\command', '', OpenCmd );

      { add the Explorer local menu item }
      if AddLocalMenu
      then
        begin
          S := Key + '\shell\' + 'Local_Menu';
          WriteString(S, '', MenuString);
          S := Key + '\shell\' + 'Local_Menu' + '\command';
          WriteString(S, '', OpenCmd);
        end;

    finally
      CloseKey;
      Free;
    end;

  end;

  Result := True;

end;

procedure DeleteFileAssociation(Extension, Key:string);
begin
  with TRegIniFile.Create('') do
  try
    RootKey := HKEY_CLASSES_ROOT;
    EraseSection('.' + Extension);
    EraseSection(Key);
  finally
    CloseKey;
    Free;
  end;
end;

procedure CreateSendToShortcut;
var
   UK : IUnknown;
   ShLnk : IShellLink;
   PF: IPersistFile;
   Shortcut: string;
   pIDL :pItemIDList;
   Buffer: array[0..MAX_PATH]of char;
   Malloc: IMalloc;
begin
   SHGetSpecialFolderLocation(0, CSIDL_SENDTO, pidl);
   ShGetPathFromIdList(pIDL, PChar(@Buffer));
   Shortcut:= Buffer;
   OLECheck(SHGetMalloc(Malloc));
   if pidl <> nil then Malloc.Free(pIDL);
   Shortcut:=Shortcut+'\'+Application.Title+'.lnk';
   CoInitialize(nil);
   UK := CreateComObject(CLSID_ShellLink);
   ShLnk := UK as IShellLink;
   PF := UK as IPersistFile;
   ShLnk.SetPath(pChar(Application.ExeName));
   PF.Save(PWChar(WideString(Shortcut)), False);
   CoUninitialize;
end;  


// ------------------------------


//  How to set your item directly into the explorer-context:
//  anywhere via buttonclick or anything else...

    with FileAssocInfo do
        begin
           AppPath        := Application.ExeName;
           Extension      := 'PDF';
           Key            := 'Your:tool_name';
           Description    := 'PDF Your_tool_name';
           AddLocalMenu   := True;
           MenuString     := 'working with my pdf-tool!';
           OpenCmd        := '';
           Icon           := '';
        end;
    RegisterFileAssociation(FileAssocInfo);

//  How to remove your item from the explorer-context:
//  anywhere via buttonclick or anything else...

    DeleteFileAssociation('PDF', 'Your_tool_name');

//  How to insert your item directly into the explorer-context:
//  anywhere via buttonclick or anything else...

    CreateSendToShortcut;

//  How to remove your send-to-item from the explorer-context:
//  anywhere via buttonclick or anything else...

    filename := Application.Title+'.lnk';
    SHGetSpecialFolderLocation(Form1.Handle, CSIDL_SENDTO, SFolder);
    SHGetPathFromIDList(SFolder, SpecialPath);
    deletefile(strpas(Specialpath)+'\'+ filename);


Cheers Ingo

Back to Top
delphiide View Drop Down
Beginner
Beginner
Avatar

Joined: 06 Mar 15
Location: Algeria
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote delphiide Quote  Post ReplyReply Direct Link To This Post Posted: 06 Mar 15 at 9:58PM
for more pro, you can use ShellPlus components
...
Delphi IDE Blog!
http://delphiide.blogspot.com
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store