# Re: How to attach the system image list handle to a tree view control ?

Posted by 吴海文 on September 16, 1999 at 10:23:15:

In Reply to: Re: How to attach the system image list handle to a tree view control ? posted by Sun Jack on September 16, 1999 at 00:01:42:

: : 我在VB表单上，放置一个TreeView控制项(名称为treFolder)，在程式中使用如下的叙述取得system imagelist handle。
: : himlSmall = SHGetFileInfo("C:\", 0, sfi, Len(sfi), SHGFI_SYSICONINDEX Or SHGFI_SMALLICON)
: : 但要如何指定给treFolder.ImageList?

: SendMessage hWnd, TVM_SETIMAGELIST, ByVal iImage, ByVal himl

谢谢你的解答，但这个方法我己经试过，仍不能正确运作，在执行加入节点时会出现Run-time error '35613' ImageList must be initialized befor it can be used.
我的程式码如下:

Private Sub Form_Load()
Dim fSuccess As Boolean ' flag indicating everything went OK, starts False
Dim himlSmall As Long ' system imagelist handle
Dim pidlDesktop As Long ' desktop's pidl, the treeview root
Dim sfi As SHFILEINFO
Dim nodX As Node
Dim sRootName As String
' Hourglass on!
Call SetCapture(hWnd)
Call SetCursor(LoadCursor(0, ByVal IDC_WAIT))

' ===============================================
' Grab a handle to the system image list, for our icons
himlSmall = SHGetFileInfo("C:\", 0, sfi, Len(sfi), SHGFI_SYSICONINDEX Or SHGFI_SMALLICON)
' ===============================================
If treFolder.hWnd <> 0 And himlSmall <> 0 Then
'Associate the system image list with the tree view control
Call SendMessage(treFolder.hWnd, TVM_SETIMAGELIST, TVSIL_NORMAL, himlSmall)
treFolder.BorderStyle = vbFixedSingle
treFolder.LineStyle = tvwRootLines
treFolder.Style = tvwTreelinesPlusMinusPictureText
End If
' Returns a complex pidl (realtive to the desktop) from a special folder's ID.
Call SHGetSpecialFolderLocation(hWnd, CSIDL_DESKTOP, pidlDesktop)
' Retrieve the root's friendly name (realtive to the desktop) that we'll put in the treeview...
Call SHGetFileInfo(pidlDesktop, 0, sfi, Len(sfi), SHGFI_PIDL Or SHGFI_DISPLAYNAME)
sRootName = sfi.szDisplayName
Call SHGetFileInfo(pidlDesktop, 0, sfi, Len(sfi), SHGFI_SYSICONINDEX Or SHGFI_SMALLICON Or SHGFI_PIDL)
Set nodX = treFolder.Nodes.Add(, , , sRootName, sfi.iIcon)
' ===============================================
' Hourglass off!
Call ReleaseCapture
Call SetCursor(LoadCursor(0, IDC_ARROW))

End Sub

Follow Ups:

- Re: How to attach the system image list handle to a tree view control ? Sun Jack 00:48:56 9/18/99 (3)
  - Re: How to attach the system image list handle to a tree view control ? 吴海文 09:01:21 9/20/99 (1)
    - Re: How to attach the system image list handle to a tree view control ? Sun Jack 23:41:29 9/21/99 (0)
  - Re: How to attach the system image list handle to a tree view control ? 吴海文 08:57:41 9/20/99 (0)
- Re: How to attach the system image list handle to a tree view control ? Sun Jack 00:48:41 9/18/99 (0)