LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically simulate the Get Menu Selection vi

Solved!
Go to solution

Hi,

 

I'm using LabVIEW 8.5 base version (no event handling). I have created a custom RTM (Run-Time Menu) and use the Get Menu Selection vi wired to a Case structure to handle all the items. (Part of the handling it to put a check mark next to the selected menu item and clearing the check mark from all other items using the Set Menu Item Info vi. Too bad it doesn't do that automatically. Maybe it does in newer versions, but I digress.)

 

My application can save and recall setups. When I recall a setup I would like to programmatically call the respective Case, as is done by the Get Menu Selection vi, even though the menu is not actually clicked by the user. I cannot find a way to do this. Is is possible?

 

Thank you.

Ed

0 Kudos
Message 1 of 9
(3,799 Views)

I'm not certain but I think you can simulate this by using Windows DLL calls to simulate the keyboard being pressed.  If you press Alt+F you'll notice that the File menu is opened.  You could then press the arrow keys and enter to select menu items in a simlar way to the user clicking on them. 

 

Here is one option for this.

 

http://www.ni.com/example/29509/en/

0 Kudos
Message 2 of 9
(3,777 Views)
Solution
Accepted by topic author Edjsch

Thank you for your reply. It looks like there is no convenient way to "simulate" a Windows "event" with the base version. Duh!

 

Anyway, as usual, I came up with a solution. First, I want to say that only a subset of my menu items require a check mark, but that's not really relevant. I have a hidden Ring control (aka, a drop-down list box) with all of the item tags of those menu items. I created a For Loop and iterate through all the items (the ring NumItems property), first clearing all the check marks (using Set Menu Item Info with the RingText.Text connected to the item tag input) and then setting the required one from what is recalled from the file. That handles the check mark issue. (Note that in the Get Menu Selection vi's Case structure, I had to actually clear each check mark and set the one for the current selection, since the RTM does not handle check marks automatically, as, for example, Visual Basic does. Again, maybe newer versions do.)

 

I can then do other reqiured operations, replicating what is done for that menu selection in the Get Menu Selection vi's Case structure. (The common things can be put in a sub vi.)

 

Let me know if anyone would like to see screen shots of that area of my block diagram.

 

Ed

0 Kudos
Message 3 of 9
(3,764 Views)

@Edjsch wrote:

Thank you for your reply. It looks like there is no convenient way to "simulate" a Windows "event" with the base version. Duh! 


I'd take that a step further and say there is no convenient way to write software without the event structure.  I don't know how people write code without it.  This limitation has been removed and the event structure comes with all versions of LabVIEW as of 2012.

 

As for my virtual keyboard trick, here is a better one I didn't get a chance to check the link previously.

 

https://decibel.ni.com/content/docs/DOC-15310

 

With that you can call a subVI that will invoke the Alt+F or whatever to open menus.

 


@Edjsch wrote:

 

Note that in the Get Menu Selection vi's Case structure, I had to actually clear each check mark and set the one for the current selection, since the RTM does not handle check marks automatically, as, for example, Visual Basic does. Again, maybe newer versions do.


They do not, you are welcome to make an idea exchange for it, but I'm fine with toggling that bit myself.  But then again I can't think of a time when clicking on a checked item, shouldn't uncheck it so I can see your point.


@Edjsch wrote:

 

Let me know if anyone would like to see screen shots of that area of my block diagram.


Never post screenshots. 

 

  • When posting code post the actual code not a screenshot.  You wouldn't take a screenshot of a text file and post it on a text language forum.  Upload the actual VI, or zip several files and upload the zip.  The exception to this rule is when uploading a VI Snippet.  This is an image with the VI embedded in it, so the source is still intact.
Message 4 of 9
(3,755 Views)

Hooovahh,

 

Thanks again for your reply. It turns out that the virtual keyboard trick might be more code than the way I'm doing it. Also, I have keyboard shortcuts for things like Open or Save a file, Help/About, or Close the application, but not for those other menu items where I need a check mark so the user knows how he has configured the program, i.e., what has previously been selected.

 

You said, "But then again I can't think of a time when clicking on a checked item, shouldn't uncheck it so I can see your point." No, it's not a toggle like a check box. If a checked menu item is selected again, the check mark remains. (If a new item (in that group) is checked, the easiest thing is to uncheck all and check the one selected.)

 

I get your point on screenshots, and the VI Snippets are very cool for newer versions of LV (what version what it introduced?), but isn't "Never post screenshots" too strong language? Remember, never say never! Anyway, there are tons of posts and NI articles with screenshots of example code, although some so have vi's attached. Furthermore, it can be quite time consuming to create a full-blown working example of a small piece of an application. My boss wouldn't be happy!

 

Cheers,

Ed

 

0 Kudos
Message 5 of 9
(3,745 Views)

@Edjsch wrote:

 

No, it's not a toggle like a check box. If a checked menu item is selected again, the check mark remains. (If a new item (in that group) is checked, the easiest thing is to uncheck all and check the one selected.) 


This is more like a radio button selection right?  I can use a use for this, but I've personally never made a menu like that before.  It could be made into a reusable function to help with menues like that.  Maybe have an array of tags be the input, and if one was selected it selects that and deselects all the others in the array.

 


@Edjsch wrote:

 

I get your point on screenshots, and the VI Snippets are very cool for newer versions of LV (what version what it introduced?), but isn't "Never post screenshots" too strong language? Remember, never say never! Anyway, there are tons of posts and NI articles with screenshots of example code, although some so have vi's attached. Furthermore, it can be quite time consuming to create a full-blown working example of a small piece of an application. My boss wouldn't be happy! 


Snippets were added in 2009, which is the oldest version that the Code Capture Tool supports which has similar functionality.  I think I will stick by my "Never" statement, but others might not agree.  Again in my analogy, I would also say to never take a screenshot of text code and post it on a VB forum.

 

I agree about the boss statement, but I justify it by saying I'm getting free online support from a huge community of developers, and NI themselves.  Taking a few minutes to strip away the non-essential part of the code, to post it seems worth it to me.

0 Kudos
Message 6 of 9
(3,738 Views)

Yes, that portion of my menu is analogous to a radio button group. If you had several singular "radio button" controls (such as the System Radio Button) you'd have to write similar code to deselect other ones when one was selected. (Actually, I can't see the use for a non-grouped radio button, but be that as it may.) We thought the applicaton would look somewhat more "modern" with menu selection for some aspects than radio buttons or drop-down list boxes (rings). Plus the front panel looks cleaner, less cluttered.

 

Your other points are well taken.

 

Ed

0 Kudos
Message 7 of 9
(3,731 Views)

@Hooovahh wrote:

Snippets were added in 2009, which is the oldest version that the Code Capture Tool supports which has similar functionality.


Actually, there are older versions of the CCT which can create snippets in any version from 7.0 and up, including 8.5. I believe version 3.0 was the first 2009 one, so you would probably need to manually download an older version from the LAVA CR and you'll lose some of the newer features. I think those didn't install through VIPM, either. Importing the snippet in <2009 is trickier (there are some tools for it), but they should be natively importable for anyone with 2009 and later.

 

Anyway, while having the code is generally great, having snippets or even regular images also has an advantage - you can look at them immediately without needing LV or depending on versions. This becomes less practical the more complicated the problem gets, but even then can be relevant sometimes. The best is probably both.

 

As for taking the time to create an example, it can be time consuming, but it's also time consuming for the people who volunteer here to help. Paring things down tends to make them easier to understand and gives people a shared baseline (and can sometimes also help you with finding the problem directly).


___________________
Try to take over the world!
0 Kudos
Message 8 of 9
(3,707 Views)

@tst wrote:

Actually, there are older versions of the CCT which can create snippets in any version from 7.0 and up, including 8.5.


Oh sorry I was basing that information on the oldest version of the CCT available in the tools network.  I agree that an image is easier to view, even on mobile devices.  But when it comes to running and probing, I'm not going to recreate an image you post, to see the behavior that is being described.

0 Kudos
Message 9 of 9
(3,688 Views)