Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
Private Const LV_VIEW_ICON As Integer = &H0
Private Const LV_VIEW_DETAILS As Integer = &H1
Private Const LV_VIEW_SMALLICON As Integer = &H2
Private Const LV_VIEW_LIST As Integer = &H3
Private Const LV_VIEW_TILE As Integer = &H4
Private Const EM_HIDEBALLOONTIP As Integer = &H1504
Private Const LVM_SETVIEW As Integer = &H108E
Private Const ListViewClassName As String = "SysListView32"
Private Shared ReadOnly NullHandleRef As HandleRef = New HandleRef(Nothing, IntPtr.Zero)
<DllImport("user32.dll", ExactSpelling:=True)> _
Private Shared Function EnumChildWindows( _
ByVal hwndParent As HandleRef, _
ByVal lpEnumFunc As EnumChildrenCallback, _
ByVal lParam As HandleRef _
) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage( _
ByVal hWnd As HandleRef, _
ByVal Msg As UInteger, _
ByVal wParam As Integer, _
ByVal lParam As Integer _
) As Integer
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function RealGetWindowClass( _
ByVal hwnd As IntPtr, _
<Out()> ByVal pszType As StringBuilder, _
ByVal cchType As UInteger _
) As UInteger
End Function
Private Delegate Function EnumChildrenCallback( _
ByVal hwnd As IntPtr, _
ByVal lParam As IntPtr _
) As Boolean
Private listViewHandle As HandleRef
Private Sub FindListViewHandle()
Me.listViewHandle = NullHandleRef
Dim lpEnumFunc As EnumChildrenCallback = New EnumChildrenCallback(AddressOf EnumChildren)
EnumChildWindows(New HandleRef(Me.WebBrowser1, Me.WebBrowser1.Handle), lpEnumFunc, NullHandleRef)
End Sub
Private Function EnumChildren( _
ByVal hwnd As IntPtr, _
ByVal lparam As IntPtr _
) As Boolean
Dim sb As StringBuilder = New StringBuilder(100)
RealGetWindowClass(hwnd, sb, 100)
If sb.ToString() = ListViewClassName Then
Me.listViewHandle = New HandleRef(Nothing, hwnd)
End If
Return True
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("c:\")
End Sub
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles Button1.Click
Dim view As Integer
FindListViewHandle()
view = LV_VIEW_ICON
SendMessage(Me.listViewHandle, LVM_SETVIEW, view, 0)
End Sub
End Class