Shell Functions


SHChangeNotifyRegister Function

Registers a window that receives notifications from the file system or Shell.

Syntax

ULONG SHChangeNotifyRegister(      
    HWND hwnd,     int fSources,     LONG fEvents,     UINT wMsg,     int cEntries,     const SHChangeNotifyEntry *pshcne );

Parameters

hwnd
A handle to the window that receives the change or notification messages.
fSources
One or more of the following values that indicate the type of events for which to receive notifications.

Note  These flags are not defined in the header file. Implementers must define them themselves or use their numeric values in their place.
SHCNRF_InterruptLevel
0x0001. Interrupt level notifications from the file system.
SHCNRF_ShellLevel
0x0002. Shell-level notifications from the shell.
SHCNRF_RecursiveInterrupt
0x1000. Interrupt events on the whole subtree. This flag must be combined with the SHCNRF_InterruptLevel flag. When using this flag, notifications must also be made recursive by setting the fRecursive member of the corresponding SHChangeNotifyEntry structure referenced by pshcne to TRUE. Use of SHCNRF_RecursiveInterrupt on a single level view—for example, a pointer to an item identifier list (PIDL) that is relative and contains only one SHITEMID—will block event notification at the highest level and thereby prevent a recursive, child update. Thus, an icon dragged into the lowest level of a folder hierarchy may fail to appear in the view as expected.
SHCNRF_NewDelivery
0x8000. Messages received use shared memory. Call SHChangeNotification_Lock to access the actual data. Call SHChangeNotification_Unlock to release the memory when done.
Note  This flag is recomended as it provides a more robust delivery method. All clients should specify this flag.
fEvents
Change notification events for which to receive notification.
wMsg
Message to be posted to the window procedure.
cEntries
Number of entries in the pshcne array.
pshcne
[in] Array of SHChangeNotifyEntry structures that contain the notifications. This array should always be set to one when calling SHChangeNotifyRegister or SHChangeNotifyDeregister will not work properly.

Return Value

Returns a positive integer registration ID. Returns zero if out of memory or in response to invalid parameters.

Remarks

See the Change Notify Watcher Sample in the Microsoft Windows Software Development Kit (SDK) for a full example that demonstrates the use of this function.

When a change notification event is raised, the message indicated by wMsg is delivered to the window specified by the hwnd parameter.

  • If SHCNRF_NewDelivery is specified, the wParam and lParam values in the message should be passed to SHChangeNotification_Lock as the hChange and dwProcID parameters respectively.
  • If SHCNRF_NewDelivery is not specified, wParam is a pointer to two PIDLIST_ABSOLUTE pointers, and lParam specifies the event. The two PIDLIST_ABSOLUTE pointers can be NULL, depending on the event being sent.

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.

Function Information

Minimum DLL Versionshell32.dll version 5.0 or later
Custom ImplementationNo
Headershlobj.h
Import libraryshell32.lib
Minimum operating systems Windows 2000
Tags :


Community Content

Chris_Guzak
SHCNRF_NewDelivery should be used as it provides a more robust delivery method
all clients should specify this flag
Tags : contentbug

Chris_Guzak
the wParam/lParam values delivered to the HWND...

when SHCNRF_NewDelivery (recomend flag) is specified then the wParam/lParam value of the message delviered to the hwnd specified in this API should be passed as the first 2 params to SHChangeNotification_Lock()

Tags : contentbug

Chris_Guzak
items sent through shell change notification system don't have full properties
The change notification system implements an optimization to avoid extra IO that would not be necessary for some use of the items sent through the change notification system. These are known as “simple items”, they don’t have any of their innate properties like size, date, and attributes.

Clients of the change notification system that want to use the items they receive on their callbacks need to convert them to “regular items”. This can be done via IShellItem::Update(). This does the IO that the change notification system deferred. so don't do this on a UI thread.

Here is sample code that takes the item sent to the change notify listener and demonstrates the results you get on the queries and how to convert the simple to full..

FILETIME ftModified;
psi1->GetFileTime(PKEY_DateModified, &ftModified); // empty result

psi1->Update(NULL); // convert simple to full item, does IO

psi1->GetFileTime(PKEY_DateModified, &ftModified); // returns the value
Tags :

Page view tracker