Pelles C forum

C language => Beginner questions => Topic started by: Grincheux on April 12, 2017, 12:03:53 PM

Title: Monitoring File
Post by: Grincheux on April 12, 2017, 12:03:53 PM
I would like to be notified when a file changes.
I explain:
I wrote an image viewer.
I select a file then launch the associated file to edit the image file.
I resize the image.
I save the image.
I quit the editor.
At the point I would like to know if the image has been modified.
I found FindFirstChangeNotification (https://msdn.microsoft.com/en-us/library/aa364417%28VS.85%29.aspx)
and an example here (https://developersarea.wordpress.com/2014/09/26/win32-file-watcher-api-to-monitor-directory-changes/)
But is there an other method?
Title: Re: Monitoring File
Post by: liut on May 10, 2017, 08:55:40 AM
Try this way:

1. Use SHChangeNotifyRegister() to register a self-defined message

2. In main message loop, monitor this message; once the message delivers, use SHGetPathFromIDList() to analyse the shell file operations

3. Use SHChangeNotifyDeregister() to unregister the message when quitting

Please notice, if the system is very busy for a mass of file operations, not each file operation would be sent a message