Results 1 to 7 of 7

Thread: [RESOLVED] SHBrowseForFolder / BrowseInfo - retrun path newly created or not?

Threaded View

  1. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,672

    Re: SHBrowseForFolder / BrowseInfo - retrun path newly created or not?

    You should be looking at SHCNE_MKDIR and SHCNE_RENAMEFOLDER rather than SHCNE_UPDATEITEM, which as you see is a bit quirky.

    Code:
    Public Function StartNotify(hWnd As Long, Optional pidlPath As Long = 0) As Long
      Dim tCNE As SHChangeNotifyEntry
      If (m_hSHNotify = 0) Then
            If pidlPath = 0 Then
                tCNE.pidl = VarPtr(0) 'this is a shortcut for the pidl of the desktop; this is to watch every folder/object
            Else
                tCNE.pidl = pidlPath
            End If
          tCNE.bWatchSubFolders = True
          
          m_hSHNotify = SHChangeNotifyRegister(hWnd, SHCNRF_ShellLevel Or SHCNRF_InterruptLevel, SHCNE_ALLEVENTS Or SHCNE_INTERRUPT, WM_SHNOTIFY, 1, tCNE)
          
          
          StartNotify = m_hSHNotify
    
      End If   ' (m_hSHNotify = 0)
    
    End Function
    For reference that's what I use to set up notifies. I tested making a new directory in SHBrowseForFolder, and it looked like this:

    Shell Notify::SHCNE_MKDIR on C:\temp2\New folder, item2=
    Shell Notify::SHCNE_RENAMEFOLDER on C:\temp2\New folder, item2=C:\temp2\vc

    (which was the correct info)

    If you don't need to watch all events, just specify the ones you need, the two for directory creation then if there's anything else you want to watch.

    PLEASE NOTE: The go-to examples of this function in VB, while they work for most scenarios, are wrong (VBNet's example even notes that it's probably wrong), so here's the correct way to define things:

    Code:
    Public Declare Function SHChangeNotifyRegister Lib "shell32" _
                                  (ByVal hWnd As Long, _
                                  ByVal uFlags As SHCNRF, _
                                  ByVal dwEventID As SHCN_EventIDs, _
                                  ByVal uMsg As Long, _
                                  ByVal cItems As Long, _
                                  lpps As SHChangeNotifyEntry) As Long
    
    Public Enum SHCNRF
        SHCNRF_InterruptLevel = &H1
        SHCNRF_ShellLevel = &H2
        SHCNRF_RecursiveInterrupt = &H1000
        SHCNRF_NewDelivery = &H8000
    End Enum
    Public Type SHChangeNotifyEntry
      pidl As Long 'fully qualified pidl; desktop pidl VarPtr(0) for all locations
      fRecursive As Long '0=not recursive, 1=recursive (subfolders)
    End Type
    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
    The SHCNF values are for when your application notifies the shell of a change it made via SHChangeNotify (which people should use more around here); the structure returned to you in the wParam is always going to have pidls.
    Last edited by fafalone; Oct 3rd, 2015 at 03:48 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width