Jump to content

_WinAPI_ShellChangeNotifyRegister problem


Go to solution Solved by LarsJ,

Recommended Posts

Posted (edited)

#include <APIShellExConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPI.au3>
#include <WinAPIShellEx.au3>

Opt('TrayAutoPause', 0)

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

DirCreate($g_sPath)
If Not FileExists($g_sPath) Then
    MsgBox(BitOR($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(BitOR($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

It is the Example script from Help file. My OS is WindowsXP.

When I copy a file into the '~TEST~' folder,console output is OK as below:

Event: 0x00000002 | Path: E:~TEST~1.au3

But when I download a file via FireFox into the folder, console output is as below:

Event: 0x00001000 | Path: E:~TEST~

A file named [filename].part is created in the folder, why the file name is missing?

Edited by linbin
Posted

I test it on Win7 and it works.

The console output is as below when I  download QQ6.4.exe via Firefox :

Event: 0x00000002 | Path: D:QQ6.4.exe
Event: 0x00000002 | Path: D:QQ6.4.exe.part
Event: 0x00002000 | Path: D:QQ6.4.exe.part
Event: 0x00002000 | Path: D:QQ6.4.exe.part
Event: 0x00000004 | Path: D:QQ6.4.exe
Event: 0x00000001 | Path: D:QQ6.4.exe.part
Event: 0x00002000 | Path: D:QQ6.4.exe
Event: 0x00002000 | Path: D:QQ6.4.exe

 

Why it doesn't work in WinXP?  Is it a bug?

  • Solution
Posted

I don't think this is a bug. This is a limitation of Windows XP.

In the bottom of the remarks for SHChangeNotifyRegister you can read:

"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."

The event you are receiving in post 1 (0x00001000) is exactly SHCNE_UPDATEDIR. Post 4 confirms that downloading a file generates a lot of events.

On XP all these events are joined into a single SHCNE_UPDATEDIR notification.

On Win 7 which is newer and faster there are no performance issues, and you are receiving all the events.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...