API函数FindFirstChangeNotification可以用于对一目录创建文件系统更改通知句柄,并设置通知条,而该通知句柄可以被Windows的“Wait”类函数利用来监视该目录
解决方案 »
- 内存似乎泄漏的很厉害,但IDE却检查不出来 麻烦大家帮我看看我这个函数
- 高手进来帮忙!MapX中图标的移动问题
- 压缩完access后推出程序后错误
- 这个XML格式的文件怎样解析出来 ?
- vc2010子窗口刷新慢
- MFC中怎样在文件末尾追加数据?
- 请问在VC中有没有比较好的调试ActiveX插件的方法呢?
- 在WIN中如何实现消息机制?
- 在自绘一个菜单,我怎么知道当前所绘制的是不是一个分割条呢~~, 请各位帮帮忙,给分~~
- 我装了.NET后,在生成VC中MFC项目时,总会提示frame.h模板文件错误,有哪位高手指点一下
- CVS哪儿有下载 for win/linux ????
- VC内存泄漏问题好严重啊!
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());
}
}
摘自msdn