Re: TreeView events

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hello all,

Most of what I write below is intended to spark-a-flame in a few on the list.
Win32lib isnt going anywhere at the moment so I thought I would help out.
Not with the coding though...

 From: "Matthew Lewis" <matthewwalkerlewis at YAHOO.COM>

> >From MSDN, when you get a WM_NOTIFY from a treeview, you've actually got an
> NMTREEVIEW structure, rather than a NMHDR structure.  

I know Matt was trying to be political about how you setup structures but if you
think far enough in advance and dont want any wasted space or memory
other controls can take advantage of the same or similar structures 
*WITHOUT ANY problems.

look at the below, I reuse these for listview and treeview
   *NMHDR_hwndFrom
   *NMHDR_code

   elsif iMsg = WM_NOTIFY then

          id = peek4s(lParam + NMHDR_hwndFrom)
                    
          if id = ListView1 then

             iMsg = peek4s(lParam + NMHDR_code)
                       
if iMsg = LVN_COLUMNCLICK then -- ListView "could run a sort
             routine here"
      
             elsif iMsg = NM_CLICK then -- ListView Item Clicked
     
                   junk = SendMessage(id,LVM_GETNEXTITEM,-1, LVNI_FOCUSED)
                   poke4(lvitem + lvitem_iItem,junk) 
                   poke4(lvitem + lvitem_iSubItem,0)
                   poke4(lvitem + lvitem_mask,LVIF_TEXT)
                   txtbuff = allocate(256) 
                   poke4(lvitem + lvitem_pszText,txtbuff) 
                   poke4(lvitem + lvitem_cchTextMax,256)
                   cmd = SendMessage(id, LVM_GETITEM, 0, lvitem)               
                   text = peek_zstring(txtbuff)
                   
              end if
                   
          elsif id = TreeView1 then               

              iMsg = peek4s(lParam + NMHDR_code)

              if iMsg = TVN_ITEMEXPANDING then    
                        
                 hItem = peek4u(lParam + NMTVHDR_itemNew)
                 
                     if peek4s(lParam + NMTVHDR_action) = TVE_EXPAND then  
                     
                        itxtbuff = filltvitem(hItem, TVIF_TEXT, 0)            
                        item = SendMessage(id, TVM_GETITEM, 0, tvitem) 


> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla
> tform/CommCtls/TreeView/structures/NMTREEVIEW.asp
> 
> typedef struct tagNMTREEVIEW {
>     NMHDR hdr; 
>     UINT action;           
>     TVITEM itemOld; 
>     TVITEM itemNew; 
>     POINT ptDrag; 
> } NMTREEVIEW, FAR *LPNMTREEVIEW
> 
> You should be able to get the child id from itemOld

Should?  are you sure Matt?

> procedure myNotify(atom iMsg, atom wParam, atom lParam)
>     atom lNewMsg, tvId, VOID
>          , itemOld, childId  -- <== ADD THIS ****************************
>     integer id
>     sequence dirData, currDir
>     -- Only look at NOTIFY messages
>     if iMsg = WM_NOTIFY then
>         -- Get which notify message it is.
>         lNewMsg = fetch( lParam, NMHDR_code )
>         -- Get which control sent it.
>         id = getId( fetch(lParam, NMHDR_hwndFrom ) )
>         --use the ID in any way
> 
> -- ***************** HERE'S WHAT YOU NEED TO DO: ************************
>         if lNewMsg = TVN_ITEMEXPANDING then
> 
>             -- get the pointer to the tvitem
>             -- need to remember to include NMHDR in offset
>             itemOld = peek4u( lParam + 16 )
>       
>             -- Get the win32lib item id
>             childId = fetch( itemOld, TVITEM_lParam )
> 
>             -- Do your stuff....
>         end if
> -- ***************** END *************************************************

You MUST fill in the _itemNew so you'll know what item is expanding if you want
to track
the item later. There again, thinking far enough in advance of yourself..

global function filltvitem(atom Item, atom mask, atom state)
   poke4(tvitem + tvitem_hItem,Item)              
   poke4(tvitem + tvitem_mask,mask)
   poke4(tvitem + tvitem_stateMask, state)
   txtbuff = allocate(256) 
   poke4(tvitem + tvitem_pszText,txtbuff) 
   poke4(tvitem + tvitem_cchTextMax,256) 
   return txtbuff
end function

itxtbuff = filltvitem(hItem, TVIF_TEXT, 0)    
item = SendMessage(id, TVM_GETITEM, 0, tvitem) 

> 
>     end if
> end procedure
> > </code>
> 
> Now that you're starting to interface directly with windows (ie, looking at
> raw structures, unfiltered by win32lib), please remember to be patient
> (unless you're *very* fluent already with C structures).

Better off just learning to write your own code for Windows API 
because you *will outgrow win32lib eventually or need a feature thats missing.
If you know how to write API from the get-go, you want be at a loss when
the time comes. Alot of people think that Win32lib will allow them to write
some major apps in no time at all but this is huge misconception just look
at Judiths IDE. How long has it taken to get to this point? Could have written
the same thing without Win32lib alot faster and used less people to do it.

>  In my experience,
> if you find a bug that you can't track down, you're probably 

Probably? you dont sound sure or, is it because it's Win32lib?

> misusing a
> structure (declared wrong, improper offset, etc).
> 
> Win32Lib will probably be fast enough 

Matt doesnt sound so sure of himself, does he?

> for almost anything you want to do.

Note: almost! My opinion I will keep to myself.

> The one known area where it is lacking is in loading large amounts of data
> at once to a list/treeview. 

Yeah, didnt you write that part Matt?

> There are some on the list who have work
> arounds for that, 

Sure do!

> and something like these methods should be a part of the
> lib eventually.  Once Derek gets his priorities straight and gets back to
> his true calling (coding win32lib, of course!), everything will be better.
> ;)
> 
> Matt Lewis
 
Euman

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu