函数参考


_WinAPI_FindNextChangeNotification

Requests that the operating system signal a change notification handle the next time it detects an appropriate change.

#Include <WinAPIEx.au3>
_WinAPI_FindNextChangeNotification ( $hChange )

参数

$hChange A handle to a change notification handle created by the _WinAPI_FindFirstChangeNotification() function.

返回值

成功: 返回 1.
失败: 返回 0 并设置 @error 标志为非 0 值.

注意/说明

After the _WinAPI_FindNextChangeNotification() function returns successfully, the application can wait for
notification that a change has occurred by using the _WinAPI_Wait... functions.

The _WinAPI_FindNextChangeNotification() function should not be used more than once on the same handle without using
one of the wait functions. An application may miss a change notification if it uses _WinAPI_FindNextChangeNotification()
when there is a change request outstanding.

相关

详情参考

在MSDN中搜索


示例/演示


#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)

Global Const $sPath = @ScriptDir & '\~TEST~'

Global $hObj[2], $tObj, $pObj, $ID

DirCreate($sPath)
If Not FileExists($sPath) Then
    MsgBox(16, 'Error', 'Unable to create folder.')
    Exit
EndIf

OnAutoItExitRegister('OnAutoItExit')

$hObj[0] = _WinAPI_FindFirstChangeNotification($sPath, $FILE_NOTIFY_CHANGE_FILE_NAME)
$hObj[1] = _WinAPI_FindFirstChangeNotification($sPath, $FILE_NOTIFY_CHANGE_DIR_NAME)

If (Not $hObj[0]) Or (Not $hObj[1]) Then
    MsgBox(16, 'Error', 'Unable to create change notification.')
    Exit
EndIf

$tObj = DllStructCreate('ptr;ptr')
$pObj = DllStructGetPtr($tObj)
For $i = 0 To 1
    DllStructSetData($tObj, $i + 1, $hObj[$i])
Next

While 1
    Sleep(100)
    $ID = _WinAPI_WaitForMultipleObjects(2, $pObj, 0, 0)
    Switch $ID
        Case 0 ; WAIT_OBJECT_0
            ConsoleWrite('A file was created, renamed, or deleted in the directory.' & @CR)
        Case 1 ; WAIT_OBJECT_0 + 1
            ConsoleWrite('A directory was created, renamed, or deleted.' & @CR)
        Case Else
            ContinueLoop
    EndSwitch
    If Not _WinAPI_FindNextChangeNotification($hObj[$ID]) Then
        MsgBox(16, 'Error', 'Unexpected error.')
        Exit
    EndIf
WEnd

Func OnAutoItExit()
    For $i = 0 To 1
        If $hObj[$i] Then
            _WinAPI_FindCloseChangeNotification($hObj[$i])
        EndIf
    Next
;   DirRemove($sPath)
EndFunc   ;==>OnAutoItExit