ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Пятница
22 ноября
324935 Топик полностью
koyodza (23.04.2012 22:18, просмотров: 156) ответил mazur на Поправил. Очередь событий.
кусочег  typedef struct tagPROCINFOSTRUCT { void* pProc; DWORD param32; __int32 delay; __int32 period; } PROCINFOSTRUCT; typedef struct tagTASKSINFOSTRUCT { PROCINFOSTRUCT* pProcInfo; int size; int max; int count; } TASKSINFOSTRUCT; void DeleteMessage(TASKSINFOSTRUCT* pTasks, int pos) { int size = pTasks->size; PROCINFOSTRUCT* pDst = pTasks->pProcInfo + pos; PROCINFOSTRUCT* pSrc = pDst + 1; size--; for (int i = pos; i < size; i++) { if (!pSrc->pProc) break; *pDst++ = *pSrc++; } CLR(*pDst); pTasks->count--; } int AddProc(TASKSINFOSTRUCT* pTasks, void* pFn, DWORD param32, __int32 delay, __int32 period) { if (pTasks->count >= pTasks->size) { #ifdef __DEBUG __Fault(1, 1); #endif return FALSE; } PROCINFOSTRUCT* pMsg = pTasks->pProcInfo + pTasks->count; pMsg->pProc = pFn; pMsg->delay = delay; pMsg->period = period; pMsg->param32 = param32; pTasks->count++; if (pTasks->count > pTasks->max) pTasks->max = pTasks->count; return TRUE; } int TaskMgr(TASKSINFOSTRUCT* pTasks, int nTask, int dTime) { int nMsgCount = pTasks->count; if (nTask < 0 || nTask >= nMsgCount) return MIN_INT32; PROCINFOSTRUCT* p = pTasks->pProcInfo + nTask; p->delay -= dTime; if (p->delay <= 0) { void* pProc = p->pProc; DWORD param32 = p->param32; if (!pProc) { DeleteMessage(pTasks, nTask); return MIN_INT32; } if (p->period > 0) p->delay += p->period; else if (p->period < 0) p->delay = 0; else DeleteMessage(pTasks, nTask--); ((void(*)(DWORD))(pProc))(param32); } nTask++; return nTask; }