Esempio n. 1
0
  virtual void ProcessGUIMessages()
  {
    // Adapted from MFC's CWinThread::Run() (thrdcore.cpp).

	_AFX_THREAD_STATE* pState = AfxGetThreadState();
	CWinApp* pApp = AfxGetApp();
    BOOL bIdle = TRUE;
    LONG lIdleCount = 0;
    // phase1: check to see if we can do idle work
    while (bIdle &&
        !::PeekMessage(&pState->m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
    {
      // call OnIdle while in bIdle state
      if (!pApp->OnIdle(lIdleCount++))
        bIdle = FALSE; // assume "no idle" state
    }
    // phase2: pump messages while available
    while (::PeekMessage(&pState->m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
    {
      // pump message, but quit on WM_QUIT
      if (!pApp->PumpMessage())
      {
        Terminate();
        pApp->ExitInstance();
      }
    }
    ::Sleep(0);
  }
Esempio n. 2
0
void ShMsgPump()
{
	// if we do MFC stuff in an exported fn, call this first!
	AFX_MANAGE_STATE(AfxGetStaticModuleState( ));

	DWORD dInitTime = GetTickCount();
	MSG m_msgCur;                   // current message
	CWinApp	*pWinApp = AfxGetApp();   
	while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE)  &&
			(GetTickCount() - dInitTime < 200) )	
	{
		pWinApp->PumpMessage();
	}
}