LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

disable callback

Hi,

i use CVI 6.0

I write program that have popup menu.
I run this menu when i get EVENT_RIGHT_CLICK from panel on it i clicked right button. The problem that i want to run menu only when i click on free panel zone (that doesn't include control).
How can i do that?
0 Kudos
Message 1 of 7
(3,731 Views)
You need check if the right click occurred in the area under a control, then popup if not.

Use GetCtrlAttribute on your control to get the ATTR_LEFT, ATTR_WIDTH, ATTR_TOP and ATTR_HEIGHT.
Create a callback function for your panel.
In the case EVENT_RIGHT_CLICK, check if the right click happened outside of that area. eventData1 is the click Y, eventData2 is the click X. If the click is not in the control area, do your popup.

See the attached project.
Message 2 of 7
(3,731 Views)
But what have i do if i have many controls on panel, to check each control?

What occures when right click event occure over control, both control and panel can get this event trought callback functions? So maybe i can define that control will get this event first, and after this i can disable this event to prevent panel callback function?
0 Kudos
Message 3 of 7
(3,731 Views)
Sure: that's even easier (meaning I wish I would have thought of that). Each control needs to have a callback function with an EVENT_RIGHT_CLICK case. If you right click on a control, the control callback will get the event before the panel callback. In the control callback EVENT_RIGHT_CLICK case, swallow the event by returning 1 rather than 0. Then the panel callback won't see the event. Check the CVI help for "Swallowing Events".
0 Kudos
Message 4 of 7
(3,731 Views)
Thanks.
5 minutes before i got your comment i founded this trick in CVI help.
0 Kudos
Message 5 of 7
(3,731 Views)
Just a word of caution to point out that if you swallow the right-click event in the control callback, the control itself will not be able to perform its default action upon receiving that event. At that point, it's as if the user had never clicked on the button.

This is probably okay for most controls, but for those control types which normally do something on a right-click (off the top my head: tables, graphs and activex controls, for example) you'd be changing the behavior of the control.

Luis Gomes
NI
0 Kudos
Message 6 of 7
(3,731 Views)
Good point Luis. Right click on a table control and the table control callback gets the event, then the panel gets the event. The built-in table-right-click menu doesn't swallow the event. The right-click menu pops up even if you handle the right click (unless you swallow the event).

So, maybe the best way to impliment the original intent (pop up on a blank area of the panel) is a combination of the two methods I mentioned earlier. Swallow the event for simple controls that don't have a built-in right-click function. Check if the right-click happened on a control (by getting the control's x,y attributes as I mentioned in my first response) for controls like tables with built-in right-click functions.
0 Kudos
Message 7 of 7
(3,731 Views)