Click to See Complete Forum and Search --> : mscomm


farshad
April 21st, 1999, 11:14 PM
I am using MFC MSComms control to receive data from the serial port. I want a function to receive information from the serial port before it returns (wait for serial port events). I know that in Visual Basic DoEvents() method can be used to yield conrol to the operating system giving it a chance to process serial port events. What is the equivalent process
in MFC C++.

Thanks in anticipation
Farshad.

James Lacey
April 22nd, 1999, 03:53 PM
I am not aware of any function in MFC like VB's DoEvents.
If I understand what it is you want to do, you should probably use a worker thread to read the serial port.

Another approach is to override CWinApp::OnIdle() or you could (but I wouldn't recommend) create you own message pump.

Andrei Korobkov
April 22nd, 1999, 04:30 PM
MFC used to have straight analog of DoEvents in Win 16 API: PumpWaitingMessages.
You can use not documented Afx PumpMessage in Win 32 in the following manner:
void MyClass::PumpWaitingMessages()
{
MSG msg;
while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ))
{
// If it is your message go ahead and proceed
if(( msg.message == WM_CHAR ) && ( msg.wParam == VK_ESCAPE ))
{
OnCancel();
}
AfxGetApp()->PumpMessage();
}
}