1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| Private Sub LoadFavorites()
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
TreeView1.BeginUpdate()
TreeView1.Nodes.Clear()
LoadFolders(New System.IO.DirectoryInfo(Path), Nothing)
LoadPath(Path, Nothing)
TreeView1.EndUpdate()
End Sub
Private Sub LoadFolders(ByVal dirInfo As System.IO.DirectoryInfo, ByVal currentNode As TreeNode)
Dim objNode As System.Windows.Forms.TreeNode
Dim objDir As System.IO.DirectoryInfo
For Each objDir In dirInfo.GetDirectories()
If currentNode Is Nothing Then
objNode = TreeView1.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
objNode.Tag = String.Empty
Else
objNode = currentNode.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
objNode.Tag = String.Empty
End If
objNode.Tag = objDir.FullName
If objDir.GetDirectories().Length = 0 Then
End If
Next objDir
End Sub
Private Sub LoadPath(ByVal strPath As String, ByVal currentNode As TreeNode)
Dim oNode As TreeNode
Dim name As String
Dim objDir As New System.IO.DirectoryInfo(strPath)
Dim SmallIco As IntPtr
Dim shinfo As SHFILEINFO
shinfo = New SHFILEINFO
Dim objFile As System.IO.FileInfo
For Each objFile In objDir.GetFiles("*.url")
oNode = New TreeNode
shinfo.szDisplayName = New String(Chr(0), 260)
shinfo.szTypeName = New String(Chr(0), 80)
SmallIco = SHGetFileInfo(objFile.FullName, 0, shinfo, _
Marshal.SizeOf(shinfo), _
SHGFI_ICON Or SHGFI_SMALLICON)
name = Path.GetFileNameWithoutExtension(objFile.Name)
Dim oIcon As Icon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
TreeView1.ImageList.Images.Add(name, oIcon.ToBitmap)
oNode.Text = name
oNode.Tag = objFile.FullName
oNode.ImageKey = name
oNode.SelectedImageKey = name
If currentNode Is Nothing Then
TreeView1.Nodes.Add(oNode)
End If
Next objFile
End Sub |
Partager