Results 1 to 4 of 4

Thread: A VERY MUCH used function in my "Browse For Folder" sysTreeView

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    976

    A VERY MUCH used function in my "Browse For Folder" sysTreeView

    This function is ONE OF THE TOP MOST repeated and used function in my "Browse For Folder" UserControl so I felt a "guilt" to share it you all
    Because it's so handy och usable

    BUT be aware!! IF YOU is not confortable with Shell/COM programming or a beginner/novice I DO recommend YOU NOT use this function.

    Code:
    Public Function IsShellItemFolder(pISI As IShellItem) As Boolean
      'Long value for the bit wise attribute(s) you request(s)
      Dim dwAttribs As Long
      'The COM return result
      Dim hr As Long
      
      'Better to be safe than sorry - quit the function if IShellItem object not was set.
      If pISI Is Nothing Then Exit Function
      
      'Initialize Function to False - Ensure no old usage is left in the memory.
      IsShellItemFolder = False
      
      'Ask for attribute(s) and return the attributes wanted.
      hr = pISI.GetAttributes(SFGAO_FOLDER, dwAttribs)
      
      'If the method returned OK - Why shouldn't it?
      If hr = S_OK Then
        'Ask your "out pointer" if there is/are the request(ed) attributes in the "out pointer"
        If (dwAttribs And SFGAO_FOLDER) Then
          'If your query match the out pointer - return True
          IsShellItemFolder = True
        End If
      Else
        'OPTIONAL - Here you can make an output/notification to the user that the method in one way or another didn't returned OK.
        'Error codes are ONLY in Hexadecimal valus for COM related errors so use Hex(hr) to find out the error code.
      End If
    End Function
    You do it best in to put this function into a class module so you don't have to write the function over and over again and just call it when needed...Like this:

    Code:
    Dim m_cShell32 As New cShell32 '<---- Put this Public/Global
    Dim bIsFolder As Boolean
    
    bIsFolder = m_cShell32.IsShellItemFolder(pISI_Enum)
    HINT - You can switch out the SFGAO_FOLDER with whatever SFGAO_Flag(s) you whish.
    Last edited by nebeln; Dec 17th, 2023 at 07:30 PM.

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