函数参考


_WinAPI_ShellChangeNotifyRegister

注册接收文件系统或 Shell 通知的窗口.

#Include <WinAPIEx.au3>
_WinAPI_ShellChangeNotifyRegister ( $hWnd, $iMsg, $iEvents, $iSources, $aPaths [, $fRecursive] )

参数

$hWnd 接收改变或通知消息的窗口句柄.
$iMsg 被发送到窗口程序的消息.
$iEvents 改接收的通知事件.此参数可以是一或多个 $SHCNE_ * 值.
$iSources 一或多个指示事件类型的通知值:
 $SHCNRF_INTERRUPTLEVEL
 $SHCNRF_SHELLLEVEL
 $SHCNRF_RECURSIVEINTERRUPT
 $SHCNRF_NEWDELIVERY
$aPaths 接收通知的单一路径或路径的数组.
名称应该是完全合格的路径,以防止发生意外的结果.
$fRecursive [可选参数] 指定是否发送 $aPaths 参数的子路径通知.有效值:
1 - 发送来自子文件夹的通知.
0 - 仅发送来自指定文件夹的通知. (默认)

返回值

成功: The registration ID.
失败: 返回 0,并设置@error标志为非 0 值.

注意/说明

当一个更改通知事件发生时,由 $iMsg 表示的消息发送到由 $hwnd 参数指定的窗口.(见示例)
 出于性能的原因,多次通知可以组合成一个单一的通知.
 例如, $SHCNE_UPDATEITEM 的多次通知是在同一文件夹中生成的,
 它们可以被加入到一个单一 $SHCNE_UPDATEDIR 通知中.

相关

详情参考

在MSDN中搜索


示例/演示


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

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

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

Global $hWnd, $iMsg, $ID

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

OnAutoItExitRegister('OnAutoItExit')

$hWnd = GUICreate('')
$iMsg = _WinAPI_RegisterWindowMessage('SHELLCHANGENOTIFY')
GUIRegisterMsg($iMsg, 'WM_SHELLCHANGENOTIFY')
$ID = _WinAPI_ShellChangeNotifyRegister($hWnd, $iMsg, $SHCNE_ALLEVENTS, BitOR($SHCNRF_INTERRUPTLEVEL, $SHCNRF_SHELLLEVEL, $SHCNRF_RECURSIVEINTERRUPT), $sPath, 1)
If @error Then
    MsgBox(16, 'Error', 'Window does not registered.')
    Exit
EndIf

While 1
    Sleep(1000)
WEnd

Func WM_SHELLCHANGENOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $Path = _WinAPI_ShellGetPathFromIDList(DllStructGetData(DllStructCreate('dword Item1; dword Item2', $wParam), 'Item1'))

    If $Path Then
        ConsoleWrite('Event: 0x' & Hex($lParam) & ' | Path: ' & $Path & @CR)
    Else
        ConsoleWrite('Event: 0x' & Hex($lParam) & @CR)
    EndIf
EndFunc   ;==>WM_SHELLCHANGENOTIFY

Func OnAutoItExit()
    If $ID Then
        _WinAPI_ShellChangeNotifyDeregister($ID)
    EndIf
;   DirRemove($sPath)
EndFunc   ;==>OnAutoItExit