Exemplo n.º 1
0
//**関数***************************************************************************
//	概要	:	デフォルトのメッセージ ループ
//*********************************************************************************
int CWindow::Run()
{
	if (!InitInstance())
		return ExitInstance();

	bool bIdle = TRUE;
	long lIdleCount = 0;
	for (;;)
	{
		while (bIdle && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE)) 
		{
			if (!OnIdle(lIdleCount++))
				bIdle = false;
		}

		do 
		{
			if (!PumpMessage())
				return ExitInstance();
			if (IsIdleMessage(&m_msgCur))
			{
				bIdle = true;
				lIdleCount = 0;
			}

		}
		while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
	}
	return -1;	// ここには来ないはず。
}
Exemplo n.º 2
0
int CWinThread::Run()
/*******************/
{
    MSG     msg;
    LONG    lCount = 0L;
    for( ;; ) {
        while( !::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) {
            if( OnIdle( lCount ) ) {
                lCount++;
            } else {
                ::WaitMessage();
            }
        }
        if( !PumpMessage() ) {
            break;
        }
        if( IsIdleMessage( &msg ) ) {
            if( OnIdle( lCount ) ) {
                lCount++;
            } else {
                ::WaitMessage();
            }
        } else {
            lCount = 0L;
        }
    }
    return( ExitInstance() );
}
Exemplo n.º 3
0
int CRadiantApp::Run( void ) {
	BOOL bIdle = TRUE;
	LONG lIdleCount = 0;
#if _MSC_VER >= 1300
	MSG *msg = AfxGetCurrentMessage();			// TODO Robert fix me!!
#else
	MSG *msg = &m_msgCur;
#endif
	// phase1: check to see if we can do idle work
	while( bIdle &&	!::PeekMessage( msg, NULL, NULL, NULL, PM_NOREMOVE ) ) {
		// call OnIdle while in bIdle state
		if( !OnIdle( lIdleCount++ ) ) {
			bIdle = FALSE; // assume "no idle" state
		}
	}
	// phase2: pump messages while available
	do {
		// pump message, but quit on WM_QUIT
		if( !PumpMessage() ) {
			return ExitInstance();
		}
		// reset "no idle" state after pumping "normal" message
		if( IsIdleMessage( msg ) ) {
			bIdle = TRUE;
			lIdleCount = 0;
		}
	} while( ::PeekMessage( msg, NULL, NULL, NULL, PM_NOREMOVE ) );
	return 0;
}
Exemplo n.º 4
0
int CWinThread::RunLoop() {
	bool bIdle = true;
	LONG lIdleCount = 0;
	_AFX_THREAD_STATE* pState = AfxGetThreadState();
	while (true)
	{
#if UCFG_GUI
		while (bIdle && !::PeekMessage(&(pState->m_msgCur), 0, 0, 0, PM_NOREMOVE))
			bIdle = OnIdle(lIdleCount++);
#endif
		do
		{
			//#ifndef NO_GUI //!!!
			if (!PumpMessage())
				return ExitInstance();
			//#endif

			if (IsIdleMessage(pState->m_msgCur))
			{
				bIdle = true;
				lIdleCount = 0;
			}
		}
		while (::PeekMessage(&(pState->m_msgCur), NULL, NULL, NULL, PM_NOREMOVE));
	}
}
Exemplo n.º 5
0
void CProtectedWinThread::PumpMessages()
{
	ASSERT_VALID(this);

	// for tracking the idle time state
	BOOL bIdle = TRUE;
	LONG lIdleCount = 0;
#if _MFC_VER >= 0x0710
	_AFX_THREAD_STATE* pState = AfxGetThreadState();
	MSG &msgCur = pState->m_msgCur;
#else
	MSG &msgCur = m_msgCur;
#endif /* _MFC_VER_ */	

	// acquire and dispatch messages until a WM_QUIT message is received.
	for (;;)
	{
		// phase1: check to see if we can do idle work
		while (bIdle &&
			!::PeekMessage(&msgCur, NULL, NULL, NULL, PM_NOREMOVE))
		{
			// call OnIdle while in bIdle state
			if (!OnIdle(lIdleCount++))
				bIdle = FALSE; // assume "no idle" state
		}
		// phase2: pump messages while available
		do
		{
			// pump message, but quit on WM_QUIT
			if (!PumpMessage()) {
#if defined(_DEBUG)
#	if _MFC_VER < 0x0710
				m_nDisablePumpCount--; // application must NOT die
#	else
				pState->m_nDisablePumpCount--; // application must NOT die
#	endif
#endif
				return;
			}

			// reset "no idle" state after pumping "normal" message
			if (IsIdleMessage(&msgCur))
			{
				bIdle = TRUE;
				lIdleCount = 0;
			}

		} while (::PeekMessage(&msgCur, NULL, NULL, NULL, PM_NOREMOVE));
	}

	ASSERT(FALSE);  // not reachable
}
Exemplo n.º 6
0
    int SMessageLoop::Run()
    {
        BOOL bDoIdle = TRUE;
        int nIdleCount = 0;
        BOOL bRet;
        
        m_bRunning = TRUE;
		m_bQuit = FALSE;
        for(;;)
        {
            while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
            {
                if(!OnIdle(nIdleCount++))
                    bDoIdle = FALSE;
				if (m_bQuit) goto exit_loop;
            }

            bRet = ::GetMessage(&m_msg, NULL, 0, 0);

            if(bRet == -1)
            {
                SLOGFMTE(_T("::GetMessage returned -1 (error)"));
                continue;   // error, don't process
            }
            else if(!bRet)
            {
                SLOGFMTT(_T("SMessageLoop::Run - exiting,code = %d"),(int)m_msg.wParam);
                break;   // WM_QUIT, exit message loop
            }
            
            OnMsg(&m_msg);

            if(IsIdleMessage(&m_msg))
            {
                bDoIdle = TRUE;
                nIdleCount = 0;
            }
			if (m_bQuit) break;
        }

	exit_loop:
        m_bRunning = FALSE;
        
        return (int)m_msg.wParam;
    }
bool CefMessageLoopDispatcher::Dispatch(const MSG &msg)
{
	static BOOL bDoIdle = TRUE;

	TranslateMessage(&msg);
	DispatchMessage(&msg);

	if (IsIdleMessage(&msg))
	{
		bDoIdle = TRUE;
	}

	while (bDoIdle && !::PeekMessage(const_cast<MSG*>(&msg), NULL, 0, 0, PM_NOREMOVE))
	{
		CefDoMessageLoopWork();
		bDoIdle = FALSE;
	}

	return true;
}
Exemplo n.º 8
0
// message loop
int CDUIMessageLoop::Run()
{
	BOOL bDoIdle = TRUE;
	int nIdleCount = 0;
	BOOL bRet;
	
	for(;;)
	{
		while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
		{
			if(!OnIdle(nIdleCount++))
				bDoIdle = FALSE;
		}
		
		bRet = ::GetMessage(&m_msg, NULL, 0, 0);
		
		if(bRet == -1)
		{
			continue;   // error, don't process
		}
		else if(!bRet)
		{
			break;   // WM_QUIT, exit message loop
		}
		
		if(!PreTranslateMessage(&m_msg))
		{
			::TranslateMessage(&m_msg);
			::DispatchMessage(&m_msg);
		}
		
		if(IsIdleMessage(&m_msg))
		{
			bDoIdle = TRUE;
			nIdleCount = 0;
		}
	}
	
	return (int)m_msg.wParam;
}
Exemplo n.º 9
0
    int SMessageLoop::Run()
    {
        BOOL bDoIdle = TRUE;
        int nIdleCount = 0;
        BOOL bRet;

        for(;;)
        {
            while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
            {
                if(!OnIdle(nIdleCount++))
                    bDoIdle = FALSE;
            }

            bRet = ::GetMessage(&m_msg, NULL, 0, 0);

            if(bRet == -1)
            {
                STRACE(_T("::GetMessage returned -1 (error)"));
                continue;   // error, don't process
            }
            else if(!bRet)
            {
                STRACE(_T("SMessageLoop::Run - exiting"));
                break;   // WM_QUIT, exit message loop
            }
            
            OnMsg(&m_msg);

            if(IsIdleMessage(&m_msg))
            {
                bDoIdle = TRUE;
                nIdleCount = 0;
            }
        }

        return (int)m_msg.wParam;
    }