Declare
PtrSafe
Function
PostMessage
Lib
"user32"
Alias
"PostMessageA"
( _
ByVal
hWnd
As
LongPtr, _
ByVal
Msg
As
Long
, _
ByVal
wParam
As
LongPtr, _
ByVal
lParam
As
LongPtr)
As
LongPtr
Declare
PtrSafe
Function
SendMessage
Lib
"user32"
Alias
"SendMessageA"
( _
ByVal
hWnd
As
LongPtr, _
ByVal
Msg
As
Long
, _
ByVal
wParam
As
LongPtr, _
ByVal
lParam
As
LongPtr)
As
LongPtr
Declare
PtrSafe
Sub
CopyMemory
Lib
"kernel32"
Alias
"RtlMoveMemory"
( _
ByVal
Destination
As
Any, _
ByVal
Source
As
Any, _
ByVal
Length
As
Long
)
Const
TV_FIRST
As
Long
= &H1100
Const
TVM_GETNEXTITEM
As
Long
= (TV_FIRST + 10)
Const
TVM_GETITEM
As
Long
= (TV_FIRST + 12)
Const
TVGN_ROOT
As
Long
= &H0
Const
TVGN_NEXT
As
Long
= &H1
Const
TVIF_TEXT
As
Long
= &H1
Type TVITEM
mask
As
Long
hItem
As
LongPtr
state
As
Long
stateMask
As
Long
pszText
As
LongPtr
cchTextMax
As
Long
iImage
As
Long
iSelectedImage
As
Long
cChildren
As
Long
lParam
As
LongPtr
End
Type
Sub
DebugTreeViewPostMessage()
Dim
hWndTree
As
LongPtr
Dim
hItem
As
LongPtr
Dim
tvItem
As
TVITEM
Dim
buffer
As
String
* 256
Dim
result
As
LongPtr
hWndTree = 198710
If
hWndTree = 0
Then
MsgBox
"Kein gültiges TreeView-Handle gefunden!"
Exit
Sub
End
If
hItem = PostMessage(hWndTree, TVM_GETNEXTITEM, TVGN_ROOT,
ByVal
0&)
If
hItem = 0
Then
MsgBox
"Kein Root-Knoten gefunden."
Exit
Sub
End
If
Do
While
hItem <> 0
With
tvItem
.mask = TVIF_TEXT
.hItem = hItem
.pszText = StrPtr(buffer)
.cchTextMax = Len(buffer)
End
With
result = PostMessage(hWndTree, TVM_GETITEM, 0,
ByVal
VarPtr(tvItem))
If
result <> 0
Then
Debug.Print
"Handle: "
& hItem
Debug.Print
"Text: "
& Left(buffer, InStr(buffer, vbNullChar) - 1)
Else
Debug.Print
"Fehler beim Abrufen des Knotens: "
& hItem
End
If
hItem = PostMessage(hWndTree, TVM_GETNEXTITEM, TVGN_NEXT, hItem)
Loop
MsgBox
"Fertig! Ergebnisse wurden im Debug-Fenster ausgegeben."
End
Sub