Here is a sample how to implement, take advantage of and exploit the "explorer.exe" built in TreeView Control.
Basic Set Up for the INameSpaceTreeControl2:
If you proceed here WITHOUT setting up a handler for your Tree Control you will get a Tree which is "braindead".
It does respond to your actions BUT IT DOESN'T KNOW WHAT IT acts on.
Therefore are theese two lines EXTREMLY crucial for the Tree Control.
If you skip these two lines you will have ha control like this by default. It looks nice and tidy but as I told you earlier the control is "Braindead!.
And if you do the implementation of the INameSpaceTreeControlEvents WITHOUT specifying how the icons shall and should be displayed YOU WILL END UP in showing ONLY "Fallback Icons". Because as I said the Tree Control is "braindead".
Therefore this is crucial and IT IS UNDOCUMENTED in the online MSDN Reference for some odd reason :confused:!!
You need to Implement following:
But this is NOT the whole thruth...at all...
If you have done every step as I have explained in this example so far you will STILL end up with fallback icons!!
This is the most crucial and the most decisive moment for you to take control of the Tree Control!!
And as I explained this method is NOT documented in the MSDN for some reason?!
I did find it in a Visual Delphi example!!
Now you have the Tree Control in your possession and it's no longer "braindead" because you are now deciding what to do whith it :D:)
I have not worked on pIF yet!! <-- '**IShellItemFilter
There are some few more interfaces that should be implemented but as it is now it's working :cool::wave:
Cheers Have Fun ;);)
Basic Set Up for the INameSpaceTreeControl2:
Code:
Private Sub Command8_Click()
Dim pidl As Long
Dim pISI As IShellItem
Dim hr As Long
Dim pINSTC2 As INameSpaceTreeControl2
Dim lpRC As RECT
Dim pIF As IShellItemFilter '**
Dim pINSTC_Events As INameSpaceTreeControlEvents
Dim pINSTC_CustomDraw As INameSpaceTreeControlCustomDraw
Dim dwAdviseCookie As Long
Dim pISP As IServiceProvider
Dim dwShContf_Flags As SHCONTF
dwShContf_Flags = SHCONTF_CHECKING_FOR_CHILDREN Or SHCONTF_ENABLE_ASYNC Or SHCONTF_FASTITEMS Or SHCONTF_FLATLIST Or _
SHCONTF_FOLDERS Or SHCONTF_INCLUDEHIDDEN Or SHCONTF_INCLUDESUPERHIDDEN Or SHCONTF_INIT_ON_FIRST_NEXT Or _
SHCONTF_NAVIGATION_ENUM Or SHCONTF_NETPRINTERSRCH Or SHCONTF_NONFOLDERS Or SHCONTF_SHAREABLE Or _
SHCONTF_STORAGE Or NSTCRS_VISIBLE
hr = m_cShell32.ShGetItemIdFromURL(Text1.Text, pidl) '<--- I have fixed this so it can be internert/network or local pidl
If pidl > 0 Then
m_cShell32.ShGetIShellItemFromItemId pidl, pISI
m_cShell32.ShCreateINameSpaceTreeControl2 pINSTC2
SetRect lpRC, 5, 5, 500, 500
pINSTC2.Initialize Me.hWnd, lpRC, NSTCS_BORDER Or NSTCS_FULLROWSELECT Or NSTCS_RICHTOOLTIP Or _
NSTCS_SPRINGEXPAND Or NSTCS_ALLOWJUNCTIONS Or NSTCS_SHOWSELECTIONALWAYS Or _
NSTCS_HASEXPANDOS Or NSTCS_SPRINGEXPAND Or NSTCS_TABSTOP Or NSTCS_EMPTYTEXT
pINSTC2.AppendRoot pISI, dwShContf_Flags, NSTCRS_EXPANDED Or _
NSTCRS_VISIBLE, pIF
pINSTC2.SetControlStyle2 NSTCS2_SHOWNULLSPACEMENU Or NTSCS2_NEVERINSERTNONENUMERATED Or NSTCS2_DISPLAYPADDING Or NSTCS2_DISPLAYPINNEDONLY, NSTCS2_SHOWNULLSPACEMENU Or NTSCS2_NEVERINSERTNONENUMERATED Or NSTCS2_DISPLAYPADDING Or NSTCS2_DISPLAYPINNEDONLY
pINSTC2.SetItemState pISI, NSTCIS_EXPANDED And NSTCIS_SELECTED, NSTCIS_EXPANDED And NSTCIS_SELECTED
Set pINSTC_Events = New cINameSpaceTreeControlEvents
pINSTC2.TreeAdvise pINSTC_Events, dwAdviseCookie
End If
End Sub
It does respond to your actions BUT IT DOESN'T KNOW WHAT IT acts on.
Therefore are theese two lines EXTREMLY crucial for the Tree Control.
Code:
Set pINSTC_Events = New cINameSpaceTreeControlEvents
pINSTC2.TreeAdvise pINSTC_Events, dwAdviseCookie '<--- dwAdviseCookie is just a number you decide if you use more than one Tree Control.
And if you do the implementation of the INameSpaceTreeControlEvents WITHOUT specifying how the icons shall and should be displayed YOU WILL END UP in showing ONLY "Fallback Icons". Because as I said the Tree Control is "braindead".
Therefore this is crucial and IT IS UNDOCUMENTED in the online MSDN Reference for some odd reason :confused:!!
You need to Implement following:
Code:
'Everything in this code bracket you shall put in a separate class-file (*.cls)
Implements INameSpaceTreeControlEvents
Public Sub INameSpaceTreeControlEvents_OnItemClick(ByVal psi As IShellItem, ByVal nstceHitTestFlag As NSTCEHITTEST, ByVal nstceClickTypeMask As NSTCECLICKTYPE)
End Sub
Public Sub INameSpaceTreeControlEvents_OnPropertyItemCommit(ByVal psi As IShellItem)
End Sub
Public Sub INameSpaceTreeControlEvents_OnItemStateChanging(ByVal psi As IShellItem, ByVal nstcisMask As NSTCITEMSTATE, ByVal nstcisState As NSTCITEMSTATE)
End Sub
Public Sub INameSpaceTreeControlEvents_OnItemStateChanged(ByVal psi As IShellItem, ByVal nstcisMask As NSTCITEMSTATE, ByVal nstcisState As NSTCITEMSTATE)
End Sub
Public Sub INameSpaceTreeControlEvents_OnSelectionChanged(ByVal psiaSelection As IShellItemArray)
End Sub
Public Sub INameSpaceTreeControlEvents_OnKeyBoardInput(ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
End Sub
Public Sub INameSpaceTreeControlEvents_OnBeforeExpand(ByVal psi As IShellItem)
End Sub
Public Sub INameSpaceTreeControlEvents_OnAfterExpand(ByVal psi As IShellItem)
End Sub
Public Sub INameSpaceTreeControlEvents_OnBeginLabelEdit(ByVal psi As IShellItem)
End Sub
Public Sub INameSpaceTreeControlEvents_OnEndLabelEdit(ByVal psi As IShellItem)
End Sub
Public Sub INameSpaceTreeControlEvents_OnGetToolTip(ByVal psi As IShellItem, ByRef pszTip As Long, ByVal cchTip As Long)
End Sub
Public Sub INameSpaceTreeControlEvents_OnBeforeItemDelete(ByVal psi As IShellItem)
End Sub
Public Sub INameSpaceTreeControlEvents_OnItemAdded(ByVal psi As IShellItem, ByVal fIsRoot As bool)
End Sub
Public Sub INameSpaceTreeControlEvents_OnItemDeleted(ByVal psi As IShellItem, ByVal fIsRoot As bool)
End Sub
Public Sub INameSpaceTreeControlEvents_OnBeforeContextMenu(ByVal psi As IShellItem, riid As UUID, ByRef ppv As Long)
End Sub
Public Sub INameSpaceTreeControlEvents_OnAfterContextMenu(ByVal psi As IShellItem, ByVal pcmIn As IContextMenu, riid As UUID, ByRef ppv As Long)
End Sub
Public Sub INameSpaceTreeControlEvents_OnBeforeStateImageChange(ByVal psi As IShellItem)
End Sub
Public Sub INameSpaceTreeControlEvents_OnGetDefaultIconIndex(ByVal psi As IShellItem, ByRef pIDefaultIcon As
Long, ByRef pIOpenIcon As Long)
End Sub
If you have done every step as I have explained in this example so far you will STILL end up with fallback icons!!
This is the most crucial and the most decisive moment for you to take control of the Tree Control!!
And as I explained this method is NOT documented in the MSDN for some reason?!
I did find it in a Visual Delphi example!!
Code:
Public Sub INameSpaceTreeControlEvents_OnGetDefaultIconIndex(ByVal psi As IShellItem, ByRef pIDefaultIcon As Long, ByRef pIOpenIcon As Long)
Dim nIconIndex As Long
Dim iIconSize As Integer
Dim m_cShell32 As New cShell32
Dim pidlItem As Long
m_cShell32.ShGetItemIdFromShellItem psi, pidlItem
If pidlItem > 0 Then
nIconIndex = m_cShell32.GetItemIconIndex(pidlItem)
Debug.Print nIconIndex
pIDefaultIcon = nIconIndex
pIOpenIcon = nIconIndex
Set psi = Nothing
CoTaskMemFree pidlItem
End If
End Sub
I have not worked on pIF yet!! <-- '**IShellItemFilter
There are some few more interfaces that should be implemented but as it is now it's working :cool::wave:
Cheers Have Fun ;);)