• Welcome to PlanetSquires Forums.
 

ListView_AddItem (edit: TreeView_AddItem)

Started by Paul Squires, March 07, 2020, 08:18:54 AM

Previous topic - Next topic

Paul Squires

Hi Jose,

Would you be able to modify the ListView_AddItem (Edit: TreeView_AddItem) function in AfxCtl.inc in order to test for the LPSTR_TEXTCALLBACK value for the incoming text pointer? This would allow me to use the TVN_GETDISPINFO notification to get the node text directly from my class rather than having to set the text for each node.

Obviously, without the following check I will get a GPF when the *pwszText pointer is dereferenced.

   if pwszText <> LPSTR_TEXTCALLBACK then
      tvinsert.Item.cchTextMax     = LEN(*pwszText)
   end if

Thanks!
Paul
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

What I have to change?


' ========================================================================================
PRIVATE FUNCTION ListView_AddItem (BYVAL hwndLV AS HWND, BYVAL nItem AS LONG, BYVAL nImage AS LONG, BYVAL pwszText AS WSTRING PTR) AS LONG
   DIM lvi AS LVITEMW
   lvi.mask = LVIF_TEXT
   lvi.pszText = pwszText
   lvi.iItem = nItem
   lvi.iImage = nImage
   FUNCTION = SendMessageW(hwndLV, LVM_INSERTITEMW, cast(WPARAM, nItem), cast(LPARAM, cast(LVITEMW PTR, @lvi)))
END FUNCTION
' ========================================================================================


Paul Squires

Lol, sorry - I wrote ListView, but I meant TreeView. Don't know why I had ListView on my brain.


' ========================================================================================
' Inserts a new item in a tree-view control.
' Note: It should have been named TreeView_InsertItem, but this name is already been used by a macro.
' ========================================================================================
PRIVATE FUNCTION TreeView_AddItem (BYVAL hwndTV AS HWND, BYVAL hParent AS HTREEITEM, BYVAL hInsertAfter AS HTREEITEM, _
BYVAL pwszText AS WSTRING PTR, BYVAL lParam AS LPARAM = 0, BYVAL iImage AS LONG = 0, BYVAL iSelectedImage AS LONG = 0) AS HTREEITEM
   DIM tvinsert AS TVINSERTSTRUCTW
   tvinsert.hParent             = hParent
   tvinsert.hInsertAfter        = hInsertAfter
   tvinsert.Item.iImage         = iImage
   tvinsert.Item.iSelectedImage = iSelectedImage
   tvinsert.Item.lParam         = lParam
   tvinsert.Item.mask           = TVIF_TEXT OR TVIF_IMAGE OR TVIF_SELECTEDIMAGE OR TVIF_PARAM
   tvinsert.Item.pszText        = pwszText
   if pwszText <> LPSTR_TEXTCALLBACK then
      tvinsert.Item.cchTextMax  = LEN(*pwszText)
   end if
   FUNCTION = cast(HTREEITEM, SendMessageW(hwndTV, TVM_INSERTITEMW, 0, cast(LPARAM, cast(TVINSERTSTRUCTW PTR, @tvinsert))))
END FUNCTION
' ========================================================================================

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca


Paul Squires

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer