Форум: "WinAPI";
Текущий архив: 2002.03.04;
Скачать: [xml.tar.bz2];
ВнизСкажите, как отловить событие открытие файла на чтение... Найти похожие ветки
← →
mIg (2001-12-19 10:46) [0]Скажите, как отловить событие: открытие какого-нибудь файла на чтение, в определённой папке?
← →
Бирзул Александр (2002-01-04 19:49) [1]Как отловить событие самому интересно, но могу предложить решение предложенное тут же в факах: по таймеру делать опрос аттрибутов файла на время последнего доступа к файлу. Функция FindFirst,перменная SearchRec.XXXXXXX в качестве XXX...XXX - то ли LastAccess то ли LastTime.
← →
Vovchik (2002-01-04 22:44) [2]Нет, уж лучше тогда использовать GetFileAttributesEx. Правда, в 95-ой винде не будет работать. Или GetFileInformationByHandle. Но тогда файл придётся держать открытым.
Но вообще, MS SDK предлагает использовать FindFirstChangeNotification, FindNextChangeNotification и WaitForMultipleObject. Эти функции могут следить за изменениями, происходящими в некоторой директории или дереве. Есть там флаг контролировать изменения атрибутов. Я сам не пробовал, но может получится? Вот пример функции из SDK. На Це++, но, кому надо, думаю, разберётся:
Monitoring Changes in a Directory or Directory Tree
The following example monitors the directory tree starting at C:\ for directory name changes. It also monitors the C:\WINDOWS directory for file name changes.
The example uses the FindFirstChangeNotification function to create two notification handles and the WaitForMultipleObjects function to wait on the handles. Whenever a directory is created or deleted in the tree starting at C:\ , the example updates the entire directory tree. Whenever a file is created or deleted in the C:\WINDOWS directory, the example refreshes the WINDOWS directory. The FindNextChangeNotification function restarts the change notification each time the example processes a change.
DWORD dwWaitStatus;
HANDLE dwChangeHandles[2];
// Watch the C:\WINDOWS directory for file creation and
// deletion.
dwChangeHandles[0] = FindFirstChangeNotification(
"C:\\WINDOWS", // directory to watch
FALSE, // do not watch the subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes
if (dwChangeHandles[0] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
// Watch the C:\ subtree for directory creation and
// deletion.
dwChangeHandles[1] = FindFirstChangeNotification(
"C:\\", // directory to watch
TRUE, // watch the subtree
FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes
if (dwChangeHandles[1] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
// Change notification is set. Now wait on both notification
// handles and refresh accordingly.
while (TRUE)
{
// Wait for notification.
dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles,
FALSE, INFINITE);
switch (dwWaitStatus)
{
case WAIT_OBJECT_0:
// A file was created or deleted in C:\WINDOWS.
// Refresh this directory and restart the
// change notification. RefreshDirectory is an
// application-defined function.
RefreshDirectory("C:\\WINDOWS")
if ( FindNextChangeNotification(
dwChangeHandles[0]) == FALSE )
ExitProcess(GetLastError());
break;
case WAIT_OBJECT_0 + 1:
// A directory was created or deleted in C:\.
// Refresh the directory tree and restart the
// change notification. RefreshTree is an
// application-defined function.
RefreshTree("C:\\");
if (FindNextChangeNotification(
dwChangeHandles[1]) == FALSE)
ExitProcess(GetLastError());
break;
default:
ExitProcess(GetLastError());
}
}
Built on Wednesday, April 21, 1999
Читайте SDK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2002.03.04;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.005 c