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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| 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)
LoadLinkFolders(New System.IO.DirectoryInfo(Path & "\Links\"))
LoadLinksPath(Path & "\Links\")
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
LoadPath(objDir.FullName, objNode)
Else
LoadFolders(objDir, objNode)
LoadPath(objDir.FullName, objNode)
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
Private Sub LoadLinkFolders(ByVal dirInfo As System.IO.DirectoryInfo)
Dim objDir As System.IO.DirectoryInfo
For Each objDir In dirInfo.GetDirectories()
If objDir.GetDirectories().Length = 0 Then
LoadLinksPath(objDir.FullName)
Else
LoadLinkFolders(objDir)
LoadLinksPath(objDir.FullName)
End If
Next objDir
End Sub
Private Sub LoadLinksPath(ByVal strPath As String)
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")
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)
Next objFile
End Sub |