LRESULT CALLBACK EventLoop::wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { EventLoop *self = (EventLoop *)Scheduler::getThis(); MORDOR_ASSERT(self->m_messageWindow == hWnd || self->m_messageWindow == NULL); if (uMsg == g_tickleMessage) { MORDOR_LOG_TRACE(g_log) << hWnd << " received tickle"; Scheduler::yield(); return 0; } switch (uMsg) { case WM_TIMER: { MORDOR_LOG_TRACE(g_log) << hWnd << " processing timers"; std::vector<boost::function<void ()> > expired = self->processTimers(); if (!expired.empty()) self->schedule(expired.begin(), expired.end()); unsigned long long nextTimer = self->nextTimer(); if (nextTimer != ~0ull) { UINT uElapse = (UINT)((nextTimer / 1000) + 1); uElapse = std::max<UINT>(USER_TIMER_MINIMUM, uElapse); uElapse = std::min<UINT>(USER_TIMER_MAXIMUM, uElapse); if (!SetTimer(hWnd, 1, uElapse, NULL)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SetTimer"); } else { if (!KillTimer(hWnd, 1)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("KillTimer"); } return 0; } default: return DefWindowProcW(hWnd, uMsg, wParam, lParam); } }