Dear Sir,
I just write a program that comminucate with serial port on Pocket PC,I use
a MFC thread to read data from it, when one byte received then this thread
use PostMessage to pass this byte to main window,but when this thread keep
running the UI will be blocking.here is all the code about that:
1,when CSerial object created this function will be called.
BOOL CSerial::OpenReadThread()
{
    if (!(m_hReadThread = AfxBeginThread(PortReadThread, this)))
      return FALSE;
 return TRUE;
}
2,thread function to read data from serial port.
UINT PortReadThread(LPVOID lpParameter)
{
     BYTE byte;
    DWORD num;
    DWORD dwCommModemStatus;
 CSerial* pThis=(CSerial*)lpParameter;
    // Specify a set of events to be monitored for the port.
 SetCommMask (pThis->m_hCommPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD );
 while (pThis->m_hCommPort != INVALID_HANDLE_VALUE)
{
  WaitCommEvent(pThis->m_hCommPort, &dwCommModemStatus, 0);
  // Re-specify the set of events to be monitored for the port.
  SetCommMask (pThis->m_hCommPort, EV_RXCHAR | EV_CTS | EV_DSR  );
          if(dwCommModemStatus & EV_RXCHAR)
          {
               do
               {
                     EnterCriticalSection(&pThis->m_csCommunicationSync);
                    ReadFile(pThis->m_hCommPort, &byte, 1, &num, 0);
                     LeaveCriticalSection(&pThis->m_csCommunicationSync);
                    if(num == 1)
                    PostMessage(pThis->m_pOwner->m_hWnd,WM_COMM_RXCHAR,
(WPARAM)byte, 0);
               } while (num == 1);
          }
 } return 0;
}
3,In main window get data when received message from serial port:BEGIN_MESSAGE_MAP(CCAMitIGSMDlg, CDialog)
 ON_MESSAGE(WM_COMM_RXCHAR, OnCommunication)
END_MESSAGE_MAP()CSerial* m_Port;
m_Port=new CSerial();
LONG CCAMitIGSMDlg::OnCommunication(WPARAM ch, LPARAM port)
{
// deal with the received data,this function will take a long time.
}I can get all the data from serial port on main window,
but I still need user interaction with UI,
could you help me?thanks!Best Regards,
yubin