File Change Notification in Windows Mobile

Source: Internet
Author: User

 

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.