June 16, 2024, 05:15:21 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


TreeView problem

Started by LarryMc, June 04, 2009, 07:22:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

I'm building an application based upon a treeview.
I have a series of entries at the root level and they all have child entries.

When a user clicks on an item I need to know if they clicked on a root item or child item.

I wrote the following sub based upon the source of other EB subs:

TYPE TVITEM
DEF mask:INT
DEF hItem:INT
DEF state:INT
DEF stateMask:INT
DEF pszText:STRING
DEF cchTextMax:INT
DEF iImage:INT
DEF iSelectedImage:INT
DEF cChildren:INT
DEF lParam:INT
ENDTYPE

CONST TVIF_CHILDREN = &H40

SUB tvGotChild(win as WINDOW,id as UINT,handle as UINT),INT
uint hControl
TVITEM tvi
hControl = GetDlgItem(win.hwnd,id)
POINTER p
UINT lParam
IF(hControl)
ZeroMemory(tvi,LEN(TVITEM))
tvi.mask = TVIF_CHILDREN
tvi.hitem = handle
p = tvi
lParam = p
SendMessageA(hcontrol,TVM_GETITEMA,0,lParam)
return tvi.cChildren
ENDIF
RETURN 0
ENDSUB

I call it with this:
tvHandle = tvGetSelectedItem(win_main,IDT_TREE)
print tvGotChild(win_main,IDT_TREE,tvHandle)


whether I click on a root item or a child of a rootitem my routine always returns 0.

Any ideas?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Sure.  Where did you get that UDT definition from?  Because it is wrong.


type TV_ITEM
    UINT       mask
    UINT     hItem
    UINT       state
    UINT       stateMask
    POINTER    pszText
    int        cchTextMax
    int        iImage
    int        iSelectedImage
    int        cChildren
    UINT       lParam
endtype


The member names come from Microsoft, and they use a common C naming convention.  then "psz" in pszText stands for Pointer String Zero terminated.  It looks like you got the definition from Creative BASIC code.

Also this is a bit odd:

      p = tvi
      lParam = p
      SendMessageA(hcontrol,TVM_GETITEMA,0,lParam)

Simpler to use:

      SendMessageA(hcontrol,TVM_GETITEMA,0,&tvi)

The other matter is TVIF_CHILDREN, which sets cChildrent to either 0 if the item has no children, or 1 if the item has 1 or more children.  Just be sure your logic is correct since a root entry with no children will still return 0. 

Paul.

Paul.
Ionic Wind Support Team

LarryMc

Quote from: Paul Turley on June 04, 2009, 08:02:24 AM
Sure.  Where did you get that UDT definition from?  Because it is wrong.
from the api viewer
Quote from: Paul Turley on June 04, 2009, 08:02:24 AM
Also this is a bit odd:

      p = tvi
      lParam = p
      SendMessageA(hcontrol,TVM_GETITEMA,0,lParam)
I'm gonna love this one....
I NEVER get to do this.......
drum roll please..........

I did a Ctrl-C/Ctrl-V from YOUR source code for the treeview commands ;D ;D ;D ;D ;D ;D ;D ;D ;D

Don't ban me. :D

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

I knew exactly where you got it from, just thought it was odd you were using it without questioning it.  ;D

It's one of those "if it ain't broke, don't fix it" pieces of code.  A few years ago I was struggling with a bug in the compiler and the address of a UDT wasn't being passed properly, so I spelled it out one step at a time to be sure lparam really contained the address of the udt.

Never change it. But at lease I remember to remove all of the DEBUGPRINT statements. lol.

Paul.

Ionic Wind Support Team