orko Posted February 16, 2007 Report Share Posted February 16, 2007 Hi all, I've been beating my head against this for hours...so it's time to ask for help. :headbang: I've created a run-time menu and saved it to disk for a numeric control with one selection item, let's say its named "foo" and is located in "menu1.rtm". I can then attach this menu to my numeric control and create an event structure handling the event: "foo: Shortcut Menu Selection (User)" to trap when someone selects this item from the menu. This works as desired. My problem is, how can I check/uncheck the selection in the menu as I can do using the "Set Menu Item Info" menu primitives for application menus?? I don't see where I can get the MenuRef of the user rtm from within my event structure... I can only get the control reference, Item tag, Item path, and something called a "SubObj" (not at all sure what this is). My goal is to perform one thing when the user "checks" the selection, and another when they "uncheck" it. Thanks for any pointers! Quote Link to comment
PJM_labview Posted February 17, 2007 Report Share Posted February 17, 2007 As far as I know, the MenuRef is valid only in the menu activation frame. LabVIEW Help is quite specific about this: MenuRef: Reference to the control shortcut menu that you can modify during this event. MenuRef is valid only during this event case. Unfortunately, in my opinion, this is an annoying shortcoming of the shortcut menu implementation in LV 8.x (no pun intended). Also, NI shipping example "Run-Time Shortcut Menus.vi" is very misleading. For instance the Menu Selection has a MenuRef output (I have no clue how to get this outside of this VI since this is not one of the event data field available [even the help does not mentioned this field]) and if you check the reference validity it is always invalid. Another error is in the mouse down frame where a comment "Programmatically generate the Menu Activation event when the user right-clicks on the Listbox control" let you believe than you need to fire a value change to programatically generate the menu activation event. This is completly inacurate, and that frame can be deleted all together. Anyway, sorry I could not help you more. PJM Quote Link to comment
Michael Aivaliotis Posted February 17, 2007 Report Share Posted February 17, 2007 Ya, I believe this is an oversight on NI's part, however there is a workaround, albeit cludgy. You need to trap the menu Activation event. From there you can detect the state of the checkmark with the "Get Menu Item Info" menu primitive. Then you need to pass that state boolean via a shift register to the menu Selection event case. You don't even have to worry about initializing the shift register since the menu Activation event always fires before the menu Selection event case Quote Link to comment
orko Posted February 18, 2007 Author Report Share Posted February 18, 2007 QUOTE(PJM_labview @ Feb 15 2007, 06:19 PM) Also, NI shipping example "Run-Time Shortcut Menus.vi" is very misleading. For instance the Menu Selection has a MenuRef output (I have no clue how to get this outside of this VI since this is not one of the event data field available [even the help does not mentioned this field]) and if you check the reference validity it is always invalid. I see that too...that is strange to have a MenuRef in that example, but I believe you are right that you can't actually *use* it for anything, since it's invalid in that event case. This is really annoying me that you can't change a simple checkmark on a control's runtime menu. I can trap it in the Menu Activation event as Michael suggested, and that works for detection, but I'd like to change states of the menu (even be able to change the text items displayed depending on what the user selected last). Here is an example of what I am trying to do, and how far I was able to get it using a kludge... Sub Panel.vi (LV8.0.1) Basically, I want to change the colors of the things the user "disables" from the right click menus available, then be able to change them back if they select it again. The checkmark would have been perfect for this, but I can't figure out how to "check" the selection when the user selection event is fired. Is this impossible? Are there suggestions out there for how to do this a different way? Thanks! Quote Link to comment
PJM_labview Posted February 18, 2007 Report Share Posted February 18, 2007 Orko, I think you can do what you want, but to do so, you will have to build your menu dynamically and depending on the "enable/disable" of your control you will present the user on the menu activation with a unchek/check otpion. Basicaly, dont use static rtm and you should be able to do this. PJM Quote Link to comment
orko Posted February 19, 2007 Author Report Share Posted February 19, 2007 Thanks PJM, I'll try that out. It would have been nice in my situation to have a static file that I can use for a bunch of similar controls...but if I can't do it that way then I have no choice. Quote Link to comment
Michael Aivaliotis Posted February 19, 2007 Report Share Posted February 19, 2007 I'm not sure why you are having problems but here is how i would do it. I'm using a static menu. LV:8.01 Download File:post-2-1171778045.vi Quote Link to comment
orko Posted February 19, 2007 Author Report Share Posted February 19, 2007 Michael, Thanks for the example. However, it only gets me 75% there. Your example would work if you have two menu items that interact with each other (toggle back and forth). Its when you try and have them toggle the checkmark individually that you run into problems. In your example, there are only two states possible: Option A checked or Option B checked. I need to have four states: both unchecked, Option A checked, Option B checked, or both checked. This is the crux of the problem since in order to change the state of these checkmarks, you need to have both the MenuRef and the selection of the user in the same event frame to know which item to check/uncheck. Quote Link to comment
Michael Aivaliotis Posted February 20, 2007 Report Share Posted February 20, 2007 Ok, I've modified it to perform what you requested. Download File:post-2-1171876399.vi LV: 8.01 Now what? Quote Link to comment
i2dx Posted May 24, 2007 Report Share Posted May 24, 2007 QUOTE(orko @ Feb 16 2007, 02:13 AM) Hi all,I've been beating my head against this for hours...so it's time to ask for help. :headbang: I've created a run-time menu and saved it to disk for a numeric control with one selection item, let's say its named "foo" and is located in "menu1.rtm". I can then attach this menu to my numeric control and create an event structure handling the event: "foo: Shortcut Menu Selection (User)" to trap when someone selects this item from the menu. This works as desired. My problem is, how can I check/uncheck the selection in the menu as I can do using the "Set Menu Item Info" menu primitives for application menus?? I don't see where I can get the MenuRef of the user rtm from within my event structure... I can only get the control reference, Item tag, Item path, and something called a "SubObj" (not at all sure what this is). My goal is to perform one thing when the user "checks" the selection, and another when they "uncheck" it. Thanks for any pointers! I stumbled uppon allmost the same problem today: I need a reference to the runtime-shortcut menu of a control, to edit that menu programatically ... If I have not missed something, there is no way to get a reference through the *normal* property-nodes. You can get a reference to the menu, if you use an event structure and the "Shortcut Menu Activation?" event, but this only works if you catch the event for one, single control. If you bundle more then one "Shortcut Menu Activation?" event in one case, you'll get no reference to the menu at all. And here's where my problem starts: I've about 50 controls on my FP, and I need to catch at least 4 events on each control, two for Shortcut menu activation and Menu selection, the rest for drag and drop. If I can get the reference to the shortcut menu only if I create an event case for each control and it's sub-controls, in case that the control is a cluster, I'd end up with a huge event structure with lots of similar cases. I'm not very happy with this, so I'd be glad, if someone out there maybe knows a better way? Quote Link to comment
jgcode Posted August 23, 2008 Report Share Posted August 23, 2008 QUOTE (Michael_Aivaliotis @ Feb 19 2007, 05:14 PM) Ok, I've modified it to perform what you requested. Ahh..my questions answered and I didn't even need to start a thread..thanks guys :beer: LAVA Quote Link to comment
Comrade Posted June 18, 2015 Report Share Posted June 18, 2015 Now this is quite old and maybe it didn't work back then, but with LV 2013 there is no problem doing this... https://lavag.org/files/file/265-falk-schneider/ I stumbled uppon allmost the same problem today: I need a reference to the runtime-shortcut menu of a control, to edit that menu programatically ...If I have not missed something, there is no way to get a reference through the *normal* property-nodes. You can get a reference to the menu, if you use an event structure and the "Shortcut Menu Activation?" event, but this only works if you catch the event for one, single control. If you bundle more then one "Shortcut Menu Activation?" event in one case, you'll get no reference to the menu at all.And here's where my problem starts: I've about 50 controls on my FP, and I need to catch at least 4 events on each control, two for Shortcut menu activation and Menu selection, the rest for drag and drop. If I can get the reference to the shortcut menu only if I create an event case for each control and it's sub-controls, in case that the control is a cluster, I'd end up with a huge event structure with lots of similar cases. I'm not very happy with this, so I'd be glad, if someone out there maybe knows a better way? Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.