LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Need a way to collect and supress stray mouse clicks or keypresses

I have not found a way to trap all user events when a process is running.

Essentially my program executes in a simple loop:

//intialize panels, variables, etc.
program_running=1;
while(program_running)
{
ProcessSystemEvents();
//read data from comport
//process data
}
//end program

All control events are processed in callbacks.

I have several processes during which the user is supposed to wait. I put up a message panel and inhibit events:

InstallPopup(messagePanel)
SetSystemAttribute (ATTR_SUPPRESS_EVENT_PROCESSING, YES);
//process code executes here, user is suppoes to wait
SetSystemAttribute (ATTR_SUPPRESS_EVENT_PROCESSING, NO);
RemovePopup
(0);

At this point if the user has pressed the mouse when he is not supposed to, and if there is a control where he pressed the mouse, the callback is processed. So I tried this loop to catch the unwanted events:

event=1;
while(event)
event=GetUserEvent(0,&panel,&control);

It catches the first event, but then executes the callback.

Is there any way to prevent these unwanted callbacks from executing?
0 Kudos
Message 1 of 5
(3,230 Views)
While the process is running, I also change the mouse cursor to the hourglass, and set the panel attribute for the main panel to ATTR_DIMMED=1. And I still get the stray events.
0 Kudos
Message 2 of 5
(3,230 Views)
Hi,

There are different ways that you can disable the events on your controls.

The firts is just add a global flag that gets checked in every callback; you tunt it on, the callbacks get generated but they do nothing.

Another more elegant option would be to create an array of the control IDs and an array of callbacks; then have a loop that uses the function InstallCtrlCallback(..) to pass NULL as the callback to all of the controls. Then another loop that passes the right callback when you need to enable the controls again.

Another good idea here that may be the easiest to implement is to create a decoration that covers all your controls. Make this decoration transparent and make it visible when you want to disable the events. The decoration would "cover
" every control and catch the events for them.

I hope this helps.

Regards,
Juan Carlos
N.I.
0 Kudos
Message 3 of 5
(3,230 Views)
Thanks for the suggestions.

Trying to aviod changing all my callbacks, I first tried making a function to loop thru all panels and controls, and disable all controls, later calling the same function to enable them again. That didnt work.

Then I tried makeing a decoration to cover the controls, setting it to transparent, with a callback to collect events. That didnt seem to work well either.

I then made a gobal variable and set it to 1 during times when I need to suppress events, and I check for this in the control callbacks. This method works the best.
0 Kudos
Message 4 of 5
(3,230 Views)
Hi,

I'm glad that you were able to get it to work. For future reference here is a small example of the methonds that I mentioned before. I'm disabling the control on the top using the decoration and assigning a NULL callback.

Hope this helps.

Regards,

Juan Carlos
0 Kudos
Message 5 of 5
(3,230 Views)