Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "KOL";
Текущий архив: 2005.08.07;
Скачать: [xml.tar.bz2];

Вниз

KOL and ContextMenu shel extension   Найти похожие ветки 

 
Boguslaw   (2005-01-05 00:10) [0]

Is there any example how to write ContextMenuHandler shell extension in KOL ?


 
thaddy   (2005-01-05 11:02) [1]

You can use kolactiveX/kolactivedll example as a basis.


 
Boguslaw   (2005-01-06 17:41) [2]

OK. Below is ContextMenuHandler simple shell extension.
Could somebody help me port this to KOL ? Should be no problem, only Registry,SySUtils and ComServ units used besides common.

Is ComServ unit ported to KOL ?

P.S. Sorry,I hate COM but must use it.
Anyway I"m writing simple antivirus with KOL GUI.
Are You interested in this project (GPL license) ?

*******************************
unit shellunt;

interface

uses
  Windows, ActiveX, ComObj, ShlObj;

type
  TContextMenu = class(TComObject, IShellExtInit, IContextMenu)
  private
     FFileName: array[0..MAX_PATH] of Char;
     FFileNameList: String;
  protected
     { IShellExtInit }
     function IShellExtInit.Initialize = SEIInitialize; // Avoid compiler warning
     function SEIInitialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
       hKeyProgID: HKEY): HResult; stdcall;
     { IContextMenu }
     function QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst, idCmdLast,
       uFlags: UINT): HResult; stdcall;
     function InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; stdcall;
     function GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
       pszName: LPSTR; cchMax: UINT): HResult; stdcall;
  end;

const
  Class_ContextMenu: TGUID = "{E15E69D0-E84D-4A69-9E3C-51839D60C9C2}";

implementation

uses ComServ, SysUtils, ShellApi, Registry;

function TContextMenu.SEIInitialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
  hKeyProgID: HKEY): HResult;
var
  StgMedium: TStgMedium;
  FormatEtc: TFormatEtc;
  Count, Loop: Byte;
begin
  // Fail the call if lpdobj is Nil.
  if (lpdobj = nil) then begin
     Result := E_INVALIDARG;
     Exit;
  end;

  with FormatEtc do begin
     cfFormat := CF_HDROP;
     ptd := nil;
     dwAspect := DVASPECT_CONTENT;
     lindex := -1;
     tymed := TYMED_HGLOBAL;
  end;

  // Render the data referenced by the IDataObject pointer to an HGLOBAL
  // storage medium in CF_HDROP format.
  Result := lpdobj.GetData(FormatEtc, StgMedium);
  if Failed(Result) then
  begin
     Exit;
  end;
  // File(s) is selected, retrieve the file name and store it in FFileName.
  // FFileNameList Soters the List of files.
  if (DragQueryFile(StgMedium.hGlobal, $FFFFFFFF, nil, 0) > 0) then begin
     Count := DragQueryFile(StgMedium.hGlobal, $FFFFFFFF, nil, 0);
     for Loop := 0 to Count - 1 do begin
       DragQueryFile(StgMedium.hGlobal, Loop, FFileName, SizeOf(FFileName));
       FFileNameList := FFileNameList + FFileName+ "*";
     end;
     //      if (DragQueryFile(StgMedium.hGlobal, $FFFFFFFF, nil, 0) = 1) then begin
     //      DragQueryFile(StgMedium.hGlobal, 0, FFileName, SizeOf(FFileName));
     Result := NOERROR;
  end
  else begin
     FFileName[0] := #0;
     Result := E_FAIL;
  end;
  ReleaseStgMedium(StgMedium);
end;

function TContextMenu.QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst,
  idCmdLast, uFlags: UINT): HResult;
begin
  Result := 0; // or use MakeResult(SEVERITY_SUCCESS, FACILITY_NULL, 0);

  if ((uFlags and $0000000F) = CMF_NORMAL) or
     ((uFlags and CMF_EXPLORE) <> 0) then begin
     // Add one menu item to context menu
     InsertMenu(Menu, indexMenu, MF_STRING or MF_BYPOSITION, idCmdFirst,"&Skanuj za pomoc&#261; programu ThunderClam AV");
     // Return number of menu items added
     Result := 1; // or use MakeResult(SEVERITY_SUCCESS, FACILITY_NULL, 1)
  end;
end;

function GetProgramPath: string;
// Returns string containing path to ThunderClam
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
     with Reg do begin
       RootKey := HKEY_LOCAL_MACHINE;
       OpenKey("\SOFTWARE\ThunderClam\Configuration", False);
       Result := ReadString("App");
     end;
     if AnsiPos(" ", Result) <> 0 then
//        Result := ExtractShortPathName(Result);
       Result := Result + " "%s"";
  finally
     Reg.Free;
  end;
end;

function TContextMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
var
  H: THandle;
begin
  Result := E_FAIL;
  // Make sure we are not being called by an application
  if (HiWord(Integer(lpici.lpVerb)) <> 0) then
  begin
     Exit;
  end;
  // Make sure we aren"t being passed an invalid argument number
  if (LoWord(lpici.lpVerb) <> 0) then begin
     Result := E_INVALIDARG;
     Exit;
  end;

  // Execute the command specified by lpici.lpVerb
     H := WinExec(PChar(Format(GetProgramPath, [FFileNameList])), lpici.nShow);
     if (H < 32) then
       MessageBox(lpici.hWnd, "Nie mo&#380;na uruchomi&#263; ThunderClam AV.", "B&#322;&#261;d",
          MB_ICONERROR or MB_OK);
  Result := NOERROR;
end;

function TContextMenu.GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
  pszName: LPSTR; cchMax: UINT): HRESULT;
begin
  if (idCmd = 0) then begin
     if (uType = GCS_HELPTEXT) then
  // return help string for menu item
  StrCopy(pszName, "Skanowanie antywirusowe u&#380;ywaj&#261;c programu ThunderClam AV");
 Result := NOERROR;
end
else
 Result := E_INVALIDARG;
end;

type
  TContextMenuFactory = class(TComObjectFactory)
  public
     procedure UpdateRegistry(Register: Boolean); override;
  end;

procedure TContextMenuFactory.UpdateRegistry(Register: Boolean);
var
  ClassID: string;
begin
  if Register then begin
     inherited UpdateRegistry(Register);

     ClassID := GUIDToString(Class_ContextMenu);
     CreateRegKey("*\shellex", "", "");
     CreateRegKey("*\shellex\ContextMenuHandlers", "", "");
     CreateRegKey("*\shellex\ContextMenuHandlers\ContMenu", "", ClassID);
     CreateRegKey("Folder\shellex", "", "");
     CreateRegKey("Folder\shellex\ContextMenuHandlers", "", "");
     CreateRegKey("Folder\shellex\ContextMenuHandlers\ContMenu", "", ClassID);

     if (Win32Platform = VER_PLATFORM_WIN32_NT) then
       with TRegistry.Create do
       try
          RootKey := HKEY_LOCAL_MACHINE;
          OpenKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions", True);
          OpenKey("Approved", True);
          WriteString(ClassID, "ThunderClam Context Menu Shell Extension");
       finally
          Free;
       end;
  end
  else begin
     DeleteRegKey("*\shellex\ContextMenuHandlers\ContMenu");
     DeleteRegKey("*\shellex\ContextMenuHandlers");
     DeleteRegKey("*\shellex");
     DeleteRegKey("Folder\shellex\ContextMenuHandlers\ContMenu");
     DeleteRegKey("Folder\shellex\ContextMenuHandlers");
     DeleteRegKey("Folder\shellex");

     inherited UpdateRegistry(Register);
  end;
end;

initialization
  TContextMenuFactory.Create(ComServer, TContextMenu, Class_ContextMenu,
     "", "ThunderClam Context Menu Shell Extension", ciMultiInstance,
          tmApartment);
end.



Страницы: 1 вся ветка

Форум: "KOL";
Текущий архив: 2005.08.07;
Скачать: [xml.tar.bz2];

Наверх




Память: 0.48 MB
Время: 0.033 c
14-1121298969
Михаил(Киров)
2005-07-14 03:56
2005.08.07
Администрирование компьютерных клубов


14-1121727655
kaif
2005-07-19 03:00
2005.08.07
А у нас есть такая организация? В США - есть.


4-1118150718
Юрий Ж.
2005-06-07 17:25
2005.08.07
Пульт ДУ + ИК-порт


14-1121262043
Андрей Жук
2005-07-13 17:40
2005.08.07
Проект развивается :)


3-1120043176
Тучудище
2005-06-29 15:06
2005.08.07
Когда лучше подтверждать транзакции





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский