AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Kontextmenü macht Schwierigkeiten :(
Thema durchsuchen
Ansicht
Themen-Optionen

Kontextmenü macht Schwierigkeiten :(

Ein Thema von stiftII · begonnen am 15. Okt 2009 · letzter Beitrag vom 15. Okt 2009
Antwort Antwort
stiftII

Registriert seit: 2. Sep 2009
Ort: Cuxhaven
122 Beiträge
 
#1

Kontextmenü macht Schwierigkeiten :(

  Alt 15. Okt 2009, 02:02
Hallo zusammen.

Ich hoffe ihr könnt mir helfen .

Ich Probiere schon seit Stunden Die Kontextmenüeinträge für Grafikdateien so zu ändern(Rechtsclick auf Grafik), sodass sie um einen Eintrag erweitert werden.

Ich hab dafür den "Demos/ActiveX/Shellext" Code angepasst.

Die Änderungen in der Registry werden vorgenommen, aber der Neue Menüeintrag erscheint nicht . Hier ist der Code meiner dll.

Bin für jeden Tipp dankbar.

Delphi-Quellcode:
unit ContextM2;

interface

uses
  Windows, ActiveX, ComObj, ShlObj, Dialogs,Registry;

type
  TContextMenu = class(TComObject, IShellExtInit, IContextMenu)
  private
    FFileName: array[0..MAX_PATH] of Char;
  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 = '{D4B97850-9199-476A-9673-7A269278D226}';

implementation

uses ComServ, SysUtils, ShellApi;

function TContextMenu.SEIInitialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
  hKeyProgID: HKEY): HResult;
var
  StgMedium: TStgMedium;
  FormatEtc: TFormatEtc;
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
    Exit;
  // If only one file is selected, retrieve the file name and store it in
  // FFileName. Otherwise fail the call.
  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

    ShowMessage('Adding ONE item');
    InsertMenu(Menu, indexMenu, MF_STRING or MF_BYPOSITION, idCmdFirst, '-> Upload Image');

    // Return number of menu items added
    Result := 1; // or use MakeResult(SEVERITY_SUCCESS, FACILITY_NULL, 1)
  end;
end;


function TContextMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
resourcestring
  sPathError = 'Error setting current directory';

var
  H: THandle;
  PrevDir: string;
regist: TRegistry;
begin

  regist:=TRegistry.Create;

    regist.RootKey:=HKEY_LOCAL_MACHINE;
    regist.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\666kb.exe', true);

  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
  // by invoking the Delphi command line compiler.
  PrevDir := GetCurrentDir;
  try
    if not SetCurrentDir(ExtractFilePath(FFileName)) then
      raise Exception.CreateRes(@sPathError);
    //H := WinExec(PChar(Format(GetCompilerPath, [FFileName])), lpici.nShow);
    //ShowMessage(Pchar(regist.ReadString('')+' '+ExtractFilePath(FFileName)+ExtractFileName(FFileName)));
    H := WinExec(Pchar(regist.ReadString('')+' "'+ExtractFilePath(FFileName)+ExtractFileName(FFileName)+'"'), lpici.nShow);

    if (H < 32) then
      MessageBox(lpici.hWnd, 'Error', 'Error',
        MB_ICONERROR or MB_OK);

    Result := NOERROR;
  finally
    SetCurrentDir(PrevDir);
  end;
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, 'Compile the selected Delphi project');
    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);

    // Die Shell-Erweiterung wird hier für Ordner (Folder) registriert
    // Der Text DFKontextMenu ist frei wählbar und charakterisier die eigene Erweiterung
    //CreateRegKey('Folder\shellex', '', '');
    //CreateRegKey('Folder\shellex\ContextMenuHandlers', '', '');
    //CreateRegKey('Folder\shellex\ContextMenuHandlers\DFKontextMenu', '', ClassID);

    //Die Shell-Erweiterung wird hier für alle Dateien registriert
    // ansonsten muss statt des Sterns (alle Dateien) die konkrete Dateiendung
    // stehen, z. B. '.zip'
    // Der Text DFKontextMenu ist frei wählbar und charakterisier die eigene Erweiterung

    CreateRegKey('.jpg\shellex', '', '');
    CreateRegKey('.jpg\shellex\ContextMenuHandlers', '', '');
    CreateRegKey('.jpg\shellex\ContextMenuHandlers\ContMenu', '', ClassID);

    CreateRegKey('.jpeg\shellex', '', '');
    CreateRegKey('.jpeg\shellex\ContextMenuHandlers', '', '');
    CreateRegKey('.jpeg\shellex\ContextMenuHandlers\ContMenu', '', ClassID);

    CreateRegKey('.gif\shellex', '', '');
    CreateRegKey('.gif\shellex\ContextMenuHandlers', '', '');
    CreateRegKey('.gif\shellex\ContextMenuHandlers\ContMenu', '', ClassID);

    CreateRegKey('.png\shellex', '', '');
    CreateRegKey('.png\shellex\ContextMenuHandlers', '', '');
    CreateRegKey('.png\shellex\ContextMenuHandlers\ContMenu', '', ClassID);

    CreateRegKey('.bmp\shellex', '', '');
    CreateRegKey('.bmp\shellex\ContextMenuHandlers', '', '');
    CreateRegKey('.bmp\shellex\ContextMenuHandlers\ContMenu', '', ClassID);

    // Shell-Erweiterung als "genehmigt" eintragen
    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, 'ContMenu');
        finally
          Free;
        end;
  end
  else
  begin
    // wird die Shell-Erweiterung wieder entfernt, werden die Einträge der
    // Registrierung gelöscht

    //hier wird dann irgendwann alles gelöscht *__*
    inherited UpdateRegistry(Register);
  end;
end;

initialization
  TContextMenuFactory.Create(ComServer, TContextMenu, Class_ContextMenu,
    '', 'Delphi Context Menu Shell Extension Example', ciMultiInstance,
    tmApartment);
end.
  Mit Zitat antworten Zitat
Benutzerbild von Sherlock
Sherlock

Registriert seit: 10. Jan 2006
Ort: Offenbach
3.763 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: Kontextmenü macht Schwierigkeiten :(

  Alt 15. Okt 2009, 09:18
Dein COM-Objekt hast Du auch registriert?

Sherlock
Oliver
  Mit Zitat antworten Zitat
Kalfany

Registriert seit: 28. Feb 2008
Ort: München
153 Beiträge
 
Delphi 2007 Professional
 
#3

Re: Kontextmenü macht Schwierigkeiten :(

  Alt 15. Okt 2009, 10:37
Für welche Windows Version ist das denn? Ab Vista hat sich da nämlich irgendwas geändert (kann aber auch sein das ich das mit den Spalten im Explorer verwechsle)
  Mit Zitat antworten Zitat
stiftII

Registriert seit: 2. Sep 2009
Ort: Cuxhaven
122 Beiträge
 
#4

Re: Kontextmenü macht Schwierigkeiten :(

  Alt 15. Okt 2009, 10:48
Hmn, ich denke mal das sollte für alle Windows Versionen gehen.

Kern des Programmes ist ja:

Delphi-Quellcode:
    CreateRegKey('.jpeg\shellex', '', '');
    CreateRegKey('.jpeg\shellex\ContextMenuHandlers', '', '');
    CreateRegKey('.jpeg\shellex\ContextMenuHandlers\ContMenu', '', ClassID);
Die Schlüssel werden auch erstellt, nur der Kontextmenü eintrag nicht.

@ Sherlock: Ich hab die dll mit regsvr32 geladen.

~stift
  Mit Zitat antworten Zitat
stiftII

Registriert seit: 2. Sep 2009
Ort: Cuxhaven
122 Beiträge
 
#5

Re: Kontextmenü macht Schwierigkeiten :(

  Alt 15. Okt 2009, 12:55
Problem gelöst:

Delphi-Quellcode:
CreateRegKey('.jpeg', '', '');
   CreateRegKey('.jpeg\shellex', '', '');
    CreateRegKey('.jpeg\shellex\ContextMenuHandlers', '', '');
    CreateRegKey('.jpeg\shellex\ContextMenuHandlers\ContMenu', '', ClassID);
Wenn man den Default reg key überschreibt geht es, ich weiß allerdings nicht was das für Folgen hat.

Jemand ne Idee ?.

~stift
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz