English 中文(简体)
• 如何进入Windows Shell背景菜单项目?
原标题:How to access Windows shell context menu items?

在Windows探测器中,你在档案中点击,背景菜单显示,其中含有Send至...和(或)第3类已建项目,如Winzip的zip案。 我的问题是:

  • How to obtain the full list of available menu items for a specific file?
  • For each menu item, how to get the caption?
  • How to invoke a specific menu item action for a specific disk file?

事先感谢你!

[EDIT]: 虽然其他信息绝对有用,但德尔菲解决方案将受到高度赞赏。

最佳回答

获取壳牌照菜单的关键是:IContextMenu接口。

http://netez.com/2xExplorer/shellFAQ/bas_context.html” rel=“noreferer”><>Shell context menu support

<>>>>>

http://www.koders.com/delphi/fid5626A4145356397ABA0FD7CB0AAB44EF3B692ECD.aspx?s=delphi”rel=“noretinger”>JclShell , 摘自JEDI JCL (check the )和壳牌Ctrls单位(载于Delphier样本)。

问题回答

www.un.org/Depts/DGACM/index_spanish.htm 简短回答

Try the ShellBrowser Parts from JAM 软件。 它们有一个组成部分,使你们能够展示探索者的背景菜单,而你们自己的指挥则好坏参半。


http://www.ohchr.org。

找到探索者菜单,盘问其所有财产,将其放在你自己的菜单上,是可能的,但你真的应该能够读写低水平的Win32法典,而C公司的工作知识将有所帮助。 你们也需要看看看看一些 go(见下文)。 我强烈建议阅读:http://blogs.msdn.com/b/oldnewthing/archive/2004/09/20/231739.aspx” rel=“noreferer” • 如何为许多技术细节主办一个IContextMenu系列。

<easier办法是询问IContextMenu界面,即HMENU,然后使用跟踪PopupMenu,让Windows显示菜单,然后打电话到InvokeCommand。

以下几部法典未经测试或已经从我们重新使用的内容中修改,因此以自己的风险进行。

http://msdn.microsoft.com/en-us/library/bb77609528VS. 8529.aspx“rel=“noreferer”>IConMenu。

function GetExplorerMenu(AHandle: HWND; const APath: string;
  AFilenames: TStrings): IContextMenu;
var
  Desktop, Parent: IShellFolder;
  FolderPidl: PItemIDList;
  FilePidls: array of PItemIDList;
  PathW: WideString;
  i: Integer;
begin
  // Retrieve the Desktop s IShellFolder interface
  OleCheck(SHGetDesktopFolder(Desktop));
  // Retrieve the parent folder s PItemIDList and then it s IShellFolder interface
  PathW := WideString(IncludeTrailingPathDelimiter(APath));
  OleCheck(Desktop.ParseDisplayName(AHandle, nil, PWideChar(PathW),
    Cardinal(nil^), FolderPidl, Cardinal(nil^)));
  try
    OleCheck(Desktop.BindToObject(FolderPidl, nil, IID_IShellFolder, Parent));
  finally
    SHFree(FolderPidl);
  end;
  // Retrieve PIDLs for each file, relative the the parent folder
  SetLength(FilePidls, AFilenames.Count);
  try
    FillChar(FilePidls[0], SizeOf(PItemIDList) * AFilenames.Count, 0);
    for i := 0 to AFilenames.Count-1 do begin
      PathW := WideString(AFilenames[i]);
      OleCheck(Parent.ParseDisplayName(AHandle, nil, PWideChar(PathW),
        Cardinal(nil^), FilePidls[i], Cardinal(nil^)));
    end;
    // Get the context menu for the files from the parent s IShellFolder
    OleCheck(Parent.GetUIObjectOf(AHandle, AFilenames.Count, FilePidls[0],
      IID_IContextMenu, nil, Result));
  finally
    for i := 0 to Length(FilePidls) - 1 do
      SHFree(FilePidls[i]);
  end;
end;

为了获取实际菜单,你需要打电话。 您可使用

function GetExplorerHMenu(const AContextMenu: IContextMenu): HMENU;
const
  MENUID_FIRST = 1;
  MENUID_LAST = $7FFF;
var
  OldMode: UINT;
begin
  OldMode := SetErrorMode(SEM_FAILCRITICALERRORS or SEM_NOOPENFILEERRORBOX);
  try
    Result := CreatePopupMenu;
    AContextMenu.QueryContextMenu(Result, 0, MENUID_FIRST, MENUID_LAST, CMF_NORMAL);
  finally
    SetErrorMode(OldMode);
  end;
end;

这里指的是用户从菜单中选择的指令:

procedure InvokeCommand(const AContextMenu: IContextMenu; AVerb: PChar);
const
  CMIC_MASK_SHIFT_DOWN   = $10000000;
  CMIC_MASK_CONTROL_DOWN = $20000000;
var
  CI: TCMInvokeCommandInfoEx;
begin
  FillChar(CI, SizeOf(TCMInvokeCommandInfoEx), 0);
  CI.cbSize := SizeOf(TCMInvokeCommandInfo);
  CI.hwnd := GetOwnerHandle(Owner);
  CI.lpVerb := AVerb;
  CI.nShow := SW_SHOWNORMAL;
  // Ignore return value for InvokeCommand.  Some shell extensions return errors
  // from it even if the command worked.
  try
    AContextMenu.InvokeCommand(PCMInvokeCommandInfo(@CI)^)
  except on E: Exception do
    MessageDlg(Owner, E.Message, mtError, [mbOk], 0);
  end;
end;

procedure InvokeCommand(const AContextMenu: IContextMenu; ACommandID: UINT);
begin
  InvokeCommand(AContextMenu, MakeIntResource(Word(ACommandID)));
end;

现在,你可以使用GetMenuItemInfo功能,以获得帽子、比图等,但更为容易的是:

procedure ShowExplorerMenu(AForm: TForm; AMousePos: TPoint; 
  const APath: string; AFilenames: TStrings; );
var
  ShellMenu: IContextMenu;
  Menu: HMENU;
  MenuID: LongInt;
begin
  ShellMenu := GetExplorerMenu(AForm.Handle, APath, AFilenames);
  Menu := GetExplorerHMenu(ShellMenu);
  try
    MenuID := TrackPopupMenu(Menu, TPM_LEFTALIGN or TPM_TOPALIGN or TPM_RETURNCMD, 
      AMousePos.X, AMousePos.Y, 0, AForm.Handle, nil);
    InvokeCommand(ShellMenu, MenuID - MENUID_FIRST);
  finally
    DestroyMenu(Menu);
  end;
end;

如果你真的想提取菜单/资本,把菜单添加到你自己的pop菜单中(我们使用工具箱,2000年,确实如此),那么,这里是你处理的其他大问题:

  • The "Send To" menu, and any others that are built on-demand won t work unless you handle messages and pass them to the IContextMenu2/IContextMenu3 interfaces.
  • Menu bitmaps are in a couple of different formats. Delphi doesn t handle Vista high-color ones without coaxing, and the older ones are blended onto the background color using an XOR.
  • Some menu items are owner-drawn, so you have to capture paint messages and have them paint to your own canvas.
  • Hint strings won t work unless you manually query for them.
  • You ll need to manage the lifetime of the IContextMenu and HMENU and only release them once the popup menu has been closed.




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签