TreeView TVM_GETITEMRECT VB -> VB.NET

S

Slava ilyin

Hi!

Does anyone know how to get TreeNode RECT using VB.NET?

My code is below seems to be incorrected.
What is wrong?
(sorry, I'm a novice in .NET)

\\\
Private Declare Function SendMessage Lib "user32.dll" Alias
"SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal
wParam As Integer, ByVal lParam As IntPtr) As Integer

....
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
...
Case CDDS_ITEMPOSTPAINT
...
Dim cd2 As NMTVCUSTOMDRAW = m.GetLParam(GetType(NMTVCUSTOMDRAW))
Dim rc2 As RECT = New RECT
//?
rc2.Left = cd2.nmcd.dwItemSpec

Dim gc As GCHandle = GCHandle.Alloc(rc2, GCHandleType.Pinned)
Dim addr As IntPtr = gc.AddrOfPinnedObject()
SendMessage(Handle, TVM_GETITEMRECT, 1, addr)

rc2 must consist Node rect after this (?), but actually - not.

Thanks,
Slava
--
 
C

Cor

Hi Slava,

I am not from the VB6 part, and therefore I have to ask what do you try to
archieve with an Api while there are so many methods and extras in dotNet.

Maybe it is much simpler to do in another way than you do now.

Cor
 
S

Slava Ilyin

Finally decision was found (see code below):

Does anyone know better way to custom paint in TreeView .NET component?
Seems to be TreeView do not support custom paint at all..

Also, how to know .NET Node index according nmcd.dwItemSpec handle? I
want to add additional image index to the TreeNode and want to get this
index on custom paint. There is TV_GETITEM message only I found, but
actually it is not what I want...

Dim memoryBuffer As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(rc2))

rc2.Left = cd2.nmcd.dwItemSpec

Marshal.StructureToPtr(rc2,
memoryBuffer, False)
Dim res = SendMessage(Me.Handle,
TVM_GETITEMRECT, Len(rc2), memoryBuffer)

If res Then
rc2 =
CType(Marshal.PtrToStructure(memoryBuffer, GetType(RECT)), RECT)
'DrawText(.hdc, rc2.Left,
-1, rc2, 0)

g.DrawImage(Me.ImageList2.Images(0), rc2.Right, rc2.Top)

Marshal.FreeHGlobal(memoryBuffer)
End If
 

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