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

后端 未结 1 1191
既然无缘
既然无缘 2021-02-10 21:18

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...\'

1条回答
  •  粉色の甜心
    2021-02-10 21:57

    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.

    0 讨论(0)
提交回复
热议问题