none
file explorer with search engine in vb.net RRS feed

  • Question

  • I have a file explorer in vb.net and I put a field and a button that for when I type in this field a name of a folder, document, image or any other file and click the button, it searches for that file and if it does not find the file it shows the files with the same name, or no case has no file with the name entered, exactly like the file explorer that Windows has.

    link image

    https://social.msdn.microsoft.com/Forums/getfile/1446035

    I am putting the whole code of the project for a better understanding of how my code works.

    Imports System.IO Public Class Form1 Dim path As String Dim nextPath As String Public Property ListView1 As Object Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try path = TextBox1.Text If (My.Computer.FileSystem.DirectoryExists(path)) Then explorer.Clear() For Each i In My.Computer.FileSystem.GetDirectories(path) explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2) Next For Each i In My.Computer.FileSystem.GetFiles(path) explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1) Next Else MsgBox("Its A File") 'or user 'pocess.Start(path) // to open the file End If Catch ex As Exception End Try End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try path = "C:\Program Files (x86)" For Each i In My.Computer.FileSystem.GetDirectories(path) explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2) Next For Each i In My.Computer.FileSystem.GetFiles(path) explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1) Next Catch ex As Exception MsgBox("Não foi encontrado o caminho 'C:\Program Files (x86)' na rede. Entre em contato com o setor de TI.") Application.Exit() End Try End Sub Private Sub ListView1_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles explorer.ItemSelectionChanged nextPath = path + "\" + e.Item.Text End Sub Private Sub ListView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles explorer.MouseDoubleClick Try If (My.Computer.FileSystem.DirectoryExists(nextPath)) Then path = nextPath explorer.Clear() TextBox1.Text = path For Each i In My.Computer.FileSystem.GetDirectories(path) explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2) Next For Each i In My.Computer.FileSystem.GetFiles(path) explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1) Next Else Process.Start(path & "\" & explorer.SelectedItems(0).Text) End If Catch ex As Exception MsgBox("Voçe não tem acesso a esse arquivo, feche o aplicativo e abra o novamente.") End Try End Sub Private Sub BtnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click Try nextPath = path.Substring(0, path.LastIndexOf("\")) path = nextPath explorer.Clear() TextBox1.Text = path For Each i In My.Computer.FileSystem.GetDirectories(path) explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2) Next For Each i In My.Computer.FileSystem.GetFiles(path) explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1) Next Catch ex As Exception MsgBox("Não é possivel voltar mais, o aplicativo 'Instruções de Trabalhos Técnicos' irá reiniciar.") Application.Restart() End Try End Sub Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button1.Click End Sub End Class

    And here is the command of the field to type and the command of the button:

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    
        End Sub
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
        End Sub
    Can you help me?


    Monday, June 3, 2019 3:13 PM

All replies

  • Hi

    Check out this MS document, maybe it could help you.

    Find Files
    using wildcards can be very useful.

    There are so many ways to do it, just a case of trial and error.


    Regards Les, Livingston, Scotland

    Monday, June 3, 2019 3:49 PM
  • Hi

    Check out this MS document, maybe it could help you.

    Find Files
    using wildcards can be very useful.

    There are so many ways to do it, just a case of trial and error.


    Regards Les, Livingston, Scotland

    Thanks leshay,

    It's very useful i used it as follow

    Dim path As String = "G:\"
    ListBox1.Items.Clear()
    For Each foundFile As String In My.Computer.FileSystem.GetFiles(path,             Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.txt")
    
                ListBox1.Items.Add(foundFile)
            Next
    Label1.Text = ListBox1.Items.Count

    But it takes time if there are many files in my case i have 1400 ".txt" files ....

    Is there a way to handle this delay or show the 1400 files like pages every page has 100 file or any solution Because it takes 4 or 5 seconds to show the files on the list box ???????  

    Thanks


    Regards From Egypt

    Tuesday, June 4, 2019 11:43 AM
  • Hi

    Check out this MS document, maybe it could help you.

    Find Files
    using wildcards can be very useful.

    There are so many ways to do it, just a case of trial and error.


    Regards Les, Livingston, Scotland

    Thanks leshay,

    It's very useful i used it as follow

    Dim path As String = "G:\"
    ListBox1.Items.Clear()
    For Each foundFile As String In My.Computer.FileSystem.GetFiles(path,             Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.txt")
    
                ListBox1.Items.Add(foundFile)
            Next
    Label1.Text = ListBox1.Items.Count

    But it takes time if there are many files in my case i have 1400 ".txt" files ....

    Is there a way to handle this delay or show the 1400 files like pages every page has 100 file or any solution Because it takes 4 or 5 seconds to show the files on the list box ???????  

    Thanks


    Regards From Egypt

    Hi

    There is going to be some time overhead collecting the information regardless of what/how it is displayed.

    You have to 'split' off the code for collecting (filtering) the data (files/folders) and the display of the data. You could conceivably display the data in a 'paged' way, but to collect the data will still remain a timed event.

    I created a BackUp utility and, over a wireless connection to my NAS, it takes about a minute to collect the necessary information for about 11000 files in hundreds of folders before it can start the actual backup.


    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, June 4, 2019 3:35 PM
    Tuesday, June 4, 2019 2:38 PM
  • For me it did not work, I sent a picture, but it was off the air and I'll try to send it now.
    The image shows the file explorer and has a blank field that you type the name of a file and when clicking the button it looks for this file in the root path and inside the folders and subfolders, which is the same file explorer that Windows has .
    That's what I want you to help me with.

    link image: https://1drv.ms/u/s!ArgT_dApPP30jZJijLUc4nQ5lKbOdw?e=WbvNlf 

    ____________________________________

    Best regards, Igor Duarte

    Tuesday, June 4, 2019 3:04 PM
  • For me it did not work, I sent a picture, but it was off the air and I'll try to send it now.
    The image shows the file explorer and has a blank field that you type the name of a file and when clicking the button it looks for this file in the root path and inside the folders and subfolders, which is the same file explorer that Windows has .
    That's what I want you to help me with.

    link image: https://1drv.ms/u/s!ArgT_dApPP30jZJijLUc4nQ5lKbOdw?e=WbvNlf 

    ____________________________________

    Best regards, Igor Duarte

    Hi

    From the image and from what you say, are you asking how to filter from a collection you have already filled. The image suggests you have already collected all the file/folder information before displaying the items, and now, you want to search through that exisring data - is that correct?

    BTW: using different threads for some of the operations can be useful too - keeping the UI responsive.


    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, June 4, 2019 3:41 PM
    Tuesday, June 4, 2019 3:39 PM
  • Yes, as I put the example path the program already opens with this path "C: \ Program Files (x86)", and as it shows in the image when I enter a name in the field blank and click the button it searches by that name in the path "C: \ Program Files (x86)" and into subfolders if the file with the name I typed inside other folders. I want it to do exactly like the file explorer that Windows has, you enter a folder and search for a file and if I have the file it shows and if it does not have it it shows the similar ones and if it does not it does not show anything.

    ______________________________

    Best regards, Igor Duarte

    Tuesday, June 4, 2019 6:45 PM
  • Hello,

    The following is a pattern to consider but the code does not match what you have. What this does;

    • Works with recursive call to a method to get directories then files then checks to see if your inputted file name is located.
    • Uses a BackGroundWorker with cancel capability.

    https://1drv.ms/u/s!AtGAgKKpqdWjjTMwv4GFCm5xWAVa


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, June 4, 2019 8:32 PM
    Moderator
  • Hi

    OK, here is as close as I could get to your request.

    This is loosely based on your code,heavily modified so that I could follow it. (and gets rid ofmost of the repetition).

    This example, for the Filter aspect, uses a TextBox2, and is dynamic (will perform the filter as User types - so no need for GO Button)

    There is still a little cross over of Button use (Button1), but I think it is needed if User wants to manually paste in  TextBox1 (Path)

    EDIT: major tidy up.Added Images to Resources and added View context menu items. Removed more code repetitions. Better exception avoidance.

    LayOut

    Code

    ' Form1 with SplitContainer1
    ' Button1,  Button2, TextBox1,
    ' TextBox2, ListView1, ContextMenuStrip1
    ' ImageList1 and ImageList2
    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim path As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Size = New Size(500, 400)
            With SplitContainer1
                .SplitterDistance = TextBox2.Bottom
                .FixedPanel = FixedPanel.Panel1
                .IsSplitterFixed = True
            End With

            ImageList1.Images.Add(My.Resources.Folder)
            ImageList1.Images.Add(My.Resources.File)
            ImageList2.Images.AddRange(ImageList1.Images.OfType(Of Image).ToArray())
            ImageList1.ImageSize = New Size(50, 50)
            ImageList2.ImageSize = New Size(16, 16)

            With ListView1
                .LargeImageList = ImageList1
                .SmallImageList = ImageList2
                .TileSize = New Size(ImageList1.ImageSize.Width + 150, ImageList1.ImageSize.Height)
                .View = View.Tile
            End With

            TextBox1.Text = path
            TextBox2.Text = Nothing
            FillLV(path)
        End Sub
        Sub FillLV(path As String)
            ListView1.Clear()
            Try
                For Each i In My.Computer.FileSystem.GetDirectories(path, FileIO.SearchOption.SearchTopLevelOnly, TextBox2.Text & "*")
                    ListView1.Items.Add(IO.Path.GetFileName(i), ImageList1.Images.Count() - 2)
                Next
                For Each i As String In My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly, TextBox2.Text & "*")
                    ListView1.Items.Add(IO.Path.GetFileName(i), ImageList1.Images.Count() - 1)
                Next
            Catch ex As UnauthorizedAccessException
                MessageBox.Show("Unauthorized Access")
            Catch ex As Exception
                MessageBox.Show("Error in FillLV")
            End Try
        End Sub
        Private Sub ListView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles ListView1.MouseDoubleClick
            If ListView1.SelectedItems.Count > 0 Then GoToPath(IO.Path.Combine(path, ListView1.SelectedItems(0).Text))
        End Sub
        Sub GoToPath(p As String)
            If (My.Computer.FileSystem.DirectoryExists(p)) Then
                path = p
                TextBox1.Text = path
                FillLV(path)
            Else
                MessageBox.Show("Its A File")
                '    Process.Start(p)
            End If
        End Sub
        Private Sub TextBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseClick
            ' USER CLICK ON PATH - SO OPEN
            '    FOLDER BROWSER
            Dim fb As New FolderBrowserDialog
            With fb
                .Description = "Browse folder"
                .SelectedPath = path
                .ShowNewFolderButton = False
            End With
            If fb.ShowDialog = DialogResult.OK Then GoToPath(fb.SelectedPath)
            fb.Dispose()
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Not path = TextBox1.Text AndAlso (My.Computer.FileSystem.DirectoryExists(TextBox1.Text)) Then
                GoToPath(TextBox1.Text)
            End If
        End Sub
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            ' GO TO PARENT
            If Not path = IO.Directory.GetDirectoryRoot(path) Then GoToPath(IO.Directory.GetParent(path).FullName)
        End Sub
        Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
            FillLV(path)
        End Sub
        Private Sub ListToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ListToolStripMenuItem.Click
            ListView1.View = View.List
        End Sub
        Private Sub TileToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TileToolStripMenuItem.Click
            ListView1.View = View.Tile
        End Sub
        Private Sub LargreToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LargreToolStripMenuItem.Click
            ListView1.View = View.LargeIcon
        End Sub
        Private Sub SmallToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SmallToolStripMenuItem.Click
            ListView1.View = View.SmallIcon
        End Sub
    End Class


    Regards Les, Livingston, Scotland





    • Edited by leshay Thursday, June 6, 2019 12:00 AM
    Tuesday, June 4, 2019 9:05 PM
  • I want it to do exactly like the file explorer that Windows has, you enter a folder and search for a file and if I have the file it shows and if it does not have it it shows the similar ones and if it does not it does not show anything.

    You can use the same interfaces that Explorer uses, like ISearchFolderItemFactory and IExplorerBrowser to display results

    (I had posted samples for IExplorerBrowser, you can add a TextBox and display the result of the search with IExplorerBrowser.BrowseToObject (It will search and display automatically all the files in a background thread))


    Wednesday, June 5, 2019 5:46 PM
  • This is not what I want, but it is similar.
    Thank you for your help.
    Wednesday, June 5, 2019 6:43 PM
  • I tried to put it here, but it did not work, nothing happens.
    I can send the whole project to you if you want.
    Thank you for your help.
    Wednesday, June 5, 2019 6:45 PM
  • I added 2 textboxes : one to search , another just to test the result string of the search (search-ms Protocol) and it works like in Explorer =>

    Thursday, June 6, 2019 8:25 AM
  • I added 2 TextBoxes, one to search, the other just to see the result string of search (search-ms Protocol)

    and it works like in Explorer : 

    Thursday, June 6, 2019 9:10 AM
  • I could not, sorry I'm an amateur in vb.net, I do not know much about it.
    Here is the whole project for you to access and has two images indicating TextBox2 and Button2:

    https://1drv.ms/u/s!ArgT_dApPP30jZJhIl7b90oF_5MaWQ?e=38dcqg

    Thursday, June 6, 2019 8:20 PM
  • The test with  IExplorerBrowser ISearchFolderItemFactory

    +2 TextBoxes (I used [Enter] to search (Explorer does it on key down) and you can change it)

    Adapted from MS SDK sample ExplorerBrowserSearch

    Option Strict On
    Imports System.Runtime.InteropServices
    Imports System.Text
    
    Public Class Form1
        Public Enum HRESULT As Integer
            S_OK = 0
            S_FALSE = 1
            E_NOINTERFACE = &H80004002
            E_NOTIMPL = &H80004001
            E_FAIL = &H80004005
            E_UNEXPECTED = &H8000FFFF
        End Enum
    
        <ComImport>
        <Guid("dfd3b6b5-c10c-4be9-85f6-a66969f402f6")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IExplorerBrowser
            Function Initialize(hwndParent As IntPtr, ByRef prc As RECT, ByRef pfs As FOLDERSETTINGS) As HRESULT
            Function Destroy() As HRESULT
            Function SetRect(phdwp As IntPtr, ByRef rcBrowser As RECT) As HRESULT
            Function SetPropertyBag(pszPropertyBag As String) As HRESULT
            Function SetEmptyText(pszEmptyText As String) As HRESULT
            Function SetFolderSettings(ByRef pfs As FOLDERSETTINGS) As HRESULT
    
            'IExplorerBrowserEvents *psbe
            Function Advise(psbe As IntPtr, ByRef pdwCookie As Integer) As HRESULT
            Function Unadvise(dwCookie As Integer) As HRESULT
            Function SetOptions(dwFlag As EXPLORER_BROWSER_OPTIONS) As HRESULT
            Function GetOptions(ByRef pdwFlag As EXPLORER_BROWSER_OPTIONS) As HRESULT
            Function BrowseToIDList(pidl As IntPtr, uFlags As UInteger) As HRESULT
    
            'IUnknown *punk,
            Function BrowseToObject(punk As IntPtr, uFlags As UInteger) As HRESULT
            Function FillFromObject(punk As IntPtr, dwFlags As EXPLORER_BROWSER_FILL_FLAGS) As HRESULT
            Function RemoveAll() As HRESULT
            Function GetCurrentView(ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
        End Interface
    
        Public Const SBSP_ABSOLUTE = &H0
    
        Public Enum EXPLORER_BROWSER_OPTIONS As Integer
            EBO_NONE = 0
            EBO_NAVIGATEONCE = &H1
            EBO_SHOWFRAMES = &H2
            EBO_ALWAYSNAVIGATE = &H4
            EBO_NOTRAVELLOG = &H8
            EBO_NOWRAPPERWINDOW = &H10
            EBO_HTMLSHAREPOINTVIEW = &H20
            EBO_NOBORDER = &H40
            EBO_NOPERSISTVIEWSTATE = &H80
        End Enum
    
        Public Enum EXPLORER_BROWSER_FILL_FLAGS As Integer
            EBF_NONE = 0
            EBF_SELECTFROMDATAOBJECT = &H100
            EBF_NODROPTARGET = &H200
        End Enum
    
        Public Enum FOLDERVIEWMODE As Integer
            FVM_AUTO = -1
            FVM_FIRST = 1
            FVM_ICON = 1
            FVM_SMALLICON = 2
            FVM_LIST = 3
            FVM_DETAILS = 4
            FVM_THUMBNAIL = 5
            FVM_TILE = 6
            FVM_THUMBSTRIP = 7
            FVM_CONTENT = 8
            FVM_LAST = 8
        End Enum
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure FOLDERSETTINGS
            Public ViewMode As Integer
            Public fFlags As UInteger
        End Structure
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure RECT
            Public left As Integer
            Public top As Integer
            Public right As Integer
            Public bottom As Integer
            Public Sub New(left As Integer, top As Integer, right As Integer, bottom As Integer)
                Me.left = left
                Me.top = top
                Me.right = right
                Me.bottom = bottom
            End Sub
        End Structure
    
        <DllImport("User32.dll", SetLastError:=True)>
        Public Shared Function GetClientRect(hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True)>
        Public Shared Function OffsetRect(ByRef lprc As RECT, dx As Integer, dy As Integer) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True)>
        Public Shared Function InflateRect(ByRef lprc As RECT, dx As Integer, dy As Integer) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True)>
        Private Shared Function MoveWindow(hWnd As IntPtr, X As Integer, Y As Integer, nWidth As Integer, nHeight As Integer, bRepaint As Boolean) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function FindWindowEx(ByVal hWndParent As IntPtr, ByVal hWndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
        End Function
    
        <DllImport("Shell32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)>
        Public Shared Function SHILCreateFromPath(<MarshalAs(UnmanagedType.LPWStr)> pszPath As String, ByRef ppIdl As IntPtr, ByRef rgflnOut As UInteger) As HRESULT
        End Function
    
    
        <ComImport>
        <Guid("a0ffbc28-5482-4366-be27-3e81e78e06c2")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface ISearchFolderItemFactory
            Function SetDisplayName(pszDisplayName As String) As HRESULT
            Function SetFolderTypeID(ByRef ftid As Guid) As HRESULT
            Function SetFolderLogicalViewMode(flvm As FOLDERLOGICALVIEWMODE) As HRESULT
            Function SetIconSize(iIconSize As Integer) As HRESULT
            Function SetVisibleColumns(cVisibleColumns As UInteger, rgKey As PROPERTYKEY) As HRESULT
            Function SetSortColumns(cSortColumns As UInteger, rgSortColumns As SORTCOLUMN) As HRESULT
            Function SetGroupColumn(keyGroup As PROPERTYKEY) As HRESULT
            Function SetStacks(cStackKeys As UInteger, rgStackKeys As PROPERTYKEY) As HRESULT
            Function SetScope(psiaScope As IShellItemArray) As HRESULT
            Function SetCondition(pCondition As ICondition) As HRESULT
            Function GetShellItem(ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function GetIDList(ByRef ppidl As IntPtr) As HRESULT
        End Interface
    
        <StructLayout(LayoutKind.Sequential, Pack:=4)>
        Public Structure PROPERTYKEY
            Private fmtid As Guid
            Private pid As Integer
            Public ReadOnly Property FormatId() As Guid
                Get
                    Return Me.fmtid
                End Get
            End Property
            Public ReadOnly Property PropertyId() As Integer
                Get
                    Return Me.pid
                End Get
            End Property
            Public Sub New(ByVal formatId As Guid, ByVal propertyId As Integer)
                Me.fmtid = formatId
                Me.pid = propertyId
            End Sub
            Public Shared ReadOnly PKEY_DateCreated As PROPERTYKEY = New PROPERTYKEY(New Guid("B725F130-47EF-101A-A5F1-02608C9EEBAC"), 15)
        End Structure
    
        Public Enum FOLDERLOGICALVIEWMODE
            FLVM_UNSPECIFIED = -1
            FLVM_FIRST = 1
            FLVM_DETAILS = 1
            FLVM_TILES = 2
            FLVM_ICONS = 3
            FLVM_LIST = 4
            FLVM_CONTENT = 5
            FLVM_LAST = 5
        End Enum
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure SORTCOLUMN
            Public propkey As PROPERTYKEY
            Public direction As SORTDIRECTION
        End Structure
    
        Public Enum SORTDIRECTION
            SORT_DESCENDING = -1
            SORT_ASCENDING = 1
        End Enum
    
        <ComImport()>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("b63ea76d-1f85-456f-a19c-48159efa858b")>
        Public Interface IShellItemArray
            'Function BindToHandler(pbc As IBindCtx, ByRef bhid As Guid, ByRef riid As Guid, ByRef ppvOut As IntPtr) As HRESULT
            Function BindToHandler(pbc As IntPtr, ByRef bhid As Guid, ByRef riid As Guid, ByRef ppvOut As IntPtr) As HRESULT
            Function GetPropertyStore(flags As GETPROPERTYSTOREFLAGS, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function GetPropertyDescriptionList(keyType As PROPERTYKEY, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            'Function GetAttributes(AttribFlags As SIATTRIBFLAGS, sfgaoMask As SFGAOF, ByRef psfgaoAttribs As SFGAOF) As HRESULT
            Function GetAttributes(AttribFlags As SIATTRIBFLAGS, sfgaoMask As Integer, ByRef psfgaoAttribs As Integer) As HRESULT
            Function GetCount(ByRef pdwNumItems As Integer) As HRESULT
            Function GetItemAt(dwIndex As Integer, ByRef ppsi As IShellItem) As HRESULT
            'Function EnumItems(ByRef ppenumShellItems As IEnumShellItems) As HRESULT
            Function EnumItems(ByRef ppenumShellItems As IntPtr) As HRESULT
        End Interface
    
        <ComImport()>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")>
        Public Interface IShellItem
            <PreserveSig()>
            Function BindToHandler(ByVal pbc As IntPtr, ByRef bhid As Guid, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function GetParent(ByRef ppsi As IShellItem) As HRESULT
            Function GetDisplayName(ByVal sigdnName As SIGDN, ByRef ppszName As System.Text.StringBuilder) As HRESULT
            Function GetAttributes(ByVal sfgaoMask As UInteger, ByRef psfgaoAttribs As UInteger) As HRESULT
            Function Compare(ByVal psi As IShellItem, ByVal hint As UInteger, ByRef piOrder As Integer) As HRESULT
        End Interface
    
        Public Enum SIGDN As Integer
            SIGDN_NORMALDISPLAY = &H0
            SIGDN_PARENTRELATIVEPARSING = &H80018001
            SIGDN_DESKTOPABSOLUTEPARSING = &H80028000
            SIGDN_PARENTRELATIVEEDITING = &H80031001
            SIGDN_DESKTOPABSOLUTEEDITING = &H8004C000
            SIGDN_FILESYSPATH = &H80058000
            SIGDN_URL = &H80068000
            SIGDN_PARENTRELATIVEFORADDRESSBAR = &H8007C001
            SIGDN_PARENTRELATIVE = &H80080001
        End Enum
    
        Public Enum GETPROPERTYSTOREFLAGS
            GPS_DEFAULT = 0
            GPS_HANDLERPROPERTIESONLY = &H1
            GPS_READWRITE = &H2
            GPS_TEMPORARY = &H4
            GPS_FASTPROPERTIESONLY = &H8
            GPS_OPENSLOWITEM = &H10
            GPS_DELAYCREATION = &H20
            GPS_BESTEFFORT = &H40
            GPS_NO_OPLOCK = &H80
            GPS_PREFERQUERYPROPERTIES = &H100
            GPS_EXTRINSICPROPERTIES = &H200
            GPS_EXTRINSICPROPERTIESONLY = &H400
            GPS_MASK_VALID = &H7FF
        End Enum
    
        Public Enum SIATTRIBFLAGS
            SIATTRIBFLAGS_AND = &H1
            SIATTRIBFLAGS_OR = &H2
            SIATTRIBFLAGS_APPCOMPAT = &H3
            SIATTRIBFLAGS_MASK = &H3
            SIATTRIBFLAGS_ALLITEMS = &H4000
        End Enum
    
        <ComImport>
        <Guid("A5EFE073-B16F-474f-9F3E-9F8B497A3E08")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IConditionFactory
            Function MakeNot(pcSub As ICondition, fSimplify As Boolean, ByRef ppcResult As ICondition) As HRESULT
            'Function MakeAndOr(ct As CONDITION_TYPE, peuSubs As IEnumUnknown, fSimplify As Boolean, ByRef ppcResult As ICondition) As HRESULT
            Function MakeAndOr(ct As CONDITION_TYPE, peuSubs As IntPtr, fSimplify As Boolean, ByRef ppcResult As ICondition) As HRESULT
            'Function MakeLeaf(pszPropertyName As String, cop As CONDITION_OPERATION, pszValueType As String,
            '        ppropvar As PROPVARIANT,
            '       pPropertyNameTerm As IRichChunk,
            '       pOperationTerm As IRichChunk,
            '       pValueTerm As IRichChunk,
            '      fExpand As Boolean, ByRef pcResult As ICondition) As HRESULT
            Function MakeLeaf(pszPropertyName As String, cop As CONDITION_OPERATION, pszValueType As String,
               ByRef ppropvar As PROPVARIANT,
               pPropertyNameTerm As IntPtr,
               pOperationTerm As IntPtr,
               pValueTerm As IntPtr,
              fExpand As Boolean, ByRef pcResult As ICondition) As HRESULT
            Function Resolve(pc As ICondition, sqro As STRUCTURED_QUERY_RESOLVE_OPTION, pstReferenceTime As SYSTEMTIME, ByRef ppcResolved As ICondition) As HRESULT
        End Interface
    
        Public Enum STRUCTURED_QUERY_RESOLVE_OPTION
            SQRO_DEFAULT = 0
            SQRO_DONT_RESOLVE_DATETIME = &H1
            SQRO_ALWAYS_ONE_INTERVAL = &H2
            SQRO_DONT_SIMPLIFY_CONDITION_TREES = &H4
            SQRO_DONT_MAP_RELATIONS = &H8
            SQRO_DONT_RESOLVE_RANGES = &H10
            SQRO_DONT_REMOVE_UNRESTRICTED_KEYWORDS = &H20
            SQRO_DONT_SPLIT_WORDS = &H40
            SQRO_IGNORE_PHRASE_ORDER = &H80
            SQRO_ADD_VALUE_TYPE_FOR_PLAIN_VALUES = &H100
            SQRO_ADD_ROBUST_ITEM_NAME = &H200
        End Enum
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure SYSTEMTIME
            Public wYear As Short
            Public wMonth As Short
            Public wDayOfWeek As Short
            Public wDay As Short
            Public wHour As Short
            Public wMinute As Short
            Public wSecond As Short
            Public wMilliseconds As Short
        End Structure
    
        <ComImport>
        <Guid("0FC988D4-C935-4b97-A973-46282EA175C8")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface ICondition
            Inherits IPersistStream
    #Region "IPersistStream"
            Overloads Function GetClassID(ByRef pClassID As Guid) As HRESULT
            Overloads Function IsDirty() As HRESULT
            Overloads Function Load(ByVal pstm As System.Runtime.InteropServices.ComTypes.IStream) As HRESULT
            Overloads Function Save(ByVal pstm As System.Runtime.InteropServices.ComTypes.IStream, ByVal fClearDirty As Boolean) As HRESULT
            Overloads Function GetSizeMax() As HRESULT
    #End Region
            Function GetConditionType(ByRef pNodeType As CONDITION_TYPE) As HRESULT
            Function GetSubConditions(ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function GetComparisonInfo(ByRef ppszPropertyName As String, ByRef pcop As CONDITION_OPERATION, ByRef ppropvar As PROPVARIANT) As HRESULT
            Function GetValueType(ByRef ppszValueTypeName As String) As HRESULT
            Function GetValueNormalization(ByRef ppszNormalization As String) As HRESULT
            'Function GetInputTerms(ByRef ppPropertyTerm As IRichChunk,
            '     ByRef pOperationTerm As IRichChunk,
            '   ByRef ppValueTerm As IRichChunk) As HRESULT
            Function GetInputTerms(ByRef ppPropertyTerm As IntPtr,
                 ByRef pOperationTerm As IntPtr,
               ByRef ppValueTerm As IntPtr) As HRESULT
            Function Clone(ByRef ppc As ICondition) As HRESULT
        End Interface
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure PROPARRAY
            Public cElems As UInt32
            Public pElems As IntPtr
        End Structure
    
        <StructLayout(LayoutKind.Explicit, Pack:=1)>
        Public Structure PROPVARIANT
            <FieldOffset(0)>
            Public varType As UShort
            <FieldOffset(2)>
            Public wReserved1 As UShort
            <FieldOffset(4)>
            Public wReserved2 As UShort
            <FieldOffset(6)>
            Public wReserved3 As UShort
            <FieldOffset(8)>
            Public bVal As Byte
            <FieldOffset(8)>
            Public cVal As SByte
            <FieldOffset(8)>
            Public uiVal As UShort
            <FieldOffset(8)>
            Public iVal As Short
            <FieldOffset(8)>
            Public uintVal As UInt32
            <FieldOffset(8)>
            Public intVal As Int32
            <FieldOffset(8)>
            Public ulVal As UInt64
            <FieldOffset(8)>
            Public lVal As Int64
            <FieldOffset(8)>
            Public fltVal As Single
            <FieldOffset(8)>
            Public dblVal As Double
            <FieldOffset(8)>
            Public boolVal As Short
            <FieldOffset(8)>
            Public pclsidVal As IntPtr
            <FieldOffset(8)>
            Public pszVal As IntPtr
            <FieldOffset(8)>
            Public pwszVal As IntPtr
            <FieldOffset(8)>
            Public punkVal As IntPtr
            <FieldOffset(8)>
            Public ca As PROPARRAY
            <FieldOffset(8)>
            Public filetime As System.Runtime.InteropServices.ComTypes.FILETIME
        End Structure
    
        Public Enum VT As Short
            VT_EMPTY = 0
            VT_NULL = 1
            VT_I2 = 2
            VT_I4 = 3
            VT_R4 = 4
            VT_R8 = 5
            VT_CY = 6
            VT_DATE = 7
            VT_BSTR = 8
            VT_DISPATCH = 9
            VT_ERROR = 10
            VT_BOOL = 11
            VT_VARIANT = 12
            VT_UNKNOWN = 13
            VT_DECIMAL = 14
            VT_I1 = 16
            VT_UI1 = 17
            VT_UI2 = 18
            VT_UI4 = 19
            VT_I8 = 20
            VT_UI8 = 21
            VT_INT = 22
            VT_UINT = 23
            VT_VOID = 24
            VT_HRESULT = 25
            VT_PTR = 26
            VT_SAFEARRAY = 27
            VT_CARRAY = 28
            VT_USERDEFINED = 29
            VT_LPSTR = 30
            VT_LPWSTR = 31
            VT_RECORD = 36
            VT_FILETIME = 64
            VT_BLOB = 65
            VT_STREAM = 66
            VT_STORAGE = 67
            VT_STREAMED_OBJECT = 68
            VT_STORED_OBJECT = 69
            VT_BLOB_OBJECT = 70
            VT_CF = 71
            VT_CLSID = 72
            VT_BSTR_BLOB = 4095
            VT_VECTOR = 4096
            VT_ARRAY = 8192
            VT_BYREF = 16384
            VT_RESERVED = &H8000S
            VT_ILLEGAL = &HFFFFS
            VT_ILLEGALMASKED = 4095
            VT_TYPEMASK = 4095
        End Enum
    
        Public Enum CONDITION_TYPE
            CT_AND_CONDITION = 0
            CT_OR_CONDITION = (CT_AND_CONDITION + 1)
            CT_NOT_CONDITION = (CT_OR_CONDITION + 1)
            CT_LEAF_CONDITION = (CT_NOT_CONDITION + 1)
        End Enum
    
        Public Enum CONDITION_OPERATION
            COP_IMPLICIT = 0
            COP_EQUAL = (COP_IMPLICIT + 1)
            COP_NOTEQUAL = (COP_EQUAL + 1)
            COP_LESSTHAN = (COP_NOTEQUAL + 1)
            COP_GREATERTHAN = (COP_LESSTHAN + 1)
            COP_LESSTHANOREQUAL = (COP_GREATERTHAN + 1)
            COP_GREATERTHANOREQUAL = (COP_LESSTHANOREQUAL + 1)
            COP_VALUE_STARTSWITH = (COP_GREATERTHANOREQUAL + 1)
            COP_VALUE_ENDSWITH = (COP_VALUE_STARTSWITH + 1)
            COP_VALUE_CONTAINS = (COP_VALUE_ENDSWITH + 1)
            COP_VALUE_NOTCONTAINS = (COP_VALUE_CONTAINS + 1)
            COP_DOSWILDCARDS = (COP_VALUE_NOTCONTAINS + 1)
            COP_WORD_EQUAL = (COP_DOSWILDCARDS + 1)
            COP_WORD_STARTSWITH = (COP_WORD_EQUAL + 1)
            COP_APPLICATION_SPECIFIC = (COP_WORD_STARTSWITH + 1)
        End Enum
    
        <ComImport(),
        Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"),
        InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IPersistStream
            Inherits IPersist
    #Region "IPersist"
            Overloads Function GetClassID(ByRef pClassID As Guid) As HRESULT
    #End Region
            Function IsDirty() As HRESULT
            Function Load(ByVal pstm As System.Runtime.InteropServices.ComTypes.IStream) As HRESULT
            Function Save(ByVal pstm As System.Runtime.InteropServices.ComTypes.IStream, ByVal fClearDirty As Boolean) As HRESULT
            Function GetSizeMax() As HRESULT
        End Interface
    
        <ComImport(),
        Guid("0000010c-0000-0000-C000-000000000046"),
        InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IPersist
            Function GetClassID(ByRef pClassID As Guid) As HRESULT
        End Interface
    
        <ComImport>
        <Guid("cde725b0-ccc9-4519-917e-325d72fab4ce")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IFolderView
            Function GetCurrentViewMode(ByRef pViewMode As UInteger) As HRESULT
            Function SetCurrentViewMode(ViewMode As UInteger) As HRESULT
            Function GetFolder(ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function Item(iItemIndex As Integer, ByRef ppidl As IntPtr) As HRESULT
            Function ItemCount(uFlags As UInteger, ByRef pcItems As Integer) As HRESULT
            Function Items(uFlags As UInteger, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function GetSelectionMarkedItem(ByRef piItem As Integer) As HRESULT
            Function GetFocusedItem(ByRef piItem As Integer) As HRESULT
            Function GetItemPosition(pidl As IntPtr, ByRef ppt As POINT) As HRESULT
            Function GetSpacing(ByRef ppt As POINT) As HRESULT
            Function GetDefaultSpacing(ByRef ppt As POINT) As HRESULT
            Function GetAutoArrange() As HRESULT
            Function SelectItem(iItem As Integer, dwFlags As Integer) As HRESULT
            Function SelectAndPositionItems(cidl As UInteger, apidl As IntPtr, apt As POINT, dwFlags As Integer) As HRESULT
        End Interface
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure POINT
            Public x As Integer
            Public y As Integer
        End Structure
    
        <ComImport>
        <Guid("2EBDEE67-3505-43f8-9946-EA44ABC8E5B0")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IQueryParser
            'Function Parse(pszInputString As String, pCustomProperties As IEnumUnknown, ByRef ppSolution As IQuerySolution) As HRESULT
            Function Parse(pszInputString As String, pCustomProperties As IntPtr, ByRef ppSolution As IQuerySolution) As HRESULT
            Function SetOption([option] As STRUCTURED_QUERY_SINGLE_OPTION, pOptionValue As PROPVARIANT) As HRESULT
            Function GetOption([option] As STRUCTURED_QUERY_SINGLE_OPTION, ByRef pOptionValue As PROPVARIANT) As HRESULT
            Function SetMultiOption([option] As STRUCTURED_QUERY_MULTIOPTION, pszOptionKey As String, ByRef pOptionValue As PROPVARIANT) As HRESULT
            'Function GetSchemaProvider(ByRef ppSchemaProvider As ISchemaProvider) As HRESULT
            Function GetSchemaProvider(ByRef ppSchemaProvider As IntPtr) As HRESULT
            Function RestateToString(pCondition As ICondition, fUseEnglish As Boolean, ByRef ppszQueryString As String) As HRESULT
            Function ParsePropertyValue(pszPropertyName As String, pszInputString As String, ByRef ppSolution As IQuerySolution) As HRESULT
            Function RestatePropertyValueToString(pCondition As ICondition, fUseEnglish As Boolean, ByRef ppszPropertyName As String, ByRef ppszQueryString As String) As HRESULT
        End Interface
    
        Public Enum STRUCTURED_QUERY_SINGLE_OPTION
            SQSO_SCHEMA = 0
            SQSO_LOCALE_WORD_BREAKING = (SQSO_SCHEMA + 1)
            SQSO_WORD_BREAKER = (SQSO_LOCALE_WORD_BREAKING + 1)
            SQSO_NATURAL_SYNTAX = (SQSO_WORD_BREAKER + 1)
            SQSO_AUTOMATIC_WILDCARD = (SQSO_NATURAL_SYNTAX + 1)
            SQSO_TRACE_LEVEL = (SQSO_AUTOMATIC_WILDCARD + 1)
            SQSO_LANGUAGE_KEYWORDS = (SQSO_TRACE_LEVEL + 1)
            SQSO_SYNTAX = (SQSO_LANGUAGE_KEYWORDS + 1)
            SQSO_TIME_ZONE = (SQSO_SYNTAX + 1)
            SQSO_IMPLICIT_CONNECTOR = (SQSO_TIME_ZONE + 1)
            SQSO_CONNECTOR_CASE = (SQSO_IMPLICIT_CONNECTOR + 1)
        End Enum
    
        Public Enum STRUCTURED_QUERY_MULTIOPTION
            SQMO_VIRTUAL_PROPERTY = 0
            SQMO_DEFAULT_PROPERTY = (SQMO_VIRTUAL_PROPERTY + 1)
            SQMO_GENERATOR_FOR_TYPE = (SQMO_DEFAULT_PROPERTY + 1)
            SQMO_MAP_PROPERTY = (SQMO_GENERATOR_FOR_TYPE + 1)
        End Enum
    
        <ComImport>
        <Guid("D6EBC66B-8921-4193-AFDD-A1789FB7FF57")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IQuerySolution
            Inherits IConditionFactory
    #Region "IConditionFactory"
            Overloads Function MakeNot(pcSub As ICondition, fSimplify As Boolean, ByRef ppcResult As ICondition) As HRESULT
            Overloads Function MakeAndOr(ct As CONDITION_TYPE, peuSubs As IntPtr, fSimplify As Boolean, ByRef ppcResult As ICondition) As HRESULT
            Overloads Function MakeLeaf(pszPropertyName As String, cop As CONDITION_OPERATION, pszValueType As String,
                                        ByRef ppropvar As PROPVARIANT, pPropertyNameTerm As IntPtr,
                                        pOperationTerm As IntPtr, pValueTerm As IntPtr,
                                        fExpand As Boolean, ByRef pcResult As ICondition) As HRESULT
            Overloads Function Resolve(pc As ICondition, sqro As STRUCTURED_QUERY_RESOLVE_OPTION, ByRef pstReferenceTime As SYSTEMTIME, ByRef ppcResolved As ICondition) As HRESULT
    #End Region
            'Function GetQuery(ByRef ppQueryNode As ICondition, ByRef ppMainType As IEntity) As HRESULT
            Function GetQuery(ByRef ppQueryNode As ICondition, ByRef ppMainType As IntPtr) As HRESULT
            Function GetErrors(ByRef riid As Guid, ByRef ppParseErrors As IntPtr) As HRESULT
            'Function GetLexicalData(ByRef ppszInputString As String, ByRef ppTokens As ITokenCollection, ByRef plcid As Integer, ByRef ppWordBreaker As IUnknown) As HRESULT
            Function GetLexicalData(ByRef ppszInputString As String, ByRef ppTokens As IntPtr, ByRef plcid As Integer, ByRef ppWordBreaker As IntPtr) As HRESULT
        End Interface
    
        <ComImport>
        <Guid("A879E3C4-AF77-44fb-8F37-EBD1487CF920")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IQueryParserManager
            Function CreateLoadedParser(pszCatalog As String, langidForKeywords As Short, ByRef riid As Guid, ByRef ppQueryParser As IntPtr) As HRESULT
            Function InitializeOptions(fUnderstandNQS As Boolean, fAutoWildCard As Boolean, pQueryParser As IQueryParser) As HRESULT
            Function SetOption([option] As QUERY_PARSER_MANAGER_OPTION, ByRef pOptionValue As PROPVARIANT) As HRESULT
        End Interface
    
        Public Enum QUERY_PARSER_MANAGER_OPTION
            QPMO_SCHEMA_BINARY_NAME = 0
            QPMO_PRELOCALIZED_SCHEMA_BINARY_PATH = (QPMO_SCHEMA_BINARY_NAME + 1)
            QPMO_UNLOCALIZED_SCHEMA_BINARY_PATH = (QPMO_PRELOCALIZED_SCHEMA_BINARY_PATH + 1)
            QPMO_LOCALIZED_SCHEMA_BINARY_PATH = (QPMO_UNLOCALIZED_SCHEMA_BINARY_PATH + 1)
            QPMO_APPEND_LCID_TO_LOCALIZED_PATH = (QPMO_LOCALIZED_SCHEMA_BINARY_PATH + 1)
            QPMO_LOCALIZER_SUPPORT = (QPMO_APPEND_LCID_TO_LOCALIZED_PATH + 1)
        End Enum
    
        Public Const LOCALE_USER_DEFAULT = &H400
    
    
        <ComImport>
        <Guid("1af3a467-214f-4298-908e-06b03e0b39f9")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IFolderView2
            Inherits IFolderView
    #Region "IFolderView"
            Overloads Function GetCurrentViewMode(ByRef pViewMode As UInteger) As HRESULT
            Overloads Function SetCurrentViewMode(ViewMode As UInteger) As HRESULT
            Overloads Function GetFolder(ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Overloads Function Item(iItemIndex As Integer, ByRef ppidl As IntPtr) As HRESULT
            Overloads Function ItemCount(uFlags As UInteger, ByRef pcItems As Integer) As HRESULT
            Overloads Function Items(uFlags As UInteger, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Overloads Function GetSelectionMarkedItem(ByRef piItem As Integer) As HRESULT
            Overloads Function GetFocusedItem(ByRef piItem As Integer) As HRESULT
            Overloads Function GetItemPosition(pidl As IntPtr, ByRef ppt As POINT) As HRESULT
            Overloads Function GetSpacing(ByRef ppt As POINT) As HRESULT
            Overloads Function GetDefaultSpacing(ByRef ppt As POINT) As HRESULT
            Overloads Function GetAutoArrange() As HRESULT
            Overloads Function SelectItem(iItem As Integer, dwFlags As Integer) As HRESULT
            Overloads Function SelectAndPositionItems(cidl As UInteger, apidl As IntPtr, apt As POINT, dwFlags As Integer) As HRESULT
    #End Region
            Function SetGroupBy(key As PROPERTYKEY, fAscending As Boolean) As HRESULT
    
            Function GetGroupBy(ByRef pkey As PROPERTYKEY, ByRef pfAscending As Boolean) As HRESULT
    
            'DEPRECATED
            Function SetViewProperty(pidl As IntPtr, propkey As PROPERTYKEY, propvar As PROPVARIANT) As HRESULT
            'DEPRECATED
            Function GetViewProperty(pidl As IntPtr, propkey As PROPERTYKEY, ByRef ppropvar As PROPVARIANT) As HRESULT
            'DEPRECATED
            Function SetTileViewProperties(pidl As IntPtr, pszPropList As String) As HRESULT
            'DEPRECATED
            Function SetExtendedTileViewProperties(pidl As IntPtr, pszPropList As String) As HRESULT
    
            Function SetText(iType As FVTEXTTYPE, pwszText As String) As HRESULT
            Function SetCurrentFolderFlags(dwMask As Integer, dwFlags As Integer) As HRESULT
            Function GetCurrentFolderFlags(ByRef pdwFlags As Integer) As HRESULT
            Function GetSortColumnCount(ByRef pcColumns As Integer) As HRESULT
            Function SetSortColumns(rgSortColumns As SORTCOLUMN, cColumns As Integer) As HRESULT
            Function GetSortColumns(ByRef rgSortColumns As SORTCOLUMN, cColumns As Integer) As HRESULT
            Function GetItem(iItem As Integer, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function GetVisibleItem(iStart As Integer, fPrevious As Boolean, ByRef piItem As Integer) As HRESULT
            Function GetSelectedItem(iStart As Integer, ByRef piItem As Integer) As HRESULT
            Function GetSelection(fNoneImpliesFolder As Boolean, ByRef ppsia As IShellItemArray) As HRESULT
            Function GetSelectionState(pidl As IntPtr, ByRef pdwFlags As Integer) As HRESULT
            Function InvokeVerbOnSelection(pszVerb As String) As HRESULT
            Function SetViewModeAndIconSize(uViewMode As FOLDERVIEWMODE, iImageSize As Integer) As HRESULT
            Function GetViewModeAndIconSize(ByRef puViewMode As FOLDERVIEWMODE, ByRef piImageSize As Integer) As HRESULT
            Function SetGroupSubsetCount(cVisibleRows As UInteger) As HRESULT
            Function GetGroupSubsetCount(ByRef pcVisibleRows As UInteger) As HRESULT
            Function SetRedraw(fRedrawOn As Boolean) As HRESULT
            Function IsMoveInSameFolder() As HRESULT
            Function DoRename() As HRESULT
        End Interface
    
        Public Enum FVTEXTTYPE
            FVST_EMPTYTEXT = 0
        End Enum
    
        Public Enum FOLDERFLAGS
            FWF_NONE = 0
            FWF_AUTOARRANGE = &H1
            FWF_ABBREVIATEDNAMES = &H2
            FWF_SNAPTOGRID = &H4
            FWF_OWNERDATA = &H8
            FWF_BESTFITWINDOW = &H10
            FWF_DESKTOP = &H20
            FWF_SINGLESEL = &H40
            FWF_NOSUBFOLDERS = &H80
            FWF_TRANSPARENT = &H100
            FWF_NOCLIENTEDGE = &H200
            FWF_NOSCROLL = &H400
            FWF_ALIGNLEFT = &H800
            FWF_NOICONS = &H1000
            FWF_SHOWSELALWAYS = &H2000
            FWF_NOVISIBLE = &H4000
            FWF_SINGLECLICKACTIVATE = &H8000
            FWF_NOWEBVIEW = &H10000
            FWF_HIDEFILENAMES = &H20000
            FWF_CHECKSELECT = &H40000
            FWF_NOENUMREFRESH = &H80000
            FWF_NOGROUPING = &H100000
            FWF_FULLROWSELECT = &H200000
            FWF_NOFILTERS = &H400000
            FWF_NOCOLUMNHEADER = &H800000
            FWF_NOHEADERINALLVIEWS = &H1000000
            FWF_EXTENDEDTILES = &H2000000
            FWF_TRICHECKSELECT = &H4000000
            FWF_AUTOCHECKSELECT = &H8000000
            FWF_NOBROWSERVIEWSTATE = &H10000000
            FWF_SUBSETGROUPS = &H20000000
            FWF_USESEARCHFOLDER = &H40000000
            FWF_ALLOWRTLREADING = &H80000000
        End Enum
    
        <DllImport("Shell32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
        Public Shared Function SHCreateShellItemArrayFromShellItem(psi As IShellItem, <[In], MarshalAs(UnmanagedType.LPStruct)> ByVal riid As Guid, <Out> ByRef ppv As IShellItemArray) As HRESULT
        End Function
    
        <DllImport("Shell32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
        Public Shared Function SHCreateItemFromParsingName(pszPath As String, pbc As IntPtr, <[In], MarshalAs(UnmanagedType.LPStruct)> ByVal riid As Guid, <Out> ByRef ppv As IntPtr) As HRESULT
        End Function
    
        <DllImport("Kernel32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
        Public Shared Sub GetLocalTime(ByRef lpSystemTime As SYSTEMTIME)
        End Sub
    
    
    
    
        Friend WithEvents TextBox1, TextBox2 As TextBox
        Dim pExplorerBrowser As IExplorerBrowser = Nothing
        Dim nTopExplorerBrowser As Integer = 40
        Dim pFolderViewPtr As IntPtr = IntPtr.Zero
        Dim pQueryParser As IQueryParser
    
        Dim sGenericProperties() As String = {"System.Generic.String", "System.Generic.Integer", "System.Generic.DateTime", "System.Generic.Boolean", "System.Generic.FloatingPoint"}
        Dim sGenericSemanticTypes() As String = {"System.StructuredQueryType.String", "System.StructuredQueryType.Integer", "System.StructuredQueryType.DateTime", "System.StructuredQueryType.Boolean", "System.StructuredQueryType.FloatingPoint"}
    
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'SuspendLayout()
            ClientSize = New System.Drawing.Size(1080, 680)
            Name = "Form1"
            Text = "Test IExplorerBrowser & Search"
    
            Dim CLSID_ExplorerBrowser As New Guid("71f96385-ddd6-48d3-a0c1-ae06e8b055fb")
            Dim ExplorerBrowserType As Type = Type.GetTypeFromCLSID(CLSID_ExplorerBrowser, True)
            Dim ExplorerBrowser As Object = Activator.CreateInstance(ExplorerBrowserType)
            pExplorerBrowser = DirectCast(ExplorerBrowser, IExplorerBrowser)
    
            Dim rc As RECT
            GetClientRect(Me.Handle, rc)
            InflateRect(rc, -10, -nTopExplorerBrowser)
            rc.bottom += (nTopExplorerBrowser - 10)
            Dim hr As HRESULT = pExplorerBrowser.Initialize(Me.Handle, rc, Nothing)
    
            If (hr = HRESULT.S_OK) Then
                pExplorerBrowser.SetOptions(EXPLORER_BROWSER_OPTIONS.EBO_SHOWFRAMES Or
                    EXPLORER_BROWSER_OPTIONS.EBO_ALWAYSNAVIGATE Or
                    EXPLORER_BROWSER_OPTIONS.EBO_NOTRAVELLOG Or
                    EXPLORER_BROWSER_OPTIONS.EBO_NOWRAPPERWINDOW Or
                    EXPLORER_BROWSER_OPTIONS.EBO_HTMLSHAREPOINTVIEW Or
                    EXPLORER_BROWSER_OPTIONS.EBO_NOBORDER Or
                    EXPLORER_BROWSER_OPTIONS.EBO_NOPERSISTVIEWSTATE)
                Dim pidlFull As IntPtr = IntPtr.Zero
                hr = SHILCreateFromPath("C:\", pidlFull, Nothing)
                If (hr = HRESULT.S_OK) Then
                    pExplorerBrowser.BrowseToIDList(pidlFull, SBSP_ABSOLUTE)
                    'Dim pfs As FOLDERSETTINGS = New FOLDERSETTINGS()
                    'pfs.ViewMode = FOLDERVIEWMODE.FVM_ICON
                    'hr = pExplorerBrowser.SetFolderSettings(pfs)
                    hr = CreateQueryParser(pQueryParser)
                End If
            End If
    
            TextBox1 = New System.Windows.Forms.TextBox()
    
            TextBox1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            TextBox1.Location = New System.Drawing.Point(ClientSize.Width - 100 - 10, 10)
            TextBox1.Name = "TextBox1"
            TextBox1.Size = New System.Drawing.Size(100, 20)
            TextBox1.TabIndex = 0
    
            TextBox2 = New System.Windows.Forms.TextBox()
            TextBox2.Location = New System.Drawing.Point(10, 10)
            TextBox2.Name = "TextBox2"
            TextBox2.Size = New System.Drawing.Size(ClientSize.Width - 100 - 10 - 10 - 10, 20)
            TextBox2.TabIndex = 1
            TextBox2.ReadOnly = True
    
            Controls.Add(Me.TextBox1)
            Controls.Add(Me.TextBox2)
            'ResumeLayout(False)
            MinimumSize = New System.Drawing.Size(800, 600)
    
            CenterToScreen()
        End Sub
    
        Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
            Dim hWndBrowserControl As IntPtr = FindWindowEx(Me.Handle, IntPtr.Zero, "ExplorerBrowserControl", Nothing)
            If (hWndBrowserControl <> IntPtr.Zero) Then
                'Dim rcBrowser As RECT = New RECT()
                'rcBrowser.left = 10
                'rcBrowser.top = nTopExplorerBrowser
                'rcBrowser.right = Me.ClientSize.Width - 10
                'rcBrowser.bottom = Me.ClientSize.Height - nTopExplorerBrowser - 10
                'pExplorerBrowser.SetRect(IntPtr.Zero, rcBrowser)
                MoveWindow(hWndBrowserControl, 10, nTopExplorerBrowser, Me.ClientSize.Width - 10 * 2, Me.ClientSize.Height - nTopExplorerBrowser - 10, True)
            End If
            If (TextBox2 IsNot Nothing) Then
                MoveWindow(TextBox2.Handle, 10, 10, ClientSize.Width - 100 - 10 - 10 - 10, 20, True)
            End If
        End Sub
        Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
            Dim hr As HRESULT = HRESULT.E_FAIL
            If e.KeyCode = Keys.Enter Then
                Dim pSearchFolderItemFactory As ISearchFolderItemFactory = Nothing
                Dim CLSID_SearchFolderItemFactory As New Guid("14010e02-bbbd-41f0-88e3-eda371216584")
                Dim SearchFolderItemFactoryType As Type = Type.GetTypeFromCLSID(CLSID_SearchFolderItemFactory, True)
                Dim SearchFolderItemFactory As Object = Activator.CreateInstance(SearchFolderItemFactoryType)
                pSearchFolderItemFactory = DirectCast(SearchFolderItemFactory, ISearchFolderItemFactory)
                If (pSearchFolderItemFactory IsNot Nothing) Then
                    hr = pSearchFolderItemFactory.SetDisplayName(TextBox1.Text)
                    Dim pFolderViewPtr As IntPtr
                    Dim IID_IFolderView As New Guid("cde725b0-ccc9-4519-917e-325d72fab4ce")
                    hr = pExplorerBrowser.GetCurrentView(IID_IFolderView, pFolderViewPtr)
                    If (hr = HRESULT.S_OK) Then
                        Dim pFolderView As IFolderView = DirectCast(Marshal.GetObjectForIUnknown(pFolderViewPtr), IFolderView)
                        Dim pShellItemPtr As IntPtr
                        Dim IID_IShellItem As New Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")
                        hr = pFolderView.GetFolder(IID_IShellItem, pShellItemPtr)
                        If (hr = HRESULT.S_OK) Then
                            Dim pShellItem As IShellItem = DirectCast(Marshal.GetObjectForIUnknown(pShellItemPtr), IShellItem)
                            Dim sbItemName As StringBuilder = New StringBuilder(260)
                            'hr = pShellItem.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY, sbItemName)
                            hr = pShellItem.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEFORADDRESSBAR, sbItemName)
                            'Test if the current view is the result of a search
                            'https://docs.microsoft.com/en-us/windows/desktop/search/-search-3x-wds-qryidx-searchms
                            Dim sItemName As String = sbItemName.ToString()
                            If (sItemName.Contains("search-ms")) Then
                                Dim nLocationPos As Integer = sItemName.IndexOf("crumb=location:")
                                Dim sLocation As String = sbItemName.ToString().Substring(nLocationPos + Len("crumb=location:"))
                                Dim pShellItemLocationPtr As IntPtr
                                Dim sDecodedLocation As String = Uri.UnescapeDataString(sLocation)
                                hr = SHCreateItemFromParsingName(sDecodedLocation, IntPtr.Zero, IID_IShellItem, pShellItemLocationPtr)
                                pShellItem = DirectCast(Marshal.GetObjectForIUnknown(pShellItemLocationPtr), IShellItem)
                            End If
                            '{search-ms:displayname=*.jpg&crumb=nomdefichier%3A~"*.jpg"&crumb=location:E%3A%5CToto}
                            Dim pShellItemArray As IShellItemArray = Nothing
                            Dim IID_IShellItemArray As New Guid("{B63EA76D-1F85-456F-A19C-48159EFA858B}")
                            hr = SHCreateShellItemArrayFromShellItem(pShellItem, IID_IShellItemArray, pShellItemArray)
                            If (hr = HRESULT.S_OK) Then
                                hr = pSearchFolderItemFactory.SetScope(pShellItemArray)
                                If (hr = HRESULT.S_OK) Then
                                    'hr = AddCustomCondition(pSearchFolderItemFactory)
                                    hr = AddStructuredQueryCondition(pSearchFolderItemFactory, pQueryParser, TextBox1.Text)
                                    If (hr = HRESULT.S_OK) Then
                                        Dim pShellItemPtr2 As IntPtr
                                        hr = pSearchFolderItemFactory.GetShellItem(IID_IShellItem, pShellItemPtr2)
                                        If (hr = HRESULT.S_OK) Then
                                            hr = pExplorerBrowser.BrowseToObject(pShellItemPtr2, 0)
                                            Dim pShellItem2 As IShellItem = DirectCast(Marshal.GetObjectForIUnknown(pShellItemPtr2), IShellItem)
                                            Dim sbItemName2 As StringBuilder = New StringBuilder(260)
                                            hr = pShellItem2.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEFORADDRESSBAR, sbItemName2)
                                            TextBox2.Text = sbItemName2.ToString()
    
                                            ' Remove columns
                                            Dim t As New Threading.Thread(AddressOf ThreadProc)
                                            t.Start()
    
                                            Marshal.ReleaseComObject(pShellItem2)
                                            'Marshal.Release(pShellItemPtr2)
                                        End If
                                    End If
                                End If
                                Marshal.ReleaseComObject(pShellItemArray)
                            End If
                            Marshal.ReleaseComObject(pShellItem)
                        End If
                        Marshal.ReleaseComObject(pFolderView)
                    End If
                    Marshal.ReleaseComObject(pSearchFolderItemFactory)
                End If
                e.Handled = True
                e.SuppressKeyPress = True
            End If
        End Sub
    
        ' Functions adapted From SDK :
        ' https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/winui/shell/appplatform/ExplorerBrowserSearch
        Public Function AddCustomCondition(psfif As ISearchFolderItemFactory) As HRESULT
            Dim hr As HRESULT = HRESULT.E_FAIL
            Dim pConditionFactory As IConditionFactory = Nothing
            Dim CLSID_ConditionFactory As New Guid("E03E85B0-7BE3-4000-BA98-6C13DE9FA486")
            Dim ConditionFactoryType As Type = Type.GetTypeFromCLSID(CLSID_ConditionFactory, True)
            Dim ConditionFactory As Object = Activator.CreateInstance(ConditionFactoryType)
            pConditionFactory = DirectCast(ConditionFactory, IConditionFactory)
            If (pConditionFactory IsNot Nothing) Then
                Dim pv As PROPVARIANT = New PROPVARIANT()
                pv.varType = CUShort(VT.VT_LPWSTR)
                pv.pwszVal = Marshal.StringToHGlobalUni(TextBox1.Text)
                Dim pCondition As ICondition = Nothing
                hr = pConditionFactory.MakeLeaf("System.FileName", CONDITION_OPERATION.COP_DOSWILDCARDS, Nothing, pv, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, False, pCondition)
                If (hr = HRESULT.S_OK) Then
                    hr = psfif.SetCondition(pCondition)
                    Marshal.ReleaseComObject(pCondition)
                End If
                Marshal.ReleaseComObject(pConditionFactory)
            End If
            Return hr
        End Function
    
        Public Function CreateQueryParser(ByRef pQueryParser As IQueryParser) As HRESULT
            Dim hr As HRESULT = HRESULT.E_FAIL
            Dim pQueryParserManager As IQueryParserManager = Nothing
            Dim CLSID_QueryParserManager As New Guid("5088B39A-29B4-4d9d-8245-4EE289222F66")
            Dim QueryParserManagerType As Type = Type.GetTypeFromCLSID(CLSID_QueryParserManager, True)
            Dim QueryParserManager As Object = Activator.CreateInstance(QueryParserManagerType)
            pQueryParserManager = DirectCast(QueryParserManager, IQueryParserManager)
            If (pQueryParserManager IsNot Nothing) Then
                Dim pQueryParserPtr As IntPtr
                Dim IID_IQueryParser As New Guid("{2EBDEE67-3505-43F8-9946-EA44ABC8E5B0}")
                hr = pQueryParserManager.CreateLoadedParser("SystemIndex", LOCALE_USER_DEFAULT, IID_IQueryParser, pQueryParserPtr)
                If (hr = HRESULT.S_OK) Then
                    pQueryParser = DirectCast(Marshal.GetObjectForIUnknown(pQueryParserPtr), IQueryParser)
                    hr = pQueryParserManager.InitializeOptions(False, True, pQueryParser)
                    If (hr = HRESULT.S_OK) Then
                        For i As Integer = 0 To sGenericProperties.Length - 1
                            Dim pv As PROPVARIANT = New PROPVARIANT()
                            pv.varType = CUShort(VT.VT_LPWSTR)
                            pv.pwszVal = Marshal.StringToHGlobalUni(sGenericProperties(i))
                            hr = pQueryParser.SetMultiOption(STRUCTURED_QUERY_MULTIOPTION.SQMO_DEFAULT_PROPERTY, sGenericSemanticTypes(i), pv)
                        Next
                    End If
                End If
                Marshal.ReleaseComObject(pQueryParserManager)
            End If
            Return hr
        End Function
    
        Public Function AddStructuredQueryCondition(psfif As ISearchFolderItemFactory, pqp As IQueryParser, pszQuery As String) As HRESULT
            Dim pc As ICondition = Nothing
            Dim hr As HRESULT = ParseStructuredQuery(pszQuery, pqp, pc)
            If (hr = HRESULT.S_OK) Then
                hr = psfif.SetCondition(pc)
                Marshal.ReleaseComObject(pc)
            End If
            Return hr
        End Function
    
        Public Function ParseStructuredQuery(pszString As String, pqp As IQueryParser, ByRef ppc As ICondition) As HRESULT
            ppc = Nothing
            Dim pqs As IQuerySolution = Nothing
            Dim hr As HRESULT = pqp.Parse(pszString, IntPtr.Zero, pqs)
            If (hr = HRESULT.S_OK) Then
                Dim pc As ICondition = Nothing
                hr = pqs.GetQuery(pc, IntPtr.Zero)
                If (hr = HRESULT.S_OK) Then
                    Dim st As SYSTEMTIME
                    GetLocalTime(st)
                    hr = pqs.Resolve(pc, STRUCTURED_QUERY_RESOLVE_OPTION.SQRO_DONT_SPLIT_WORDS, st, ppc)
                    Marshal.ReleaseComObject(pc)
                End If
            End If
            Return hr
        End Function
    
        ' To check current view and remove columns for search result view
        Public Sub ThreadProc()
            Dim hr As HRESULT = HRESULT.E_FAIL
            Dim pFolderViewSearch As IFolderView2 = Nothing
            Dim pFolderViewSearchPtr As IntPtr
            Dim IID_IFolderView2 As New Guid("1af3a467-214f-4298-908e-06b03e0b39f9")
            Dim bContinue As Boolean = True
            While (bContinue)
                hr = pExplorerBrowser.GetCurrentView(IID_IFolderView2, pFolderViewSearchPtr)
                If (hr = HRESULT.S_OK) Then
                    pFolderViewSearch = DirectCast(Marshal.GetObjectForIUnknown(pFolderViewSearchPtr), IFolderView2)
                    Dim pShellItemPtr As IntPtr
                    Dim IID_IShellItem As New Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")
                    hr = pFolderViewSearch.GetFolder(IID_IShellItem, pShellItemPtr)
                    If (hr = HRESULT.S_OK) Then
                        Dim pShellItem As IShellItem = DirectCast(Marshal.GetObjectForIUnknown(pShellItemPtr), IShellItem)
                        Dim sbItemName As StringBuilder = New StringBuilder(260)
                        hr = pShellItem.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEFORADDRESSBAR, sbItemName)
                        Dim sItemName As String = sbItemName.ToString()
                        If (sItemName.Contains("search-ms") = False) Then
                            bContinue = True
                            Marshal.ReleaseComObject(pFolderViewSearch)
                        Else
                            bContinue = False
                        End If
                        Marshal.ReleaseComObject(pShellItem)
                    End If
                End If
                System.Threading.Thread.Sleep(100)
            End While
            hr = pFolderViewSearch.SetCurrentFolderFlags(FOLDERFLAGS.FWF_NOCOLUMNHEADER, FOLDERFLAGS.FWF_NOCOLUMNHEADER)
            Marshal.ReleaseComObject(pFolderViewSearch)
        End Sub
    End Class


    • Edited by Castorix31 Thursday, June 6, 2019 8:43 PM
    Thursday, June 6, 2019 8:41 PM
  • Leshay

    Can you send me all this project for me to open it here in my visual studio? 

    Wednesday, June 19, 2019 1:27 PM
  • Hi

    What do you want? All the code (well, at that time) is posted above.

    The copy I have now is no longer the same as the code I posted above.


    Regards Les, Livingston, Scotland

    Wednesday, June 19, 2019 4:33 PM
  • Yes, I want the whole project and not only what you ordered, I speak of all the design even with the design and everything else. If possible.
    I'm really thankful for the help
    Wednesday, June 19, 2019 5:51 PM
  • I was able to open here, I'm going to do some tests. Thank you very much.
    Wednesday, June 19, 2019 6:35 PM
  • Hi,

    Do you resolve the issue? If you resolve the issue, please mark the helpful as answer. It will be beneficial to other community.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 25, 2019 2:59 AM