Link to home
Start Free TrialLog in
Avatar of fidel83
fidel83

asked on

explorer context menu

Hi,

I got a TListview that shows a list of files. I want to be able to right-click one of the files and have a context menu displayed. (like in explorer).

So if for example you right-click an mp3, then it has 'Play in winamp', 'Enqueue in winamp', Delete, Cut, Properties etc.
ASKER CERTIFIED SOLUTION
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fidel83
fidel83

ASKER

hey slayer,

i could not get the code to run. Could you please give me some parameters to call it with?





procedure DisplayContextMenu(DisplayHandle, ExecuteHandle: THandle; P: TPoint; ShellFolder: IShellFolder; PIDLCount: Integer; var PIDL: PItemIDList; var ContextMenu2: IContextMenu2; RenameItem: Boolean = True; ExecuteCommand: TExecuteCommand = nil);
var Result: HResult;
 PopupMenu: HMenu;
 Cmd: Cardinal;
 ICM: TCMInvokeCommandInfo;
 ContextMenu: IContextMenu;
 Verb: string;
 uFlags: UInt;
 ErrorMode: Word;
 Execute: Boolean;
begin
 if RenameItem then uFlags := CMF_EXPLORE or CMF_CANRENAME
 else uFlags := CMF_EXPLORE;
 PopupMenu := CreatePopupMenu;
 try
   Result := ShellFolder.GetUIObjectOf(ExecuteHandle, PIDLCount, PIDL, IID_IContextMenu, nil, Pointer(ContextMenu));
   if Result = 0 then
   begin
     Result := ContextMenu.QueryInterface(IID_IContextMenu2, ContextMenu2);
     ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
     try
       if Result = 0 then
         ContextMenu2.QueryContextMenu(PopupMenu, 0, 1, $7FFF, uFlags)
       else
         ContextMenu.QueryContextMenu(PopupMenu, 0, 1, $7FFF, uFlags);
     finally
       SetErrorMode(ErrorMode);
     end;
     Cmd := Cardinal(TrackPopupMenuEx(PopupMenu, TPM_LEFTALIGN or TPM_RIGHTBUTTON or TPM_RETURNCMD, P.X, P.Y, DisplayHandle, nil));
     if Cmd > 0 then
     begin
       SetLength(Verb, 255);
       if ContextMenu2 <> nil then ContextMenu2.GetCommandString(Cardinal(MakeIntResource(Cmd - 1)), GCS_VERB, nil, PChar(Verb), length(Verb))
       else ContextMenu.GetCommandString(Cardinal(MakeIntResource(Cmd - 1)), GCS_VERB, nil, PChar(Verb), length(Verb));
       SetLength(Verb, strlen(PChar(Verb)));
     end;
   end;
 finally
   DestroyMenu(PopupMenu);
 end;
end;
hi fidel,

you can't just use the above immediately because I cut it out from a much larger programme... but just look at how I use the IContextMenu2 interface's various procedures.