LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to programmatically fire an event from within the callback for the event

Solved!
Go to solution

I need to send a UI control event, through the message system so as to not be re-entrant, at the end of the control event callback to cause it to run as a loop.

I regularly call ProcessSystemEvents() so that the ui doesn't lock up. In MFC I could just call SendMessage() function with the control id and event id in the WParam. This would allow me to exit the callback function, and the next time the app message pump runs, it would fire the requested event. I've tried QueueUserEvent(), both with EVENT_COMMIT and with a generic message id 1001, but neither one fired the event callback. I've tried CallCtrlCallback(). This seems to call the callback function directly which causes it to be re-entrant.

 

Is there another way to do this?

0 Kudos
Message 1 of 3
(1,587 Views)
Solution
Accepted by topic author TechnoMage41

I originally thought I couldn't use "PostDeferredCall(DeferredCallbackPtr deferredFunction, void *callbackData)" because the parameters didn't match the callback "int CVICALLBACK RunSequence(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)".

What I ended up doing is to create an intermediate function that I called using PostDeferredCall(), which in turn directly calls my callback with the proper parameters:

 

PostDeferredCall(&callRunEvent, NULL)

...

void callRunEvent(void *data)
{
     RunSequence(hndMainPanel, PANEL_RUN, EVENT_COMMIT, data, 0, 0);
}

0 Kudos
Message 2 of 3
(1,583 Views)

While your system works, I'm suspecting there may be a better, more efficient way of doing what you want than faking the user to compulsively click on a button. There are a couple ways of having a process running in the background leaving the UI responsive: if you can describe your process we may be able to suggest you some alternative.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 3
(1,479 Views)