From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

popup menu

Solved!
Go to solution

Hi

I try to create a popup menu that popsup on a right click on a panel.

I've created the menu in the UIR editor

I've checked the .h file associated to .uir file and this what I find there :

#define  POPUPMENU                        1
#define  POPUPMENU_TEST1           2       /* callback function: PopUpMenuCB */
#define  POPUPMENU_TEST2           3       /* callback function: PopUpMenuCB */                      

 

I load the menu and get a valid value in 'PopUpMenuHandle'

PopUpMenuHandle=LoadMenuBar(0,"MyUIR.uir",POPUPMENU);

  

When I later try to run the menu by 

RunPopupMenu(PopUpMenuHandle,POPUPMENU,0,30,60,0,0,0,0);

 

I get a run time error -40 "The id passed was not a valid menu id."

If I pass the panelhandle where I invoke RunPopupMenu() the result is the same 

Thanx in advance

 

0 Kudos
Message 1 of 12
(4,597 Views)

The third parameter of RunPopupMenu has to be the panel handle, not zero...

0 Kudos
Message 2 of 12
(4,593 Views)

Hi Wolfgang

panel handle to what ?

 

I have a panel callback function that responds to EVEN_RIGHT_CLICK

I have tried to use this panel's handle as the third argument but the result is the same.

 

I have also tried to use MenuId obtained from the function below.

MenuId=NewMenu(PopUpMenuHandle,"Popup testing",-1);

 

I was unsure about the third argument here.

Afterall the menu is created in the .uir file. The result is the same.

0 Kudos
Message 3 of 12
(4,590 Views)

See here for a related discussion.

 

With reference to wolfgang suggestion, as clearly stated in the help for the command you must pass the handle of the panel you want the menu to appear.

 

Last but not least, it's better not to spread the same question over more threads.



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 12
(4,583 Views)

Hi Roberto

Sorry for having the same question in two threads. I thougt that repying to you in the old thread would stay in that thread.

I started a new in case you would'nt answer.

 

As I've said I have tried to to pass the handel of the panel that invokes the call to RunPopupMenu() and it still gives me the error -40

E.g. the third argument to RunPopupMenu() is the panel handle that calls it.

 

Initially in the code I have to calls

PopUpMenuHandle=LoadMenuBar(0,"MyUIR.uir",POPUPMENU);
MenuId=NewMenu(PopUpMenuHandle,"Popup testing",-1);

 

I bellive that the call to NewMenu() should not be neccecary as the menu is created in the uir editor.

 

However this is the help text for the id in cvi:

ID for a particular menu within a menu bar. The ID must be a constant name, located in the .uir header file, that you assign in
the User Interface Editor or a value that you obtain from functions such as NewMenu and NewSubMenu.

 

 

0 Kudos
Message 5 of 12
(4,572 Views)

Have you seen my answer in the other thread where I discuss about menu three-level structure?



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 6 of 12
(4,568 Views)

Yes I have but that was regarding a popup menu for a control - and it was also a bit back and forth.

 

I think my two question are :

1: What is the third parameter in the call to RunPopupMenu()

2 : Is the call to NewMenu() neccecary, it is created in the uir editor.

0 Kudos
Message 7 of 12
(4,564 Views)

Regarding your questions:

1. It's the handle of the panel you want the menu to appear on

2. NewMenu is not necessary if the menu bar is created in the UIR editor, provided it is created with the correct structure

 

And so I'm back again with it: is your menu organized in a three-level structure?

(i.e. the menubar called POPUPMENU, the menu called MENU and the items ITEM1 and ITEM2).

 

Menu.png

 

If so, you can pass POPUPMENU_MENU as the menu ID in RunPopupMenu and it will correctly show your menu. Otherwise you will continue receiving the -40 error.

When the user selects an item in the popup menu, the function will return the item selected (e.g. POPUPMENU_MENU_ITEM1) or 0 if the user has cancelled the operation.



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 8 of 12
(4,555 Views)

Roberto

I'm sorry I ment the second agrument to RunPopupMenu).

You answerd that to be POPUPMENU_MENU

 

I cannot see where I can set the menu name such as POPUPMENU_MENU becomes valid.

I cannot find the third level. I miss the name Menu1  (prefix is MENU.

In uir editor I can set the 'Menu bar constant prefix'  (POPUPMENU) and configure the menu items (TEST1 and TEST2).

 

Test.png

0 Kudos
Message 9 of 12
(4,552 Views)
Solution
Accepted by topic author fluidtronic

In the menu editor you set the constant prefix as POPUPMENU, ok.

 

NEXT press "Insert Item" button and set it this way:

Constant name = MENU

Item name = Menu 1

No callback

 

NEXT press "Insert child item" button and set the element this way:

Constant name = TEST1

Item name = Test 1

No callback

 

After that you can execute RunPopupmMenu passing POPUPMENU_MENU as the menu ID.



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 12
(4,544 Views)