Delete a file in resource manager and change the name of a folder. How is this done? The answer is the file change notification.
First look at a structure
Typedef struct tagshchangenotifyentry {
DWORD dweventmask;
Lptstr pszwatchdir;
Bool frecursive;
} Shchangenotifyentry;
To receive the file change message, we need to use a window hwnd and register it in the wm_create message created in the window:
Shchangenotifyentry schnenotifyentry;
Schnenotifyentry. dweventmask = shcn_allevents; // monitors all events
Schnenotifyentry. pszwatchdir = NULL; // The name of the directory to be monitored. null indicates all
Schnenotifyentry. frecursive = true; // whether to recursion when monitoring the Directory
Shchangenotifyregister (hwnd, & schnenotifyentry );
In the window procedure function, we respond to the wm_filechangeinfo message.
Case wm_filechangeinfo:
{
Filechangenotify * lpfcn;
Filechangeinfo * lpfci;
Lpfcn = (filechangenoworkflow *) lparam;
If (null = lpfcn)
{
Break;
}
Lpfci = & (lpfcn-> FCI );
If (null = lpfci)
{
Break;
}
Else
{
If (false = shcnevent (lpfci ))
{
MessageBox (text ("schne event failed"), text ("error"), mb_ OK );
}
}
Shchangenotifyfree (lpfcn );
}
Break;
Implementation of the shcnevent function is as follows:
Bool shcnevent (filechangeinfo * lpfci)
{
// Lpfci-> weventid, event
// Lpfci-> dwitem1, old file or directory name
// Lpfci-> dwitem2, new file or directory name
// Lpfci-> dwattributes, file or directory features
// Lpfci-> ftmodified, time when the file is changed
// Lpfci-> nfilesize, file size
Switch (lpfci-> weventid)
{
Case shcn_renameitem:
Break;
Case shcn_create:
Break;
Case shcn_delete:
Break;
Case shcn_mkdir:
Break;
Case shcn_rmdir:
Break;
Case shcn_mediainserted:
Break;
Case shcn_mediaremoved:
Break;
Case shcn_driveadd:
Break;
Case shcn_driveremoved:
Break;
Case shcn_netshare:
Break;
Case shcn_netunshare:
Break;
Case shcn_attributes:
Break;
Case shcn_updatedir:
Break;
Case shcn_serverdisconnect:
Break;
Case shcn_renamefolder:
Break;
Default:
Break;
}
Return true;
}
Based on the event, you can know which file or directory has changed.
Finally, log out at the hwnd destruction:
Shchangenotifyderegister (hwnd );
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/pknife/archive/2009/08/27/4490213.aspx