LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to popup a menu when I click the mouse on the panel?

I looked up in the help of CVI, and found that only the table and tree have this attribute, can anybody tell me how to do it?
Dongsheng Zhao
North China Electronic Power Univ.
zds_hd@yahoo.com.cn
0 Kudos
Message 1 of 6
(3,273 Views)
The easiest way is to install a panel callback either programmatically or in the UIR editor. In the panel callback trap EVENT_LEFT_CLICK or EVENT_RIGHT_CLICK events and call RunPopupMenu function: this will display a menu at the mouse cursor position. The displayed menu can either be built programmatically or in the UIR editor and does not need to be associated (i.e. visible as a menu bar) with a panel before RunPopupMenu executes.

I do suggest you install the panel callback for EVENT_RIGHT_CLICK, since EVENT_LEFT_CLICK is received from the panel callback for each control you operate on in the panel.

In case you trap the same mouse event in a control callback and in the panel callback, you'll have to swallow this event in the control callback to avoid it is trapped by the panel callback too. To do this return 1 in the control callback for this event.

I attach a simple project that displays a popup menu for both the panel and a control on it.

Hope this helps
Roberto


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 6
(3,261 Views)
thanks.
I program like the following:
int CVICALLBACK PanelCallback (int PreviewPanel, int event, void *callbackData,
int eventData1, int eventData2)
{ int MenuBar,MenuID;
if (event == EVENT_CLOSE)
HidePanel (panels);
if (event == EVENT_RIGHT_CLICK)
{
MenuBar = NewMenuBar (panels);
MenuID = NewMenu (MenuBar,"_tool",-1);
RunPopupMenu (MenuBar, MenuID, panels, 250, 330, 300, 400, 10, 10);
}

return 0;
}
but it did not work, i click on the panel and there is no popup menu.Another problem is that i don't want to display the menubar on the panel, can you answer my question?
Dongsheng Zhao
North China Electronic Power Univ.
zds_hd@yahoo.com.cn
0 Kudos
Message 3 of 6
(3,238 Views)
Sorry, Zhao, I forgot to attach the example!

Anyway, your code is good. To display a popup menu you must simply populate it with at list one item, using
MenuID = NewMenuItem (MenuBar, MenuID, "Item1", -1, 0, 0, 0);
Doing this RunPopupMenu displays the menu.

To display the popup menu at the cursor position, pass eventData1 as Top and eventData2 as Left parameter to RunPopupMenu.

To prevent the menu bar from being displayed on the panel pass "0" as the Destination Panel Handle in NewMenuBar function.

Hope this helps
Roberto


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 6
(3,233 Views)
THANKS A LOT!
I have solve the problem, but i find when i right click on the panel, the menu pop up, and i right click again, the menu dispear, click again ,it pop up.
I think this is not effective. I want the old menu dispear when i right clicked the mouse in a new posotion and the new menu pop up immediately in the new position,HOW CAN I GOT IT?
Dongsheng Zhao
North China Electronic Power Univ.
zds_hd@yahoo.com.cn
0 Kudos
Message 5 of 6
(3,233 Views)
I'm sorry. I'm afraid there isn't a very good way to do this. You'll find that this is how all right-click menus work in CVI (the source window, the table and tree controls, etc...)

You do have one possibility for achieving this, but I'm not sure how reliable it is. If you really need this behavior, you can try it, but it might not be completely reliable:

As soon as the RunPopupMenu function returns, call the GetRelativeMouseState function to find out: 1) if the right mouse button was clicked, and 2) if the click happened in the panel area. If both those conditions are true, you can then redisplay the menu, and keep doing so, as long as those conditions remain true every time the RunPopupMenu returns.

One last observation: in your example code, you are creating a menubar that is associated with the panel. That will force the menubar to be visible. If you don't want that (which I'm guessing you don't) you should pass 0 to NewMenuBar.

Luis
NI
0 Kudos
Message 6 of 6
(3,217 Views)