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!
How to use explorer context for your tool |
Post Reply |
Author | |
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
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 |
|
delphiide
Beginner Joined: 06 Mar 15 Location: Algeria Status: Offline Points: 1 |
Post Options
Thanks(0)
|
for more pro, you can use ShellPlus components
|
|
...
Delphi IDE Blog! http://delphiide.blogspot.com |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store