Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
xgadkob
Old
#1  
Junior Member - OP
Thanks Meter 1
Posts: 22
Join Date: Apr 2003
Default how to process events in a loop

Hi,

in my C-Program there is a loop, where data are send and received.

I want to give the user a chance to break this loop.
There is a push-button on the dialog-form. In the event-handler there is a flag, which is set, when the button is pressed. But when the program is running in the lopp, this code is never reached.

In the loop, I want to break, if the flag is set.

How can I achieve that the button-pressed-event is processed,
when the program ist running in the transmission-loop.

Perhaps someone knows a solution.

Have a nice day!

Franz
 
jrom
Old
#2  
Junior Member
Thanks Meter 0
Posts: 13
Join Date: Feb 2003
Have you tried running the 'loop' in a different thread then the User Interface? It might be the problem that the main thread is so busy looping that it ignored/doesn't receive the button press...
 
belial
Old
#3  
Member
Thanks Meter 0
Posts: 42
Join Date: Apr 2003
Default Re: how to process events in a loop

Your best solution would be to kick off your loop as a seperate thread.

the other option is to process messages every so often, by peeking and pumping the message handler.

The thread method is the cleanest by far.

..Chuck..
 
benclewett
Old
#4  
Member
Thanks Meter 0
Posts: 58
Join Date: Jul 2003
Location: London
Quote:
the other option is to process messages every so often, by peeking and pumping the message handler.
Is this like the old VB command DoEvents?

I am looking for a way to process the WM_PAINT event of a form, whilst again in a loop, which the DoEvents would have perfectly completed.

Have you a code example for 'peeking and pumping'?

Thanks!

Ben.
 
belial
Old
#5  
Member
Thanks Meter 0
Posts: 42
Join Date: Apr 2003
Quote:
Originally Posted by benclewett
Have you a code example for 'peeking and pumping'?
void CProgressDlg::PeekAndPump()
{
MSG msg;
while (::PeekMessage(&msg, NULL,0,0,PM_NOREMOVE)) {
if (!AfxGetApp()->PumpMessage()) {
::PostQuitMessage(0);
return;
}
}
}
 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

report this ad
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...