LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

menu on right-click for numeric control

Hello,

is there a way to program a "menu on right-click" for a control (e.g. numeric), like there is for table controls?

I'm working with CVI 8.0.1 

 

Thanks & Best Regards,

Greg

 

0 Kudos
Message 1 of 21
(4,345 Views)
You can use RunPopupMenu(...) in the control's callback for the EVENT_RIGHT_CLICK event to show a menu when the user right-clicks on the control.  In order to place the menu exactly where the user right-clicked I generally use GetRelativeMouseState(...) to find where the mouse cursor is.  Hope this helps.
0 Kudos
Message 2 of 21
(4,342 Views)

Yes, every control can be added a popup menu with a few instructions.

  1. Design the menu nar in the UIR editor; do not associate it to any panel
  2. Load the menu bar when needed with the line menuHandle = LoadMenuBar (0, "myfile.uir", menuBar): by passing 0 as the panel handle it will not be associated to any of them
  3. In the numeric callback add these instructions:

     switch (event) {
        case EVENT_RIGHT_CLICK:
            // Context menu

           choice = RunPopupMenu (menuHandle, menuBar_Menu, panel, eventData1, eventData2, 0, 0, 0, 0);
            switch (choice) {

                 case menuBar_menu_item1:

                          // menu item handling code

                          break;

            }

            break;

     }

 

Passing eventData parameters to RunPopupMenu function ensures that the menu is displayed at the mouse position.



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?
Message 3 of 21
(4,342 Views)

Hello need some help here,

 

I created a myfile.uir and I want to show it as a menu when I right click on the mouse. I have the following as code:

 

else if (event == EVENT_RIGHT_CLICK)
     {      
        int MenuBar,MenuID,MenuHandle;
        
         MenuID = NewMenuItem (MenuBar, MenuID,-1, 0, 0, 0);
         MenuHandle = LoadMenuBar (0,myfile.uir, MenuBar):
         RunPopupMenu (MenuHandle, MenuID, panel, eventData1, eventData2, 0, 0, 0, 0);
           
            break;
     }    
    
    
    return (0);

 

 

I have a bunch of error, what am I doing right? (because I know most of it is wrong, thanks for the help

LabVIEW Intermediate I level!
0 Kudos
Message 4 of 21
(4,008 Views)

Hi Bebeto,

 

the first thing I would change is moving the line

 

int MenuBar,MenuID,MenuHandle;

to the top of your code; I would assume that it is not permitted in an if clause.

 

Good luck,

 

Wolfgang

0 Kudos
Message 5 of 21
(4,008 Views)

Thanks Wolfgang, I have moved it, still it is giving some errors

LabVIEW Intermediate I level!
0 Kudos
Message 6 of 21
(4,006 Views)

hm,

 

sometimes these error messages give a clue.... for example, in the first line:

 

MenuID = NewMenuItem (MenuBar, MenuID,-1, 0, 0, 0);

this function requires one more parameter, I would assume that you miss the menu item name (third parameter)

0 Kudos
Message 7 of 21
(4,003 Views)

What I am trying to accomplish is:

 

as when I right click on the mouse to open a menu (myfile.uir) so I can select one of the options from this menu. And from the examples found in the forums I came up with those lines of code.

 

The problem is that I am not sure if my programming technique is correct to make that happen, I see what you are saying, but I am not sure how to do it.

 

Thanks

LabVIEW Intermediate I level!
0 Kudos
Message 8 of 21
(4,001 Views)

OK,

 

also the sequence of commands is wrong: first you need the menu bar (LoadMenuBar), and only then you should add your menu item. If you do not want a menu item name, you can simply use "" as third parameter:

 

Wolfgang

0 Kudos
Message 9 of 21
(4,000 Views)

Hi Bebeto, what are you trying to do with that code? Particularly, what are you trying to ad to the menubar with NewMenuItem?

 

I can see some problems in your code, let me list them:

1. MenuBar is the constant name associated to the menu bar in the UIR editor. Defining a variable with the same name in the code can lead to several compile errors; you do not need to define it in any way since you are alreadi includding the include file of your UIR in the code (because you are doing it, right?)

2. In the UIR have you defined your own menu bar? In doing so you must have set a constant name for it, which is the one to pass to LoadMenuBar

3. Let's put away NewMenuItem line for the moment: in any case yo should put it after LoadMenuBar, but let's start with native menu bar without customising it

 

Can you post the complete code for the control callback so that wecan check if there are other hints that can help you?



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 10 of 21
(4,001 Views)