好学IT学院:IT信息技术分享交流平台
标签:Delphi  来源:互联网  作者:本站整理  发布时间:2009-05-16  ★★★加入收藏〗〖手机版
摘要: 在自己的界面中弹出系统右键菜单。unit PopupShell;interfaceusesWindows, Messages, SysUtils, StrUtils, ComObj,ShlObj,ActiveX;function Disp……

function DriveToPidlBind(const DriveName: string; out Folder: IShellFolder):
  PItemIdList;
var
  Attr: ULONG;
  Eaten: ULONG;
  DesktopFolder: IShellFolder;
  Drives: PItemIdList;
  Path: TUnicodePath;
begin
  Result := nil;
  if Succeeded(SHGetDesktopFolder(DesktopFolder)) then begin
  if Succeeded(SHGetSpecialFolderLocation(0, CSIDL_DRIVES, Drives)) then begin
    if Succeeded(DesktopFolder.BindToObject(Drives, nil, IID_IShellFolder, Pointer(Folder))) then  begin
      MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, PChar(PathAddSeparator(DriveName)), -1, Path, MAX_PATH);
      if FAILED(Folder.ParseDisplayName(0, nil, Path, Eaten, Result, Attr)) then begin
        Folder := nil;
      end;
    end;
  end;
  PidlFree(Drives);
  end;
end;

function PathToPidlBind(const FileName: string; out Folder: IShellFolder):
  PItemIdList;
var
  Attr, Eaten: ULONG;
  PathIdList: PItemIdList;
  DesktopFolder: IShellFolder;
  Path, ItemName: pwidechar;
  s1,s2: string;
  k: integer;
begin
  Result := nil;
 
  s1:= ExtractFilePath(FileName);
  s2:= ExtractFileName(FileName);
  Path:= a2u(s1);
  ItemName:= a2u(s2);

if Succeeded(SHGetDesktopFolder(DesktopFolder)) then begin
  if Succeeded(DesktopFolder.ParseDisplayName(0, nil, Path, Eaten, PathIdList, Attr)) then begin // FAIL
    if Succeeded(DesktopFolder.BindToObject(PathIdList, nil, IID_IShellFolder, Pointer(Folder))) then begin
      if FAILED(Folder.ParseDisplayName(0, nil, ItemName, Eaten, Result, Attr)) then begin
        Folder := nil;
        Result := DriveToPidlBind(FileName, Folder);
      end;
    end;
    PidlFree(PathIdList);
  end
  else
    Result := DriveToPidlBind(FileName, Folder);
  end;

FreeMem(Path);
  FreeMem(ItemName);
end;

function LANToPidlBind(NetPath: string; out Folder: IShellFolder): PItemIdList;
var
  Attr, Eaten: ULONG;
  DesktopFolder: IShellFolder;
  nt,pid1,pid2: PItemIdList;
  Path,FullPath: pwidechar;
  s1,s2: string;
  k: integer;
  err: HResult;
begin
  Result := nil;
end;

function DisplayContextMenu(const Handle: Thandle; const FileName: string; Pos: TPoint): Boolean;
var
  ItemIdList: PItemIdList;
  Folder: IShellFolder;
begin
  Result := False;
  ItemIdList := PathToPidlBind(FileName, Folder);

if ItemIdList <> nil then
  begin
  Result := DisplayContextMenuPidl(Handle, Folder, ItemIdList, Pos);
  PidlFree(ItemIdList);
  //Folder:= nil;
  end;
end;

end.

// ========================================= //

procedure TFormTest.Button59Click(Sender: TObject);
var
  pos: TPoint;
begin
  GetCursorPos(pos);
  pos:= ScreenToClient(pos);
  DisplayContextMenu(handle, 'c:\tools\setup', pos);
end;

利用SVN log命令查看提交日志信息详解
  内容提示:本文将详细介绍通过SVN log命令查看提交日志信息的方法。log: 显示一组版本与/或文件的提交日志信息。用法: 1、…
  • 好学考试H5触屏版开放内测
  • 好学触屏公众号虎力全开、杨帆起航!