How can I display the 'Send to' and 'Open With' context menus?

血红的双手。 提交于 2019-12-21 02:50:13

问题


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.).

How can I make those menus appear?


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/2040659/how-can-i-display-the-send-to-and-open-with-context-menus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!