LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Changing runtime menu of a control programmatically.

Hi all,
I am using LabVIEW 8.0.
I have a application where i need to change runtime menu of a Boolean control programmatically.
That is if boolean value is TRUE, runtime menu should contain 2 items.
That is if boolean value is FALSE, runtime menu should contain 3 items.
Is it poossible?
Kindly suggest.
 
Regards
SajK
0 Kudos
Message 1 of 17
(14,753 Views)
Yes, you can change the run-time menu of a control programmatically.  You have to use the event structure and the menu functions.  When you popup (right-click on Windows) on a control, its "Shortcut Menu Activation?" event fires.  So, if you've registered for this event on your boolean control, that event diagram will execute.  This is where you have the opportunity to modify your shortcut menu programmatically before it is displayed.
 
One of the event parameters is the MenuRef.  Assuming you haven't done any edit-time customization of the control's menu, the items in the menu will just be the default items.  If you don't want any of the default items, you can wire the MenuRef to a Delete Menu Items function, leaving "menu tag" and "items" unwired, which will clear all of the menu items.  Then, you can insert (using the Insert Menu Items function) two menu items if the boolean's value is TRUE and three items if it is FALSE.
 
If these are user-defined menu items, you'll need to add a "Shortcut Menu Selection (User)" event as well.  Handle the items based on the tags you passed into the Insert function.
 
There's a good example program of programmatically controlling shortcut menus at run-time.  It's at <LabVIEW>/examples/general/Run-TimeShortcutMenu.llb.  The documentation on this feature is very good as well.  Check out the help topic called "Customizing Run-Time Shortcut Menus for Controls Programmatically".
 
Good luck,
Robbie
Message 2 of 17
(14,736 Views)
sajK:

Here is a small example to show you how you can add Run-Time shortcut menus to a boolean. I hope this helps.

Rudi N.
Message 3 of 17
(14,725 Views)

Thank u  very much Robbie.

I could locate the example and solve my problem.

One more thing I want to ask, how to get runtime menu reference of a control without using event strucutre. Is that possible?

Regards

SajK

 

0 Kudos
Message 4 of 17
(14,705 Views)

Thank  you  very much Rudi for user example.

I could solve the problem.

SajK

0 Kudos
Message 5 of 17
(14,703 Views)
sajK,
Getting the MenuRef of a control programmatically cannot be done outside of the event structure.  In fact, the MenuRef of a control is only valid in its "Shortcut Menu Activation" event diagram.  In other words, it is useless to wire it outside of that diagram and try to use it somewhere else in the program.  The menu for a control is created when you right-click/command-click on it and is destroyed after we finish tracking it (either because something is selected or you click outside the menu bounds).  Thus, it doesn't exist and there cannot be a reference to it except in the Shortcut Menu Activation event.
 
If this causes a problem for your application, let us know and I'm sure we can find you a workaround.
 
 
Thanks,
Robbie
 
 
Message 6 of 17
(14,662 Views)

Robbie,

Thanks. It is fine to some extent.

The only problem is that if the program is handling someother events (like one involves serial read which takes more than 1 sencond in my program), it will take a second to display the runtime menu after right clicking the button.

SajK

0 Kudos
Message 7 of 17
(14,647 Views)
SajK,
Sorry for not responding sooner, I've been out on vacation.
 
It sounds like you should be using a Producer/Consumer (Events) design pattern.  Anytime you have an operation (especially those triggered by a user interface event) which takes a noticeable amount of time, this is a good design pattern to use.  That way you can quickly "handle" the event by pushing a serial read message onto a message queue and then free up the UI to handle other events.  Then the other loop just responds to these messages.
 
It may take a little refactoring of your program, but there's a template VI for the Producer/Consumer (Events) design pattern in the New... dialog, so you would at least have a little head start.
 
Robbie
Message 8 of 17
(14,570 Views)
Hi there,
I have a (seemingly) similar but more simple problem. I debataed on making a new thread, but this way I know the people who'll most likely know the answer (the ones who've already posted) will get notified of the post.

I'd like to add a static entry to the control's shortcut menu (easy enough to do using advanced/run-time shortcut menu/edit), but I'd like to emulate the ability to check and uncheck the menu item.

It seems the only way to do that is to have access to the shortcut menu reference and use the "get/set info" vis to read and alter the checked state of the menu item. However, to do this you need to know that the user has clicked on that particular menu item which by definition of the Menu Activation? state, has not happened yet. I'd also like to be able to uncheck the menu item programmatically when the user does another action other than direct selection/deselection from the menu. But if the menu reference is dumped at the close of the Menu Activation? state, then it seems like I'm sunk.

Am I missing something here or is this behavior just not possible?
0 Kudos
Message 9 of 17
(14,480 Views)
Follow up: Here's an example of what I want to do. I think it would work except for the fact you get an "Illegal menu" error because the menu ref doesn't exist outside the Menu Activation? state (I think).
0 Kudos
Message 10 of 17
(14,480 Views)