Humor Me Please (Modified Treeview)

G

govolsbaby

I have the following code that I got from somewhere on the web. I use
it to turn checkboxes on and off for particular nodes of a treeview.
It works fine. My problem is that I didn't write it and I don't
understand it. Obviously I'm pretty much a rank amateur here. I'm
really an aerospace engineer that sometimes writes simple software.
In my quest to learn more, could someone possible give me an English
explanation of what is going on here, especially in sub
TreeNode_SetCheckbox? Especially the hex values? Or at the very
least could you point me to the appropriate place in the documentation
so that I could investigate further on my own? I'd like to further
modify the treeview if I can, and I'm thinking that understanding what
I already have would be a good start. Thanks.

<StructLayout(LayoutKind.Sequential)> Public Structure TVITEM
Public mask As Integer
Public hItem As IntPtr
Public state As Integer
Public stateMask As Integer
<MarshalAs(UnmanagedType.LPTStr)> Public lpszText As String
Public cchTextMax As Integer
Public iImage As Integer
Public iSelectedImage As Integer
Public cChildren As Integer
Public lParam As IntPtr
End Structure

Public Overloads Declare Auto Function SendMessage Lib
"User32.dll" (ByVal _
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr,
ByRef lParam _
As TVITEM) As Integer

Private Sub TreeNode_SetCheckBox(ByVal myNode As TreeNode, ByVal
bVisible As Boolean)
Dim iIndex As Integer = 0
If bVisible Then
iIndex = 1
End If
Dim myTVI As New TVITEM
myTVI.hItem = myNode.Handle
myTVI.mask = &H8
myTVI.stateMask = &HF000
myTVI.state = iIndex << 12
SendMessage(myNode.TreeView.Handle, &H1100 + 63, IntPtr.Zero,
myTVI)
End Sub
 
J

James Hahn

The author is Brad Martinez. The original code had quite a few comments and
includes many more features - you can still find it at
vbnet.mvps.org/index.html?code/comctl/, and there is some additional
discussion at btmtz.mvps.org/treeview/. But AFAICT you should not need any
of this special code if you use .NET. Even if you do use these routines,
then understanding the equivalent procedure in .NET is probably the simplest
way to work out what they are doing. To understand the process you need to
consult the description of Windows message numbers &H100+nn, and 63 in
particular. MSDN no longer maintains reference material that is this old,
but you can see it for Windows Mobile, which is a subset. See, for
instance, here:
http://msdn.microsoft.com/en-us/library/ms913992.aspx
for information about the TVItem structure, which is what does all the work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top