Attribute VB_Name ="mShellNotify" OptionExplicit ' Brought to you by Brad Martinez ' http://members.aol.com/btmtz/vb ' http://www.mvps.org/ccrp ' Code was written in and formatted for 8pt MS San Serif ' ==================================================================== ' Demonstrates how to receive shell change notifications (ala "what happens when the ' SHChangeNotify API is called?") ' Interpretation of the shell's undocumented functions SHChangeNotifyRegister (ordinal 2) ' and SHChangeNotifyDeregister (ordinal 4) would not have been possible without the ' assistance of James Holderness. For a complete (and probably more accurate) overview ' of shell change notifcations, please refer to James' "Shell Notifications" page at ' http://www.geocities.com/SiliconValley/4942/ ' ==================================================================== Private m_hSHNotify AsLong' the one and only shell change notification handle for the desktop folder Private m_pidlDesktop AsLong' the desktop's pidl ' User defined notiication message sent to the specified window's window proc. PublicConst WM_SHNOTIFY =&H401 ' ==================================================================== Public Type PIDLSTRUCT ' Fully qualified pidl (relative to the desktop folder) of the folder to monitor changes in. ' 0 can also be specifed for the desktop folder. pidl AsLong ' Value specifying whether changes in the folder's subfolders trigger a change notification ' event (it's actually a Boolean, but we'll go Long because of VB's DWORD struct alignment). bWatchSubFolders AsLong End Type DeclareFunction SHChangeNotifyRegister()Function SHChangeNotifyRegister Lib"shell32"Alias"#2" _ (ByVal hWnd AsLong, _ ByVal uFlags As SHCN_ItemFlags, _ ByVal dwEventID As SHCN_EventIDs, _ ByVal uMsg AsLong, _ ByVal cItems AsLong, _ lpps As PIDLSTRUCT) AsLong ' hWnd - Handle of the window to receive the window message specified in uMsg. ' uFlags - Flag that indicates the meaning of the dwItem1 and dwItem2 members of the ' SHNOTIFYSTRUCT (which is pointed to by the window procedure's wParam ' value when the specifed window message is received). This parameter can ' be one of the SHCN_ItemFlags enum values below. ' This interpretaion may be inaccurate as it appears pdils are almost alway returned ' in the SHNOTIFYSTRUCT. See James' site for more info... ' dwEventId - Combination of SHCN_EventIDs enum values that specifies what events the ' specified window will be notified of. See below. ' uMsg - Window message to be used to identify receipt of a shell change notification. ' The message should *not* be a value that lies within the specifed window's ' message range ( i.e. BM_ messages for a button window) or that window may ' not receive all (if not any) notifications sent by the shell!!! ' cItems - Count of PIDLSTRUCT structures in the array pointed to by the lpps param. ' lpps - Pointer to an array of PIDLSTRUCT structures indicating what folder(s) to monitor ' changes in, and whether to watch the specified folder's subfolder. ' If successful, returns a notification handle which must be passed to SHChangeNotifyDeregister ' when no longer used. Returns 0 otherwise. ' Once the specified message is registered with SHChangeNotifyRegister, the specified ' window's function proc will be notified by the shell of the specified event in (and under) ' the folder(s) speciifed in apidl. On message receipt, wParam points to a SHNOTIFYSTRUCT ' and lParam contains the event's ID value. ' The values in dwItem1 and dwItem2 are event specific. See the description of the values ' for the wEventId parameter of the documented SHChangeNotify API function. Type SHNOTIFYSTRUCT dwItem1 AsLong dwItem2 AsLong End Type ' ...? 'Declare Function SHChangeNotifyUpdateEntryList Lib "shell32" Alias "#5" _ ' (ByVal hNotify As Long, _ ' ByVal Unknown As Long, _ ' ByVal cItem As Long, _ ' lpps As PIDLSTRUCT) As Boolean ' 'Declare Function SHChangeNotifyReceive Lib "shell32" Alias "#5" _ ' (ByVal hNotify As Long, _ ' ByVal uFlags As SHCN_ItemFlags, _ ' ByVal dwItem1 As Long, _ ' ByVal dwItem2 As Long) As Long ' Closes the notification handle returned from a call to SHChangeNotifyRegister. ' Returns True if succeful, False otherwise. DeclareFunction SHChangeNotifyDeregister()Function SHChangeNotifyDeregister Lib"shell32"Alias"#4" (ByVal hNotify AsLong) AsBoolean ' ==================================================================== ' This function should be called by any app that changes anything in the shell. ' The shell will then notify each "notification registered" window of this action. DeclareSub SHChangeNotify()Sub SHChangeNotify Lib"shell32" _ (ByVal wEventId As SHCN_EventIDs, _ ByVal uFlags As SHCN_ItemFlags, _ ByVal dwItem1 AsLong, _ ByVal dwItem2 AsLong) ' Shell notification event IDs PublicEnum SHCN_EventIDsEnum SHCN_EventIDs SHCNE_RENAMEITEM =&H1 ' (D) A nonfolder item has been renamed. SHCNE_CREATE =&H2 ' (D) A nonfolder item has been created. SHCNE_DELETE =&H4 ' (D) A nonfolder item has been deleted. SHCNE_MKDIR