Ik heb met de volgende code een soort venster weten te maken, die de inhoud van een bepaalde map laat zien (zie onder)
Het enige probleem is nu dat ik die bestanden die ik te zien krijg, niet kan STARTEN! Je kunt klikken wat je wil maar er gebeurd niets. Je kunt alleen maar de inhoud van de directory bekijken.
Weet iemand hoe ik dus een venster kan bouwen waarop de inhoud van een bepaalde map te zien is en de bestanden daarin kan STARTEN?
CODE:
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Private inSysIMageList(2) As Integer
'Form_Load Event.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DisableCloseButton(Me.Handle)
Call GetAssociatedIcons("d:\miek", ListView1)
Dim shLoop As Short 'Loop variable.
Dim SFI As SHFILEINFO 'SHFILEINFO structure.
Dim SGI As SHGFI 'SHGFI enumeration.
'Retrieve and set the large and small ImageLists for ListView1.
'Each control used by .NET has a built in SendMessage, but i`m using the
'good old API.
For shLoop = 0 To 1
inSysIMageList(shLoop) = SHGetFileInfo(Nothing, 0, SFI, Marshal.SizeOf(SFI), SGI.SYSICONINDEX Or shLoop)
SendMessage(ListView1.Handle, LVM_SETIMAGELIST, shLoop, inSysIMageList(shLoop))
Next
End Sub
'This sub retrieves the associated icon of a file`s.
Private Sub GetAssociatedIcons(ByVal stPath As String, ByVal obListView As ListView)
Dim stFiles() As String 'Retrieve all files
' from path stPath.
stFiles = Directory.GetFiles(stPath)
stFiles.Sort(stFiles)
Dim SHI As New SHFILEINFO 'SHFILEINFO structure.
Dim SHISize As Integer = Marshal.SizeOf(SHI) 'Size of SHI.
Dim uflags As SHGFI = SHGFI.SMALLICON Or SHGFI.ICON 'Flags for SHI.
Dim shLoop As Short 'Loop variable.
Dim lvItem As ListViewItem 'ListView item.
With obListView
.BeginUpdate()
.Items.Clear()
For shLoop = 0 To stFiles.Length - 1
lvItem = .Items.Add(stFiles(shLoop), SHI.iIcon)
Next
.EndUpdate()
End With
End Sub
'Set view = LargeIcon.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListView1.View = View.LargeIcon
End Sub
'Set view = Details.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ListView1.View = View.Details
End Sub
'Set view = SmallIcon.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ListView1.View = View.SmallIcon
End Sub
'Set view = List.
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ListView1.View = View.List
End Sub
End Class
Het enige probleem is nu dat ik die bestanden die ik te zien krijg, niet kan STARTEN! Je kunt klikken wat je wil maar er gebeurd niets. Je kunt alleen maar de inhoud van de directory bekijken.
Weet iemand hoe ik dus een venster kan bouwen waarop de inhoud van een bepaalde map te zien is en de bestanden daarin kan STARTEN?
CODE:
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Private inSysIMageList(2) As Integer
'Form_Load Event.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DisableCloseButton(Me.Handle)
Call GetAssociatedIcons("d:\miek", ListView1)
Dim shLoop As Short 'Loop variable.
Dim SFI As SHFILEINFO 'SHFILEINFO structure.
Dim SGI As SHGFI 'SHGFI enumeration.
'Retrieve and set the large and small ImageLists for ListView1.
'Each control used by .NET has a built in SendMessage, but i`m using the
'good old API.
For shLoop = 0 To 1
inSysIMageList(shLoop) = SHGetFileInfo(Nothing, 0, SFI, Marshal.SizeOf(SFI), SGI.SYSICONINDEX Or shLoop)
SendMessage(ListView1.Handle, LVM_SETIMAGELIST, shLoop, inSysIMageList(shLoop))
Next
End Sub
'This sub retrieves the associated icon of a file`s.
Private Sub GetAssociatedIcons(ByVal stPath As String, ByVal obListView As ListView)
Dim stFiles() As String 'Retrieve all files
' from path stPath.
stFiles = Directory.GetFiles(stPath)
stFiles.Sort(stFiles)
Dim SHI As New SHFILEINFO 'SHFILEINFO structure.
Dim SHISize As Integer = Marshal.SizeOf(SHI) 'Size of SHI.
Dim uflags As SHGFI = SHGFI.SMALLICON Or SHGFI.ICON 'Flags for SHI.
Dim shLoop As Short 'Loop variable.
Dim lvItem As ListViewItem 'ListView item.
With obListView
.BeginUpdate()
.Items.Clear()
For shLoop = 0 To stFiles.Length - 1
lvItem = .Items.Add(stFiles(shLoop), SHI.iIcon)
Next
.EndUpdate()
End With
End Sub
'Set view = LargeIcon.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListView1.View = View.LargeIcon
End Sub
'Set view = Details.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ListView1.View = View.Details
End Sub
'Set view = SmallIcon.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ListView1.View = View.SmallIcon
End Sub
'Set view = List.
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ListView1.View = View.List
End Sub
End Class