SHGFI_ICONLOCATION = &H1000 'fills sfi.szDisplayName with filename containing the icon, rtns BOOL
SHGFI_EXETYPE = &H2000 'rtns two ASCII chars of exe type
SHGFI_SYSICONINDEX = &H4000 'sfi.iIcon is sys il icon index, rtns hImagelist
SHGFI_LINKOVERLAY = &H8000& 'add shortcut overlay to sfi.hIcon
SHGFI_SELECTED = &H10000 'sfi.hIcon is selected icon
End Enum
Public Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
'Frees memory allocated by the shell (pidls)
Public Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As Long)
'Retrieves the location of a special (system) folder. Returns ERROR_SUCCESS if successful or an OLE-defined error result otherwise.
Public Declare Function SHGetSpecialFolderLocation Lib "shell32" (ByVal hwndOwner As Long, ByVal nFolder As SHSpecialFolderIDs, pidl As Long) As Long
'Converts an item identifier list to a file system path. Returns TRUE if successful or FALSE if an error occurs, for example, if the location specified by the pidl parameter is not part of the file system.
Public Declare Function SHGetPathFromIDList Lib "shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
'Retrieves information about an object in the file system, such as a file, a folder, a directory, or a drive root.
Public Declare Function SHGetFileInfoPidl Lib "shell32" Alias "SHGetFileInfoA" (ByVal pidl As Long, ByVal dwFileAttributes As Long, psfib As SHFILEINFOBYTE, ByVal cbFileInfo As Long, ByVal uFlags As SHGFI_FLAGS) As Long
Public Declare Function SHGetFileInfo Lib "shell32" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As SHGFI_FLAGS) As Long
Private Const WM_NCDESTROY As Long = &H82
Private Const GWL_WNDPROC As Long = (-4)
Private Const OLDWNDPROC As String = "OldWndProc"
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'the one and only shell change notification handle for the desktop folder
Private m_hSHNotify As Long
'the desktop's pidl
Private m_pidlDesktop As Long
'User defined notification message sent to the specified window's window proc.
'Fully qualified pidl (relative to the desktop folder) of the folder to monitor changes in. 0 can also be specified for the desktop folder.
pidl As Long
'Value specifying whether changes in the folder's subfolders trigger a change notification event.
bWatchSubFolders As Long
End Type
Public Declare Function SHChangeNotifyRegister Lib "shell32" Alias "#2" (ByVal hwnd As Long, ByVal uFlags As SHCN_ItemFlags, ByVal dwEventID As SHCN_EventIDs, ByVal uMsg As Long, ByVal cItems As Long, lpps As PIDLSTRUCT) As Long
'If successful, SHChangeNotifyRegister 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) specified in a pidl.
'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.
Public Type SHNOTIFYSTRUCT
dwItem1 As Long
dwItem2 As Long
End Type
'...?
'Public Declare Function SHChangeNotifyUpdateEntryList Lib "shell32" Alias "#5" (ByVal hNotify As Long, ByVal Unknown As Long, ByVal cItem As Long, lpps As PIDLSTRUCT) As Boolean
'Public 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 successful,False otherwise.
Public Declare Function SHChangeNotifyDeregister Lib "shell32" Alias "#4" (ByVal hNotify As Long) As Boolean
'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.
Public Declare Sub SHChangeNotify Lib "shell32" (ByVal wEventId As SHCN_EventIDs, ByVal uFlags As SHCN_ItemFlags, ByVal dwItem1 As Long, ByVal dwItem2 As Long)
'Shell notification event IDs
Public Enum SHCN_EventIDs
SHCNE_RENAMEITEM = &H1 '(D) A non-folder item has been renamed.
SHCNE_CREATE = &H2 '(D) A non-folder item has been created.
SHCNE_DELETE = &H4 '(D) A non-folder item has been deleted.
SHCNE_MKDIR = &H8 '(D) A folder item has been created.
SHCNE_RMDIR = &H10 '(D) A folder item has been removed.
SHCNE_MEDIAINSERTED = &H20 '(G) Storage media has been inserted into a drive.
SHCNE_MEDIAREMOVED = &H40 '(G) Storage media has been removed from a drive.
SHCNE_DRIVEREMOVED = &H80 '(G) A drive has been removed.
SHCNE_DRIVEADD = &H100 '(G) A drive has been added.
SHCNE_NETSHARE = &H200 'A folder on the local computer is being shared via the network.
SHCNE_NETUNSHARE = &H400 'A folder on the local computer is no longer being shared via the network.
SHCNE_ATTRIBUTES = &H800 '(D) The attributes of an item or folder have changed.
SHCNE_UPDATEDIR = &H1000 '(D) The contents of an existing folder have changed, but the folder still exists and has not been renamed.
SHCNE_UPDATEITEM = &H2000 '(D) An existing non-folder item has changed, but the item still exists and has not been renamed.
SHCNE_SERVERDISCONNECT = &H4000 'The computer has disconnected from a server.
SHCNE_UPDATEIMAGE = &H8000& '(G) An image in the system image list has changed.
SHCNE_DRIVEADDGUI = &H10000 '(G) A drive has been added and the shell should create a new window for the drive.
SHCNE_RENAMEFOLDER = &H20000 '(D) The name of a folder has changed.
SHCNE_FREESPACE = &H40000 '(G) The amount of free space on a drive has changed.
#If (WIN32_IE >= &H400) Then
SHCNE_EXTENDED_EVENT = &H4000000 '(G) Not currently used.
#End If
SHCNE_ASSOCCHANGED = &H8000000 '(G) A file type association has changed.
SHCNE_DISKEVENTS = &H2381F '(D) Specifies a combination of all of the disk event identifiers.
SHCNE_GLOBALEVENTS = &HC0581E0 '(G) Specifies a combination of all of the global event identifiers.
SHCNE_ALLEVENTS = &H7FFFFFFF
SHCNE_INTERRUPT = &H80000000 'The specified event occurred as a result of a system
'interrupt. It is stripped out before the clients of SHCNNotify_ see it.
End Enum
#If (WIN32_IE >= &H400) Then
Public Const SHCNEE_ORDERCHANGED = &H2 'dwItem2 is the pidl of the changed folder
#End If
'Notification flags uFlags & SHCNF_TYPE is an ID which indicates what dwItem1 and dwItem2 mean
Public Enum SHCN_ItemFlags
SHCNF_IDLIST = &H0 'LPITEMIDLIST
SHCNF_PATHA = &H1 'path name
SHCNF_PRINTERA = &H2 'printer friendly name
SHCNF_DWORD = &H3 'DWORD
SHCNF_PATHW = &H5 'path name
SHCNF_PRINTERW = &H6 'printer friendly name
SHCNF_TYPE = &HFF
'Flushes the system event buffer. The function does not return until the system is finished processing the given event.
SHCNF_FLUSH = &H1000
'Flushes the system event buffer. The function returns immediately regardless of whether the system is finished processing the given event.
SHCNF_FLUSHNOWAIT = &H2000
#If UNICODE Then
SHCNF_PATH = SHCNF_PATHW
SHCNF_PRINTER = SHCNF_PRINTERW
#Else
SHCNF_PATH = SHCNF_PATHA
SHCNF_PRINTER = SHCNF_PRINTERA
#End If
End Enum
Public Function SHNotify_Register(hwnd As Long) As Boolean
'Registers the one and only shell change notification.