注册接收文件系统或 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 值. |
在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