UDF > WinAPIEx > Files & Devices > Files >


_WinAPI_FindCloseChangeNotification

Arrête le handle de surveillance pour la notification des changements

#include <WinAPIFiles.au3>
_WinAPI_FindCloseChangeNotification ( $hChange )

Paramètre

$hChange Le handle de notification de changement créé par la fonction _WinAPI_FindFirstChangeNotification().

Valeur de retour

Succès: Retourne True.
Échec: Retourne False, appelez _WinAPI_GetLastError() pour obtenir des informations sur l'erreur

Voir aussi

Consultez FindCloseChangeNotification dans la librairie MSDN.

Exemple

#include <APIFilesConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <WinAPIProc.au3>

Opt('TrayAutoPause', 0)

Global Const $g_sPath = @TempDir & '\~TEST~'

DirCreate($g_sPath)
If Not FileExists($g_sPath) Then
    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Erreur', 'Impossible de créer le répertoire.')
    Exit
EndIf

OnAutoItExitRegister('OnAutoItExit')

Global $g_ahObj[2]
$g_ahObj[0] = _WinAPI_FindFirstChangeNotification($g_sPath, $FILE_NOTIFY_CHANGE_FILE_NAME)
$g_ahObj[1] = _WinAPI_FindFirstChangeNotification($g_sPath, $FILE_NOTIFY_CHANGE_DIR_NAME)

If (Not $g_ahObj[0]) Or (Not $g_ahObj[1]) Then
    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Erreur', 'Impossible de créer les notifications de changement.')
    Exit
EndIf

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

Local $iID, $bStopLoop = False

Do
    Sleep(100)
    $iID = _WinAPI_WaitForMultipleObjects(2, $pObj, 0, 0)

    Switch $iID
        Case 0 ; WAIT_OBJECT_0
            ConsoleWrite('Un fichier a été créé, renommé, ou supprimé dans le répertoire.' & @CRLF)
            $bStopLoop = Not _WinAPI_FindNextChangeNotification($g_ahObj[$iID])
        Case 1 ; WAIT_OBJECT_0 + 1
            ConsoleWrite('Un répertoire a été créé, renommé ou supprimé.' & @CRLF)
            $bStopLoop = Not _WinAPI_FindNextChangeNotification($g_ahObj[$iID])
    EndSwitch
Until $bStopLoop

MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Erreur', 'Erreur inattendu.')

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