Here is some code we worked out. It's not particularly useful, but I am posting it here so I can delete it from my desktop:
SuperStrict
Import maxgui.drivers
Extern "win32"
Function FindFirstChangeNotificationA:Int(lpPathName$z,bWatchSubtree:Int,dwNotifyFilter:Int)
Function FindNextChangeNotification(hChangeHandle:Int)
Function WaitForMultipleObjects(nCount:Int,lpHandles:Byte Ptr,bWaitAll:Int,dwMilliseconds:Int)
Function FindCloseChangeNotification(hChangeHandle:Int)
EndExtern
Const WAIT_FAILED% = $FFFFFFFF
Const WAIT_OBJECT_0% = $0
Const WAIT_ABANDONED% = $80
Const WAIT_TIMEOUT% = $102
Const FILE_NOTIFY_CHANGE_FILE_NAME:Int=$001
Const FILE_NOTIFY_CHANGE_DIR_NAME:Int=$002
Const FILE_NOTIFY_CHANGE_SIZE:Int=$008
Const FILE_NOTIFY_CHANGE_LAST_WRITE:Int=$10
Const FILE_NOTIFY_CHANGE_SECURITY:Int=$100
Const FILE_NOTIFY_CHANGE_ATTRIBUTES:Int=$004
CreateWindow("My Window",300,400,320,240)
Local folder:String[]=["C:\"]
Local handle:Int[folder.length]
Local result:Int
Local n:Int
Local flags:Int=FILE_NOTIFY_CHANGE_LAST_WRITE
For n=0 To folder.length-1
handle[n]=FindFirstChangeNotificationA(folder[n],True,flags)
Next
Repeat
If PeekEvent()
If WaitEvent () = Event_WINDOWCLOSE Exit
EndIf
result=WaitForMultipleObjects(folder.length,handle,False,0)
If result=>WAIT_OBJECT_0 And result<WAIT_OBJECT_0+folder.length
Local time:Int=MilliSecs()
For n=1 To 1
FindNextChangeNotification(handle[result-WAIT_OBJECT_0])
Next
Print (MilliSecs()-time)
Print "Change detected within folder: "+folder[result-WAIT_OBJECT_0]
EndIf
Forever
For n=0 To folder.length-1
FindCloseChangeNotification(handle[n])
Next
End
|