Set focus to a particular control (e.g. an open popup menu)

I have a custom control that uses a popup menu, but which does not control a parameter, so the control class has its own IPopupMenuControl and IPopupMenu members, instead of using PromptUserInput. But whereas menus created by PromptUserInput will close if the user clicks outside their boundaries, the UI doesn’t know to check whether my custom menu is open when it checks for mouse-down events, thus clicking outside the open menu has no effect.

I think what I need to do is, when the menu is opened, tell the UI to give focus to the custom control (which owns the popup menu control) and send any mouse-down events to it as long as the menu is open. Does this functionality exist in IGraphics?

Creating an IPopupMenuControl is the wrong approach. That is one of the “Special Controls” that live outside the main control stack that IGraphics creates for you, if you want to override the native popup menu and draw a popup menu using IGraphics.

You can do what you want by calling IGraphics::CreatePopupMenu() rather than IControl::PromptForUserInput();

Here is an example, which is creating the menu inside an IVButtonControl’s action function:

Ahh, thanks! My approach felt pretty bodgy, and this looks a lot more elegant.