在使用这两个函数之前,必须要先声明它们的原型,同时还要添加一些宏和结构定义。我们在原工程中添加一个ShellDef.h头文件,然后加入如下声明: #define SHCNRF_InterruptLevel 0x0001 //Interrupt level notifications from the file system #define SHCNRF_ShellLevel 0x0002 //Shell-level notifications from the shell #define SHCNRF_RecursiveInterrupt 0x1000 //Interrupt events on the whole subtree #define SHCNRF_NewDelivery 0x8000 //Messages received use shared memory
typedef struct { LPCITEMIDLIST pidl; //Pointer to an item identifier list (PIDL) for which to receive notifications BOOL fRecursive; //Flag indicating whether to post notifications for children of this PIDL }SHChangeNotifyEntry;
typedef struct { DWORD dwItem1; // dwItem1 contains the previous PIDL or name of the folder. DWORD dwItem2; // dwItem2 contains the new PIDL or name of the folder. }SHNotifyInfo;
typedef ULONG (WINAPI* pfnSHChangeNotifyRegister) ( HWND hWnd, int fSource, LONG fEvents, UINT wMsg, int cEntries, SHChangeNotifyEntry* pfsne );
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());
//监视C:\下子目录树的文件创建和删除
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.