PlanetSquires Forums

Support Forums => WinFBX - Windows Framework for FreeBASIC => Topic started by: Paul Squires on March 07, 2020, 08:18:54 AM

Title: ListView_AddItem (edit: TreeView_AddItem)
Post by: Paul Squires on March 07, 2020, 08:18:54 AM
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
Title: Re: ListView_AddItem
Post by: Josť Roca on March 07, 2020, 08:46:27 AM
What I have to change?

Code: [Select]
' ========================================================================================
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
' ========================================================================================
Title: Re: ListView_AddItem
Post by: Paul Squires on March 07, 2020, 08:52:42 AM
Lol, sorry - I wrote ListView, but I meant TreeView. Don't know why I had ListView on my brain.

Code: [Select]
' ========================================================================================
' 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
' ========================================================================================
Title: Re: ListView_AddItem (edit: TreeView_AddItem)
Post by: Josť Roca on March 07, 2020, 09:26:27 AM
Done.
Title: Re: ListView_AddItem (edit: TreeView_AddItem)
Post by: Paul Squires on March 07, 2020, 11:19:55 AM
Excellent - thanks