Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.184 Beiträge
 
Delphi 12 Athens
 
#2

Re: Kontextmenü des Explorers anzeigen

  Alt 26. Aug 2009, 18:26
irgendwo in der DP dürften sich auch noch die Originalcodes rumliegen, aus welchen ich dieses mal erstellt hatte
Delphi-Quellcode:
  Procedure ContextMenuForFile(Wnd: HWND; FileName: String; X, Y: Integer);
    Var ContextMenu: IContextMenu;
      Popup: HMENU;
      CmdInfo: TCMInvokeCommandInfo;
      PIDL: PItemIDList;
      ShellFolder: IShellFolder;
      Eaten, Attr: LongWord;
      FileDir: String;

    Begin
      If SHGetDesktopFolder(ShellFolder) <> NO_ERROR Then Exit;
      FileDir := ExtractFileDir(FileName);
      FileName := ExtractFileName(FileName);
      If (FileDir <> '') and ((ShellFolder.ParseDisplayName(Wnd, nil, PChar(FileDir), Eaten, PIDL, Attr) <> NO_ERROR)
        or (ShellFolder.BindToObject(PIDL, nil, IID_IShellFolder, Pointer(ShellFolder)) <> NO_ERROR))
        or (ShellFolder.ParseDisplayName(Wnd, nil, PChar(FileName), Eaten, PIDL, Attr) <> NO_ERROR)
        or (ShellFolder.GetUIObjectOf(Wnd, 1, PIDL, IID_IContextMenu, nil, Pointer(ContextMenu)) <> NO_ERROR) Then Exit;
      Popup := CreatePopUpMenu;
      If Popup = 0 Then Exit;
      Try
        If Failed(ContextMenu.QueryContextMenu(Popup, 0, 1, $7FFF, CMF_NORMAL)) Then Exit;
        FillChar(CmdInfo, Sizeof(TCMInvokeCommandInfo), 0);
        CmdInfo.cbSize := SizeOf(TCMInvokeCommandInfo);
        CmdInfo.lpVerb := PAnsiChar(TrackPopupMenuEx(Popup, TPM_LEFTALIGN or TPM_RETURNCMD
          or TPM_RIGHTBUTTON or TPM_HORIZONTAL or TPM_VERTICAL, X, Y, Wnd, nil)) - 1;
        CmdInfo.nShow := SW_SHOWNORMAL;
        If CmdInfo.lpVerb = PAnsiChar(-1) Then Exit;
        ContextMenu.InvokeCommand(CmdInfo);
      Finally
        DestroyMenu(Popup);
      End;
    End;
als HWnd z.B. das Handle deiner Form
$2B or not $2B
  Mit Zitat antworten Zitat