LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Popup menus for any controls

Solved!
Go to solution

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 ?

0 Kudos
Message 1 of 4
(2,753 Views)
Solution
Accepted by topic author gdargaud

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(2,726 Views)

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

0 Kudos
Message 3 of 4
(2,720 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(2,714 Views)