04-27-2009 06:52 AM
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
04-27-2009 07:35 AM
04-27-2009 07:36 AM
Yes, every control can be added a popup menu with a few 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.
07-01-2010 03:04 PM
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
07-01-2010 03:26 PM
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
07-01-2010 03:32 PM
Thanks Wolfgang, I have moved it, still it is giving some errors
07-01-2010 03:44 PM
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)
07-01-2010 03:51 PM
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
07-01-2010 04:01 PM
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
07-01-2010 04:02 PM
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?