Function Reference


_WinAPI_ShellChangeNotifyRegister

Registers a window to receive notifications from the file system or Shell

#include <WinAPIShellEx.au3>
_WinAPI_ShellChangeNotifyRegister ( $hWnd, $iMsg, $iEvents, $iSources, $aPaths [, $bRecursive = False] )

Parameters

$hWnd Handle to the window that receives the change or notification messages.
$iMsg Message to be posted to the window procedure.
$iEvents Change notification events for which to receive notification. This parameter can be one or more
of the $SHCNE_* values.
$iSources One or more of the following values that indicate the type of events for which to receive
notifications.
$SHCNRF_INTERRUPTLEVEL
$SHCNRF_SHELLLEVEL
$SHCNRF_RECURSIVEINTERRUPT
$SHCNRF_NEWDELIVERY
$aPaths Single path or array of paths for which to receive notifications. These names should be
fully-qualified paths to prevent unexpected results.
$bRecursive [optional] Specifies whether to post notifications for children paths in $aPaths parameter, valid values:
    True - Notifications would come from the folder's children.
    False - Notifications would come from the specified folder's only (Default).

Return Value

Success: The registration ID.
Failure: 0 and sets the @error flag to non-zero.

Remarks

When a change notification event is raised, the message indicated by $iMsg is delivered to the window
specified by the $hWnd parameter.

For performance reasons, multiple notifications can be combined into a single notification. For example,
if a large number of $SHCNE_UPDATEITEM notifications are generated for files in the same folder, they can be
joined into a single $SHCNE_UPDATEDIR notification.

Related

_WinAPI_ShellChangeNotifyDeregister

See Also

Search SHChangeNotifyRegister in MSDN Library.

Example

#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(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'Unable to create folder.')
        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(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'Window does not registered.')
        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('Event: 0x' & Hex($lParam) & ' | Path: ' & $sPath & @CRLF)
        Else
                ConsoleWrite('Event: 0x' & Hex($lParam) & @CRLF)
        EndIf
EndFunc   ;==>WM_SHELLCHANGENOTIFY

Func OnAutoItExit()
        If $g_iID Then
                _WinAPI_ShellChangeNotifyDeregister($g_iID)
        EndIf
        DirRemove($g_sPath)
EndFunc   ;==>OnAutoItExit