PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: ListView_AddItem (edit: TreeView_AddItem)  (Read 244 times)

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9221
  • Windows 10
    • PlanetSquires Software
ListView_AddItem (edit: TreeView_AddItem)
« 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
« Last Edit: March 07, 2020, 08:54:00 AM by Paul Squires »
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3255
Re: ListView_AddItem
« Reply #1 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
' ========================================================================================

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9221
  • Windows 10
    • PlanetSquires Software
Re: ListView_AddItem
« Reply #2 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
' ========================================================================================
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3255
Re: ListView_AddItem (edit: TreeView_AddItem)
« Reply #3 on: March 07, 2020, 09:26:27 AM »

Done.

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9221
  • Windows 10
    • PlanetSquires Software
Re: ListView_AddItem (edit: TreeView_AddItem)
« Reply #4 on: March 07, 2020, 11:19:55 AM »

Excellent - thanks
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer