设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> Visual C++ >> [C++]监控特定文件夹的事件:三种解决方法汇总
精品推荐
Visual C++点击TOP10
·用WINSOCK实现聊天室的VC++程序设计
·利用mfc编写activex控件
·用vc实现生产者消费者问题
·DirectX8.0
·C/C++ 大量经典编程书籍下载
·VC快捷键大全
·CreateFileMapping的MSDN翻译和使用心得
·Windows环境下的麦克风录音系统
·挂钩Windows API
·如何开发OPC Server
编程开发点击TOP10
·数字小键盘指法练习
·用C语言编通讯录程序(初学者级别的)
·ASP.NET 程序中常用的三十三种代码
·我写的Java学生成绩管理系统源代码
·CHK文件恢复工具
·Modem 常用AT指令集
·java笔试题
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
精选专题

[C++]监控特定文件夹的事件:三种解决方法汇总

作者: 来源:网络文章 时间:2005-12-13 17:13:07

监控特定文件夹的事件:三种解决方法汇总XML:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

LDBIVR程序中要监视特定文件夹的文件落地或者删除事件,本来要用SHELL中的事件通知机制,后来因为要考虑到各种意外事件,如服务意外退出、服务器崩溃等,遂作罢。

对于目录事件异步通知,大致有三个方法:

调用Windowsapi函数ReadDirectoryChanges监视指定目录中文件(推荐使用),这个使用异步IO

ASP?url=/library/en-us/fileio/base/readdirectorychangesw.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/readdirectorychangesw.asp

The ReadDirectoryChangesW function retrieves information that describes the changes within a directory.

To track changes on a volume, see change journals.

BOOL ReadDirectoryChangesW(

  HANDLE hDirectory,

  LPVOID lpBuffer,

  DWord nBufferLength,

  BOOL bWatchSubtree,

  DWORD dwNotifyFilter,

  LPDWORD lpBytesReturned,

  LPOVERLAPPED lpOverlapped,

  LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine

);

 

 

或者用SHChangeNotifyRegisterSHChangeNotifyDeregister来注册事件SHChangeNotify

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shchangenotify.asp

 

SHChangeNotify Function


Notifies the system of an event that an application has performed. An application should use this function if it performs an action that may affect the Shell.

Syntax

void SHChangeNotify(      
    LONG wEventId,

    UINT uFlags,

    LPCVOID dwItem1,

    LPCVOID dwItem2

);

这个SHELL事件,有人这么介绍(http://qk.5nx.com/article_view.asp?id=11)。

 

或者调用API函数-FindFirstChangeNotification FindCloseChangeNotificationFindNextChangeNotification WaitForSingleObject

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstchangenotification.asp

FindFirstChangeNotification

The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle sUCceeds when a change matching the filter conditions occurs in the specified directory or subtree. However, the function does not indicate the change that satisfied the wait condition.

To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.

HANDLE FindFirstChangeNotification(

  LPCTSTR lpPathName,

  BOOL bWatchSubtree,

  DWORD dwNotifyFilter

);


著名的FileMon工具用的是虚拟驱动。 

 

相关资源:

1:《CSdn.net/article/0/408.shtm">监视程序的编制》;

2:《Win32中的目录监控》;

3:《change journals》;

4:《CDirectoryChangeWatcher - ReadDirectoryChangesW all wrapped up》;

5:《监测目录活动》;

6:《Delphibbs.com/delphibbs/dispq.asp?lid=693107">请问如何监视系统对文件的访问?》。


[C++]监控特定文件夹的事件:三种解决方法汇总 相关文章:
[C++]监控特定文件夹的事件:三种解决方法汇总 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com