question

jenCarlosLopezReyes-3297 avatar image
0 Votes"
jenCarlosLopezReyes-3297 asked jenCarlosLopezReyes-3297 commented

OPERATIONS WITH IEXPLORERBROWSER

Hello

  1. What I want is to get the path of the selected item by pressing a Button1 from IExplorerBrowser.

  2. Implement this interface IExplorerPaneVisibility to IExplorerBrowser.

I found this code and it shows me the browser.
But I cannot do the mentioned operations. I tried to do it, but was unsuccessful.


Imports System.Runtime.InteropServices
Public Class Form1
Public Enum HRESULT As Integer
DRAGDROP_S_CANCEL = &H40101
DRAGDROP_S_DROP = &H40100
DRAGDROP_S_USEDEFAULTCURSORS = &H40102
DATA_S_SAMEFORMATETC = &H40130
S_OK = 0
S_FALSE = 1
E_NOINTERFACE = &H80004002
E_NOTIMPL = &H80004001
OLE_E_ADVISENOTSUPPORTED = &H80040003
E_FAIL = &H80004005
MK_E_NOOBJECT = &H800401E5
End Enum

 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 Structure RECT
     Public Left As Integer
     Public Top As Integer
     Public Right As Integer
     Public Bottom As Integer
 End Structure

 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 UInteger
     Public fFlags As UInteger
 End Structure

 <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(ByRef phdwp As IntPtr, rcBrowser As RECT) As HRESULT
     Function SetPropertyBag(pszPropertyBag As String) As HRESULT
     Function SetEmptyText(pszEmptyText As String) As HRESULT
     Function SetFolderSettings(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

 <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)>
 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", 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", SetLastError:=True)>
 Public Shared Function SHGetKnownFolderIDList(ByRef rfid As Guid, dwFlags As Integer, hToken As IntPtr, ByRef ppidl As IntPtr) As HRESULT
 End Function

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     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)
     Dim pExplorerBrowser As IExplorerBrowser = DirectCast(ExplorerBrowser, IExplorerBrowser)

     Dim fs As FOLDERSETTINGS
     fs.ViewMode = FOLDERVIEWMODE.FVM_DETAILS
     fs.fFlags = 0
     Dim rc As RECT
     GetClientRect(Me.Handle, rc)
     Dim hr As HRESULT = pExplorerBrowser.Initialize(Me.Handle, rc, fs)
     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 pidlInit As IntPtr
         Dim FOLDERID_ComputerFolder As New Guid("0AC0837C-BBF8-452A-850D-79D08E667CA7")
         SHGetKnownFolderIDList(FOLDERID_ComputerFolder, 0, IntPtr.Zero, pidlInit)
         pExplorerBrowser.BrowseToIDList(pidlInit, SBSP_ABSOLUTE)
     End If
 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)
     MoveWindow(hWndBrowserControl, 0, 0, Me.ClientSize.Width, Me.ClientSize.Height, True)
 End Sub

End Class


I hope you can help me.
Thanks a lot.

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
1 Vote"
Castorix31 answered jenCarlosLopezReyes-3297 commented

A test =>
It works for the button but for IExplorerPaneVisibility I can force it but I don't seem to read it correctly
Otherwise, you can see the implementation in "Microsoft Windows API Code Pack", but it is complex...

 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
    
     <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
    
     <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
    
     <StructLayout(LayoutKind.Sequential)>
     Public Structure FOLDERSETTINGS
         Public ViewMode As Integer
         Public fFlags As UInteger
     End Structure
    
     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
    
     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
    
     <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
    
     <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
    
     <ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214E6-0000-0000-C000-000000000046")>
     Interface IShellFolder
         Function ParseDisplayName(ByVal hwnd As IntPtr, ByVal pbc As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal pszDisplayName As String, <[In], Out> ByRef pchEaten As UInteger, <Out> ByRef ppidl As IntPtr, <[In], Out> ByRef pdwAttributes As SFGAO) As HRESULT
         Function EnumObjects(ByVal hwnd As IntPtr, ByVal grfFlags As SHCONTF, <Out> ByRef ppenumIDList As IEnumIDList) As HRESULT
         Function BindToObject(ByVal pidl As IntPtr, ByVal pbc As IntPtr, <[In]> ByRef riid As Guid, <Out> <MarshalAs(UnmanagedType.[Interface])> ByRef ppv As Object) As HRESULT
         Function BindToStorage(ByVal pidl As IntPtr, ByVal pbc As IntPtr, <[In]> ByRef riid As Guid, <Out> <MarshalAs(UnmanagedType.[Interface])> ByRef ppv As Object) As HRESULT
         Function CompareIDs(ByVal lParam As IntPtr, ByVal pidl1 As IntPtr, ByVal pidl2 As IntPtr) As HRESULT
         Function CreateViewObject(ByVal hwndOwner As IntPtr, <[In]> ByRef riid As Guid, <Out> <MarshalAs(UnmanagedType.[Interface])> ByRef ppv As Object) As HRESULT
         Function GetAttributesOf(ByVal cidl As UInteger, ByVal apidl As IntPtr, <[In], Out> ByRef rgfInOut As SFGAO) As HRESULT
         Function GetUIObjectOf(ByVal hwndOwner As IntPtr, ByVal cidl As UInteger, ByRef apidl As IntPtr, <[In]> ByRef riid As Guid, <[In], Out> ByRef rgfReserved As UInteger, <Out> ByRef ppv As IntPtr) As HRESULT
         Function GetDisplayNameOf(ByVal pidl As IntPtr, ByVal uFlags As SHGDNF, <Out> ByRef pName As STRRET) As HRESULT
         Function SetNameOf(ByVal hwnd As IntPtr, ByVal pidl As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal pszName As String, ByVal uFlags As SHGDNF, <Out> ByRef ppidlOut As IntPtr) As HRESULT
     End Interface
    
     Public Enum SHCONTF
         SHCONTF_CHECKING_FOR_CHILDREN = &H10
         SHCONTF_FOLDERS = &H20
         SHCONTF_NONFOLDERS = &H40
         SHCONTF_INCLUDEHIDDEN = &H80
         SHCONTF_INIT_ON_FIRST_NEXT = &H100
         SHCONTF_NETPRINTERSRCH = &H200
         SHCONTF_SHAREABLE = &H400
         SHCONTF_STORAGE = &H800
         SHCONTF_NAVIGATION_ENUM = &H1000
         SHCONTF_FASTITEMS = &H2000
         SHCONTF_FLATLIST = &H4000
         SHCONTF_ENABLE_ASYNC = &H8000
     End Enum
    
     Public Enum SFGAO
         CANCOPY = &H1
         CANMOVE = &H2
         CANLINK = &H4
         STORAGE = &H8
         CANRENAME = &H10
         CANDELETE = &H20
         HASPROPSHEET = &H40
         DROPTARGET = &H100
         CAPABILITYMASK = &H177
         ENCRYPTED = &H2000
         ISSLOW = &H4000
         GHOSTED = &H8000
         LINK = &H10000
         SHARE = &H20000
         [READONLY] = &H40000
         HIDDEN = &H80000
         DISPLAYATTRMASK = &HFC000
         STREAM = &H400000
         STORAGEANCESTOR = &H800000
         VALIDATE = &H1000000
         REMOVABLE = &H2000000
         COMPRESSED = &H4000000
         BROWSABLE = &H8000000
         FILESYSANCESTOR = &H10000000
         FOLDER = &H20000000
         FILESYSTEM = &H40000000
         HASSUBFOLDER = &H80000000
         CONTENTSMASK = &H80000000
         STORAGECAPMASK = &H70C50008
         PKEYSFGAOMASK = &H81044000
     End Enum
    
     Public Enum SHGDNF
         SHGDN_NORMAL = 0
         SHGDN_INFOLDER = &H1
         SHGDN_FOREDITING = &H1000
         SHGDN_FORADDRESSBAR = &H4000
         SHGDN_FORPARSING = &H8000
     End Enum
    
     <StructLayout(LayoutKind.Explicit, Size:=264)>
     Public Structure STRRET
         <FieldOffset(0)>
         Public uType As UInteger
         <FieldOffset(4)>
         Public pOleStr As IntPtr
         <FieldOffset(4)>
         Public uOffset As UInteger
         <FieldOffset(4)>
         Public cString As IntPtr
     End Structure
    
     <ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214F2-0000-0000-C000-000000000046")>
     Interface IEnumIDList
         <PreserveSig()>
         Function [Next](ByVal celt As UInteger, <Out> ByRef rgelt As IntPtr, <Out> ByRef pceltFetched As Integer) As HRESULT
         <PreserveSig()>
         Function Skip(ByVal celt As UInteger) As HRESULT
         Sub Reset()
         Function Clone() As IEnumIDList
     End Interface
    
     <ComImport, Guid("e07010ec-bc17-44c0-97b0-46c7c95b9edc"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
     Friend Interface IExplorerPaneVisibility
         <PreserveSig>
         Function GetPaneState(ByRef ep As Guid, <Out()> ByRef peps As EXPLORERPANESTATE) As HRESULT
     End Interface
    
     Public Enum EXPLORERPANESTATE
         EPS_DONTCARE = 0
         EPS_DEFAULT_ON = &H1
         EPS_DEFAULT_OFF = &H2
         EPS_STATEMASK = &HFFFF
         EPS_INITIALSTATE = &H10000
         EPS_FORCE = &H20000
     End Enum
    
     Dim EP_NavPane As New Guid("{cb316b22-25f7-42b8-8a09-540d23a43c2f}")
     Dim EP_Commands As New Guid("{d9745868-ca5f-4a76-91cd-f5a129fbb076}")
     Dim EP_Commands_Organize As New Guid("{72e81700-e3ec-4660-bf24-3c3b7b648806}")
     Dim EP_Commands_View As New Guid("{21f7c32d-eeaa-439b-bb51-37b96fd6a943}")
     Dim EP_DetailsPane As New Guid("{43abf98b-89b8-472d-b9ce-e69b8229f019}")
     Dim EP_PreviewPane As New Guid("{893c63d1-45c8-4d17-be19-223be71be365}")
     Dim EP_QueryPane As New Guid("{65bcde4f-4f07-4f27-83a7-1afca4df7ddd}")
     Dim EP_AdvQueryPane As New Guid("{b4e9db8b-34ba-4c39-b5cc-16a1bd2c411c}")
     Dim EP_StatusBar As New Guid("{65fe56ce-5cfe-4bc4-ad8a-7ae3fe7e8f7c}")
     Dim EP_Ribbon As New Guid("{D27524A8-C9F2-4834-A106-DF8889FD4F37}")
    
     <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)>
     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", SetLastError:=True)>
     Public Shared Function SHGetKnownFolderIDList(ByRef rfid As Guid, dwFlags As Integer, hToken As IntPtr, ByRef ppidl As IntPtr) As HRESULT
     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
    
     'Dim pExplorerBrowser As IExplorerBrowser = Nothing
     Friend WithEvents TextBox1 As TextBox
     Friend WithEvents Button1 As Button
    
     Dim ebh As CExplorerBrowserHost
    
     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
         ebh = New CExplorerBrowserHost(Me.Handle)
    
         ClientSize = New System.Drawing.Size(1080, 800)
    
         Button1 = New System.Windows.Forms.Button()
         Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
         Button1.Location = New System.Drawing.Point(10, ClientSize.Height - (32 - (32 - 20) / 2))
         Button1.Name = "Button1"
         Button1.Text = "Current Folder"
         Button1.Size = New System.Drawing.Size(100, 20)
    
         TextBox1 = New System.Windows.Forms.TextBox()
         TextBox1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
         TextBox1.Location = New System.Drawing.Point(120, ClientSize.Height - (32 - (32 - 20) / 2))
         TextBox1.Name = "TextBox1"
         TextBox1.ReadOnly = True
         TextBox1.Size = New System.Drawing.Size(400, 20)
    
         Controls.Add(Me.Button1)
         Controls.Add(Me.TextBox1)
         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)
         MoveWindow(hWndBrowserControl, 0, 0, Me.ClientSize.Width, Me.ClientSize.Height - 32, True)
     End Sub
    
     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
         Dim pFolderViewPtr As IntPtr
         Dim IID_IFolderView As New Guid("cde725b0-ccc9-4519-917e-325d72fab4ce")
         Dim hr As HRESULT = ebh.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_DESKTOPABSOLUTEPARSING, sbItemName)
                 ' hr = pShellItem.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEFORADDRESSBAR, sbItemName)
                 TextBox1.Text = sbItemName.ToString()
             End If
    
             ' Test IExplorerPaneVisibility : does not work ?
             Dim pShellFolderPtr As IntPtr
             Dim IID_IShellFolder As New Guid("000214E6-0000-0000-C000-000000000046")
             hr = pFolderView.GetFolder(IID_IShellFolder, pShellFolderPtr)
             If (hr = HRESULT.S_OK) Then
                 Dim pShellFolder As IShellFolder = DirectCast(Marshal.GetObjectForIUnknown(pShellFolderPtr), IShellFolder)
                 Dim pExplorerPaneVisibility As IExplorerPaneVisibility = DirectCast(pShellFolder, IExplorerPaneVisibility)
                 Dim eps As EXPLORERPANESTATE
                 hr = pExplorerPaneVisibility.GetPaneState(EP_DetailsPane, eps)
             End If
         End If
     End Sub
    
     Private Class CExplorerBrowserHost : Implements IServiceProvider, IExplorerPaneVisibility
         <ComImport()>
         <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
         <Guid("6d5140c1-7436-11ce-8034-00aa006009fa")>
         Public Interface IServiceProvider
             <PreserveSig()>
             Function QueryService(ByRef guidService As Guid, ByRef riid As Guid, ByRef ppvObject As IntPtr) As HRESULT
         End Interface
    
         <DllImport("Shlwapi.DLL", CharSet:=CharSet.Unicode, SetLastError:=True)>
         Friend Shared Function IUnknown_SetSite(<[In](), MarshalAs(UnmanagedType.IUnknown)> ByVal punk As Object, <[In](), MarshalAs(UnmanagedType.IUnknown)> ByVal punkSite As Object) As HRESULT
         End Function
    
         Private Function QueryService(ByRef guidService As Guid, ByRef riid As Guid, <Out()> ByRef ppvObject As IntPtr) As HRESULT Implements IServiceProvider.QueryService
             Dim hr As HRESULT = HRESULT.S_OK
             If guidService.CompareTo(New Guid("e07010ec-bc17-44c0-97b0-46c7c95b9edc")) = 0 Then
                 ppvObject = Marshal.GetComInterfaceForObject(Me, GetType(IExplorerPaneVisibility))
                 hr = HRESULT.S_OK
             Else
                 Dim nullObj As IntPtr = IntPtr.Zero
                 ppvObject = nullObj
                 hr = HRESULT.E_NOINTERFACE
             End If
             Return hr
         End Function
    
         Public Function GetPaneState(ByRef explorerPane As Guid, <System.Runtime.InteropServices.Out()> ByRef peps As EXPLORERPANESTATE) As HRESULT Implements IExplorerPaneVisibility.GetPaneState
             ' Test force all on ON 
             'peps = EXPLORERPANESTATE.EPS_DEFAULT_ON Or EXPLORERPANESTATE.EPS_INITIALSTATE Or EXPLORERPANESTATE.EPS_FORCE
             peps = EXPLORERPANESTATE.EPS_DEFAULT_ON Or EXPLORERPANESTATE.EPS_INITIALSTATE
             Return HRESULT.S_OK
         End Function
    
         Public pExplorerBrowser As IExplorerBrowser = Nothing
    
         Dim EP_NavPane As New Guid("{cb316b22-25f7-42b8-8a09-540d23a43c2f}")
         Dim EP_Commands As New Guid("{d9745868-ca5f-4a76-91cd-f5a129fbb076}")
         Dim EP_Commands_Organize As New Guid("{72e81700-e3ec-4660-bf24-3c3b7b648806}")
         Dim EP_Commands_View As New Guid("{21f7c32d-eeaa-439b-bb51-37b96fd6a943}")
         Dim EP_DetailsPane As New Guid("{43abf98b-89b8-472d-b9ce-e69b8229f019}")
         Dim EP_PreviewPane As New Guid("{893c63d1-45c8-4d17-be19-223be71be365}")
         Dim EP_QueryPane As New Guid("{65bcde4f-4f07-4f27-83a7-1afca4df7ddd}")
         Dim EP_AdvQueryPane As New Guid("{b4e9db8b-34ba-4c39-b5cc-16a1bd2c411c}")
         Dim EP_StatusBar As New Guid("{65fe56ce-5cfe-4bc4-ad8a-7ae3fe7e8f7c}")
         Dim EP_Ribbon As New Guid("{D27524A8-C9F2-4834-A106-DF8889FD4F37}")
    
         Public Sub New(hWnd As IntPtr)
             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 fs As FOLDERSETTINGS
             'fs.ViewMode = FOLDERVIEWMODE.FVM_THUMBNAIL
             fs.ViewMode = FOLDERVIEWMODE.FVM_DETAILS
             fs.fFlags = FOLDERFLAGS.FWF_HIDEFILENAMES
             Dim rc As RECT
             GetClientRect(hWnd, rc)
             If (pExplorerBrowser IsNot Nothing) Then
                 Dim hr As HRESULT = pExplorerBrowser.Initialize(hWnd, rc, fs)
                 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 pUnknown As IntPtr = Marshal.GetIUnknownForObject(pExplorerBrowser)
                     Dim pUnknownSite As IntPtr = Marshal.GetIUnknownForObject(CType(Me, IServiceProvider))
                     'hr = IUnknown_SetSite(pUnknown, pUnknownSite)
                     'hr = IUnknown_SetSite(pUnknown, Me)
                     hr = IUnknown_SetSite(pExplorerBrowser, Me)
                     Dim pidlInit As IntPtr = IntPtr.Zero
                     Dim FOLDERID_ComputerFolder As New Guid("0AC0837C-BBF8-452A-850D-79D08E667CA7")
                     SHGetKnownFolderIDList(FOLDERID_ComputerFolder, 0, IntPtr.Zero, pidlInit)
                     'hr = SHILCreateFromPath("C:\", pidlInit, Nothing)
                     If (hr = HRESULT.S_OK) Then
                         pExplorerBrowser.BrowseToIDList(pidlInit, SBSP_ABSOLUTE)
                     End If
                 End If
             End If
         End Sub
     End Class
 End Class


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.