Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2002.03.04;
Скачать: CL | DM;

Вниз

Скажите, как отловить событие открытие файла на чтение...   Найти похожие ветки 

 
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 вся ветка

Текущий архив: 2002.03.04;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.008 c
4-9339
Ted
2002-01-05 12:11
2002.03.04
КАК спрятать минимизированное окно?????


6-9253
Alligator
2001-12-18 08:18
2002.03.04
Как создать-убрать сетевой диск вWin2000


1-9145
ДмитрийВ
2002-02-17 19:27
2002.03.04
в буфер кусок изображения на форме сохранить


3-9069
kserg@ukr.net
2002-02-06 12:50
2002.03.04
Как узнать дату последнего обновления файла-таблицы?


14-9285
Геннадий
2002-01-18 07:51
2002.03.04
Ребята, подскажите где можно скачать бесплатную версию InterBase