Inscrit une fenêtre pour recevoir des notifications du système de fichiers ou du Shell
#include <WinAPIShellEx.au3>
_WinAPI_ShellChangeNotifyRegister ( $hWnd, $iMsg, $iEvents, $iSources, $aPaths [, $bRecursive = False] )
$hWnd | Handle de la fenêtre qui doit recevoir les messages de changement ou de notification. |
$iMsg | Message à poster à la procédure de fenêtre. |
$iEvents | Change les événements de notification pour lequel recevoir les notifications. Ce paramètre peut prendre une ou plusieurs des valeurs $SHCNE_*. |
$iSources | Une ou plusieurs des valeurs suivantes qui indiquent le type d'événement pour lequel recevoir les notifiations $SHCNRF_INTERRUPTLEVEL $SHCNRF_SHELLLEVEL $SHCNRF_RECURSIVEINTERRUPT $SHCNRF_NEWDELIVERY |
$aPaths | Chemin unique ou tableau de chemin pour lequel vous souhaitez recevoir des notifications. Ces noms doivent être des chemins pleinement qualifiés pour éviter des résultats inattendus. |
$bRecursive | [optionnel] Spécifie s'il faut poster les notifications pour les chemins enfants du paramètre $aPaths, les valeurs valabless sont: True - Les notifications proviendraient des enfants du dossier. False - Les notifications proviendraient du dossier spécifié uniquement (par défaut). |
Succès: | Retourne l'ID d'inscription. |
Échec: | Retourne 0 et définit @error <> 0. |
Lorsqu'un changement d'événement de notification est déclenché, le message indiqué par $IMSG est délivré à la fenêtre spécifiée par le paramètre $hWnd.
Pour des raisons de performances, les notifications multiples peuvent être combinés en une seule notification. Par exemple, si un grand nombre de notifications $SHCNE_UPDATEITEM sont générées pour les fichiers d'un même dossier, ils peuvent être joint en une seule notification $SHCNE_UPDATEDIR.
_WinAPI_ShellChangeNotifyDeregister
Consultez SHChangeNotifyRegister dans la librairie MSDN.
#include <APIShellExConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIShellEx.au3> #include <WinAPISysWin.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 dossier.') Exit EndIf OnAutoItExitRegister('OnAutoItExit') Local $hWnd = GUICreate('') Local $iMsg = _WinAPI_RegisterWindowMessage('SHELLCHANGENOTIFY') GUIRegisterMsg($iMsg, 'WM_SHELLCHANGENOTIFY') Global $g_iID = _WinAPI_ShellChangeNotifyRegister($hWnd, $iMsg, $SHCNE_ALLEVENTS, BitOR($SHCNRF_INTERRUPTLEVEL, $SHCNRF_SHELLLEVEL, $SHCNRF_RECURSIVEINTERRUPT), $g_sPath, 1) If @error Then MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Erreur', 'Window n''a pas inscrit.') Exit EndIf While 1 Sleep(1000) WEnd Func WM_SHELLCHANGENOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $sPath = _WinAPI_ShellGetPathFromIDList(DllStructGetData(DllStructCreate('dword Item1; dword Item2', $WPARAM), 'Item1')) If $sPath Then ConsoleWrite('Événement: 0x' & Hex($lParam) & '| Path: ' & $sPath & @CRLF) Else ConsoleWrite('Événement: 0x' & Hex($lParam) & @CRLF) EndIf EndFunc ;==>WM_SHELLCHANGENOTIFY Func OnAutoItExit() If $g_iID Then _WinAPI_ShellChangeNotifyDeregister($g_iID) EndIf DirRemove($g_sPath) EndFunc ;==>OnAutoItExit