LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Eent Swallowing: LabWindows/CVI

Solved!
Go to solution

Hi, can someone please explain me how event swallowing works, the purpose of it and how to use it in LabWindows/CVI. I have read the context help but couldn't wrap my head around it. Examples would be appreciated.

0 Kudos
Message 1 of 4
(1,104 Views)
Solution
Accepted by topic author linu95k

Hi,

 

user interface control elements such as buttons, menus etc. generate more than one event on user input. For example, if you click on a button, there will be an EVENT_LEFT_CLICK event, an EVENT_LEFT_CLICK_UP event, possibly a EVENT_GOT_FOCUS or an EVENT_COMMIT event.

Because callback functions respond to all events generated by the User Interface Library, the same callback function will be called multiple times. This may not always be ideal. In such a case, the callback function should return 1 instead of 0, telling CVI to forget / swallow all the other events of the related user action (here: clicking the button); in consequence no more callbacks will be called for this action.

 

An example:

 

/* This function MainCallbackEvents checks for all panel, control, and menu events. */

int CVICALLBACK MainCallbackEvents ( int panelOrMenuBarHandle, int controlOrMenuItemID, int event, void *callbackData, int eventData1, int eventData2 )

{
    if ( event == EVENT_END_TASK )
    {
        ...

    return ( 1 );
    }
    else
    {
        ....

        return ( 0 );
    }
}

0 Kudos
Message 2 of 4
(1,077 Views)

To answer OP's question: in most cases just return 0 and don't think about it. The only times when you want to swallow an even is if you want to specifically block the cascade of events. For instance you can catch Ctrl-P in a panel to print the entire panel, or in a control to print only that control. In the latter case you'll swallow the keyboard event so as to block its transmission to the panel.

 

Which brings me to a question of my own: why don't we always return 1 on commit events ? It would probably save some useless loops. Is it because it's the last in the line of events (mouse move, focus, left click, left click up, val changed...) and it wouldn't matter anyway ?

0 Kudos
Message 3 of 4
(1,072 Views)

Thank you now it makes sense.

0 Kudos
Message 4 of 4
(1,068 Views)