LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

renaming tree items


DanielGreen wrote:
 I don't totally understand "swallowing" but I'm sure I can figure it out, I've messed with it before but haven't really looked into it.

Hi Daniel,
 
"swallowing" an event means that the event will not be passed to the control, and the control will behave like the event didn't happen. To swallow an event, the callback function should return 1 instead of 0. Here is a list of all events that can be swallowed (you can find this list in the CVI help, look for "Swallowing Events"):

EVENT_COMBO_BOX_INSERT

EVENT_COLLAPSE

EVENT_COMMIT

EVENT_DRAG

EVENT_DROP

EVENT_END_TASK

EVENT_EXPAND

EVENT_HSCROLL (Swallowable for tabs only.)

EVENT_KEYPRESS

EVENT_LEFT_CLICK

EVENT_LEFT_DOUBLE_CLICK

EVENT_MARK_STATE_CHANGE

EVENT_MOUSE_WHEEL_SCROLL

EVENT_RIGHT_CLICK

EVENT_RIGHT_DOUBLE_CLICK

EVENT_SELECTION_CHANGE (Swallowable for trees only.)

EVENT_SORT

 
Short example: suppose you created a string control on a panel, and you want the user only to enter alphanumeric characters in this control. All you need to do is catch the keypress event and swallow it if the key that is pressed is not alphanumeric. If this event is swallowed, the keypress will not be passed to the string control, and the string will remain unchanged.
 
int CVICALLBACK StringCallback (int panel, int control, int event,  void *callbackData, int eventData1, int eventData2) {
 
     int key; // The ASCII part of the pressed key.
 
     switch (event){
           case EVENT_KEYPRESS:
   
              // Get the pressed key character.
              key = GetKeyPressEventCharacter (eventData2);
   
             // If a character is pressed, and it's not alpanumeric, swallow the event.
             if (key && !isalnum (key))
                   return 1;
             break;
     }
}


Message Edited by Wim S on 04-02-2008 01:44 PM
0 Kudos
Message 11 of 12
(1,039 Views)
That is an excellent example, thank you so much, it makes alot more sense now.  Thanks for all your help.
0 Kudos
Message 12 of 12
(1,021 Views)