11-09-2017 10:28 AM
Hi all,
I recently discovered the possibility of having popup menus on right-click. But it seems to be only possible with trees and tables. Why is that ? Why can't the attribute ATTR_ENABLE_POPUP_MENU be enabled for any type of control ?
BTW, the example code treemenu.prj seems to be gone from CVI 2017.
Alternatives ?
Solved! Go to Solution.
11-10-2017 02:06 AM - edited 11-10-2017 02:08 AM
The only alternative that comes to my mind is the use of RunPopupMenu inside the control callback.
You'll have to design a new menu bar with the control menu items and their callbacks and call it this way:
int CVICALLBACK ControlCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: // Other code here break; case EVENT_RIGHT_CLICK: RunPopupMenu (menuBarHandle, MENUBAR_CONTROLMENU, panel, eventData1, eventData2, 0, 0, 0, 0); break; } return 0; }
If you don't want to create menu item callbacks, you can switch on the return value of RunPopupMenu, which is the menu item ID of the element selected by the user, or 0 if he dismisses the menu without any choice.
11-10-2017 05:38 AM
OK, thanks, I see how that'd work, although it's a lot more work than just using ATTR_ENABLE_POPUP_MENU. Do you have any idea why this isn't available on all controls ? It seems like a no-brainer to me. Maybe it was too much work to define default menu events for all kinds of controls... But in that case just leave it empty or with a basic background color change...
11-10-2017 08:03 AM
Well, I rarely am happy with standard control menu, so the alternatives are a) use standard control menu with a set of HideBuiltInCtrlMenuItem and NewCtrlMenuItem calls or b) create my own menu in the UIR editor and call it via RunPopupMenu.
In either case I have to accomodate the menu to my needs: I really see no big difference in these two approaches.