如何显示“发送到”和“打开”上下文菜单? [英] How can I display the 'Send to' and 'Open With' context menus?

查看:121
本文介绍了如何显示“发送到”和“打开”上下文菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前一段时间,我询问过如何在Delphi中弹出某个文件的Windows上下文(右键单击)菜单。然而,即使一切正常(几乎)OK,发送到...和打开与...子菜单没有任何项目,即使当我在同一文件名右键单击资源管理器时,他们工作OK (例如,发送到...有桌面(创建镜头),电子邮件收件人等)。

Some time ago I asked about how to pop up the Windows context (right-click) menu for a certain file in Delphi. However, even if everything works (almost) OK, the 'Send to...' and 'Open with...' submenus don't have any items, even if when I right-click in Explorer on the same file name they work OK. (For example, 'Send to...' has 'Desktop (create shotcut)', 'Email recipient' etc.).

如何让这些菜单出现?

推荐答案

Raymond Chen在几年前就有关托管上下文菜单的许多系列文章中提到了这个确切的问题。他的文章的关键主题是,当您阅读文档时,您必须记住,您的程序正在播放shell的一部分,而文档通常是从实现上下文菜单界面,而不是调用它们的代码。

Raymond Chen wrote about this precise problem a few years ago in a many-part series about hosting a context menu. The key theme to his articles was that as you read the documentation, you have to remember that your program is playing the part of the shell, whereas the documentation is normally written from the perspective of the code implementing the context-menu interfaces, as opposed to the code calling them.

早在第2部分,Chen观察到发送和打开菜单显示为空。 第5部分解决了您对这些子菜单的直接关注。答案是您需要处理菜单消息。有一个与您的菜单相关联的窗口句柄 - 您提供给的句柄TrackPopupMenuEx HND in 伊萨姆的回答你的问题)。该窗口将在菜单活动时接收消息,并且需要将它们转发到实现菜单命令的对象。窗口有一个窗口过程,你需要调用菜单界面的 HandleMenuMsg HandleMenuMsg2 方法。该文章有一个例子。

As early as part 2, Chen observed that the send-to and open-with menus appear empty. Part 5 addresses your immediate concern about those submenus. The answer is that you need to handle menu messages. There is a window handle associated with your menu — the handle you provided to TrackPopupMenuEx (HND in Issam's answer to your question). That window will receive messages while the menu is active, and it needs to forward them to the objects implementing the menu commands. The window has a window procedure, and that's where you need to call the menu interface's HandleMenuMsg and HandleMenuMsg2 methods. The article has an example.

文章系列的其他部分涵盖了当您将菜单几乎工作时您无疑提到的其他内容。 第3部分介绍了属性对话框的出现位置。关于调用默认动词的第7部分。我建议你阅读整个系列。不要害怕C ++中的一切;它几乎是所有的接口方法和API函数,所以它应该转换为Delphi没有太多麻烦。

Other parts of the article series cover the other things that you no-doubt alluded to when you said your menu "almost" works. Part 3 talks about where the property dialog appears. Part 7 s about invoking the default verb. I suggest you read the entire series. Don't fear that everything's in C++; it's almost all interface methods and API functions, so it should translate to Delphi without much trouble.

这篇关于如何显示“发送到”和“打开”上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆