Вот так таймер работает:
| Код | int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int cmdShow) { SetTimer(NULL, NULL, MY_TIME_PERIOD, (TIMERPROC)MyTimerProc); MessageCycle():
return 0; }
VOID CALLBACK MyTimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwtime) { i++; }
void MessageCycle() { MSG msg; BOOL bRet; while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) { if (bRet == -1) { // handle the error anpossibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } } } |
А вот так нет:| Код | int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int cmdShow) { SetTimer(NULL, NULL, MY_TIME_PERIOD, (TIMERPROC)MyTimerProc); Cycle();
return 0; }
void Cycle() { HANDLE hDir = CreateFile(_T(pathDir), // pointer to the file name FILE_LIST_DIRECTORY, // access (read/write) mode FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, // share mode NULL, // security descriptor OPEN_EXISTING, // how to create FILE_FLAG_BACKUP_SEMANTICS, // file attributes (FILE_FLAG_OVERLAPPED) NULL); // file with attributes to copy const DWORD dwNotificationFlags = FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_FILE_NAME; FILE_NOTIFY_INFORMATION Buffer[1024]; DWORD BytesReturned; VOID *pBuf = (BYTE*)&Buffer;
while (ReadDirectoryChangesW(hDir, // handle to directory &Buffer, // read results buffer sizeof(Buffer), // length of buffer TRUE, // monitoring option dwNotificationFlags, &BytesReturned, // bytes returned NULL, // overlapped buffer NULL)) // completion routine { FILE_NOTIFY_INFORMATION* pInfo = (FILE_NOTIFY_INFORMATION*) pBuf; SelectAction(pInfo);
} CloseHandle(hDir);
}
VOID CALLBACK MyTimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwtime) { i++; } |
Как организовать работу MyTimerProc?
VS 2008 |