怎么可能,OnIdle是在主线程里运行的,要么运行OnIdle要么运行事件处理,不会同时执行的

解决方案 »

  1.   

    int CWinThread::Run()
    {
    ASSERT_VALID(this);
    _AFX_THREAD_STATE* pState = AfxGetThreadState(); // for tracking the idle time state
    BOOL bIdle = TRUE;
    LONG lIdleCount = 0; // 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(&(pState->m_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())
    return ExitInstance(); // reset "no idle" state after pumping "normal" message
    //if (IsIdleMessage(&m_msgCur))
    if (IsIdleMessage(&(pState->m_msgCur)))
    {
    bIdle = TRUE;
    lIdleCount = 0;
    } } while (::PeekMessage(&(pState->m_msgCur), NULL, NULL, NULL, PM_NOREMOVE));
    }
    }
      

  2.   

    只是说明,OnIlde是在主消息循环的线程中运行,要么做OnIdle,要么做消息处理