News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

TreeView

Started by ragdog, October 15, 2010, 09:06:19 PM

Previous topic - Next topic

ragdog

Hi

I coding with a Treeview is better than listview.

Now have i a question (problem) ::)

I have a Treeview with checkboxes,how i can get the text of all parent items and checked child items of the treeview?
Have any an example about it?

Regards,
ragdog

ragdog

Hi

This is the first time ,thats i coding with a TreeView   ::)
And use checkboxed from a Bmp Image.

Now have i a qeustion how i can ,get text from all Root and all Checked Items?

Please help me

My source is in Radasm and Winasm project files.

Regards,
ragdog

ToutEnMasm


You must know if your checbox is in a resource (dialog box) or in a window.
In a dialog box you can get the handle as this:
   invoke GetDlgItem,Hparente,NumIdentifiant
or use this syntax
      invoke SendDlgItemMessage,Hparente,NumIdentifiant,
            BM_GETCHECK,0, 0

then use "CheckDlgButton"


ragdog

I use not a checkbox button i use checkbox in a treeview

Working with normal checkboxbutton in a Dialog if not this probelm

ToutEnMasm


Perhaps could you put here your piece of code ?.

ragdog

I have uploaded in my second post the source code

Here is a piece of code


.if edx==BN_CLICKED
.if eax==1002
    push ebx
mov tvi._mask, TVIF_HANDLE or TVIF_IMAGE or TVIF_SELECTEDIMAGE
invoke SendDlgItemMessage, hWnd, IDC_MAINTRV, TVM_GETNEXTITEM, TVGN_ROOT, 0
.if eax
               mov tvi.hItem,eax
               mov tvi.imask,TVIF_TEXT
               mov eax,offset lpBuffer
               mov tvi.pszText,eax
               mov tvi.cchTextMax,MAX_PATH
            invoke SendMessage,hMainTreeView,TVM_GETITEM,0,addr tvi
            .if eax
            invoke MessageBox,0,addr lpBuffer,0,MB_OK
               mov eax,tvi.hItem
         
        invoke SendDlgItemMessage, hWnd, IDC_MAINTRV, TVM_GETNEXTITEM, TVGN_CHILD, eax
           mov tvi.hItem, eax

        invoke SendDlgItemMessage, hWnd, IDC_MAINTRV, TVM_GETITEM, 0, addr tvi
        .if tvi.iImage==2
        invoke MessageBox,0,addr lpBuffer,0,MB_OK
        .endif
        invoke SendDlgItemMessage, hWnd, IDC_MAINTRV, TVM_GETNEXTITEM, TVGN_NEXT, tvi.hItem
        mov tvi.hItem, eax
        pop ebx
        .endif
    .endif
            .endif
.endif

ragdog

I have this solved with get all text of a one child
Now have i a question how i can get the text of child


               mov        tvi._mask, TVIF_HANDLE or TVIF_IMAGE or TVIF_SELECTEDIMAGE
           invoke SendMessage,hMainTreeView,TVM_GETNEXTITEM,TVGN_ROOT,0
              mov   tvi.hItem,eax
       invoke SendMessage,hMainTreeView,TVM_GETNEXTITEM,TVGN_CHILD,eax
   .repeat
   .if  eax != NULL
   mov   tvi.hItem,eax
    mov      tvi.imask,TVIF_TEXT or TVIF_IMAGE
   mov   tvi.pszText,offset szBuffer
   mov   tvi.cchTextMax,MAX_PATH
   
invoke   SendMessage,hMainTreeView,TVM_GETITEM,0,addr tvi
.if tvi.iImage==2
                        invoke MessageBox,0,offset szBuffer ,0,MB_OK
                   .endif
   .endif
   invoke SendMessage,hMainTreeView,TVM_GETNEXTITEM,TVGN_NEXT,tvi.hItem
   .until (!eax)



How i can make this?

Please help me :bg

Tedd

A little recursion goes (A little recursion goes (A little recursion goes (A little recursion goes (A little recursion goes (A little recursion goes (A little recursion goes (...) a long way.) a long way.) a long way.) a long way.) a long way.) a long way.) a long way.


    ;to start enumerating all the tree-view items
    invoke SendMessage, hTv,TVM_GETNEXTITEM,TVGN_ROOT,NULL
    invoke enumTvItems, eax
;----------------------------------------------------------------


enumTvItems proc hItem:HANDLE
    push ebx
    mov ebx,hItem
  @@:
    ;invoke printItem, ebx ;;; do what you want with the current item here

    invoke SendMessage, hTv,TVM_GETNEXTITEM,TVGN_CHILD,ebx
    .IF (eax)
        invoke enumTvItems, eax
    .ENDIF

    invoke SendMessage, hTv,TVM_GETNEXTITEM,TVGN_NEXT,ebx
    mov ebx,eax
    test eax,eax
    jnz @B
    pop ebx
    ret
enumTvItems endp

No snowflake in an avalanche feels responsible.

ragdog

Hi Tedd

I must add this for get the text ,but where?
In the procedur enumTvItems?

mov     tvi.imask,TVIF_TEXT or TVIF_IMAGE
mov     tvi.pszText,offset szBuffer
mov     tvi.cchTextMax,MAX_PATH

Thanks for your help

ragdog

#9
I coming not further i need help from member with experince for programming a threeview

Now have solved to get all Rootname of the treeview and nodes name

My probelm is i try to write all RootNames and Nodes Names to a file
root1
  -nodes1
  -nodes2
  -nodes3
  ...
  ..
  .
root2
  -nodes1
  -nodes2
  -nodes3
  ...
  ..
  .

Written File:

Root1=nodes1,nodes2,nodes3....
Root2=nodes1,nodes2,nodes3....

This write file procedur have i not this problem only with get all rootnames and nodes names from the TreeView

This get all root names

GetRootNames Proc
LOCAL tvi :TVITEM
LOCAL RootPath[MAX_PATH] :BYTE

                     
      mov   tvi._mask, TVIF_HANDLE or TVIF_IMAGE or TVIF_SELECTEDIMAGE
      mov   tvi.imask,TVIF_TEXT; or TVIF_IMAGE
      mov   tvi.pszText,offset szBuffer
      mov   tvi.cchTextMax,MAX_PATH
     
      invoke   SendMessage,hMainTreeView,TVM_GETNEXTITEM,TVGN_NEXT,tvi.hItem
         mov   tvi.hItem,eax
      invoke   SendMessage,hMainTreeView,TVM_GETNEXTITEM,TVGN_CHILD,eax
      .while (eax)
                mov  tvi.hItem,eax
             invoke  SendMessage,hMainTreeView, TVM_GETITEM, 0, addr tvi
             .if (eax)
                 invoke MessageBox,0,offset szBuffer,0,MB_OK
             .endif
             invoke   SendMessage,hMainTreeView,TVM_GETNEXTITEM,TVGN_NEXT,tvi.hItem
                mov   tvi.hItem,eax
      .endw
  ret
GetRootNames endp


This get all Nodesname (only from the first root)



                 mov   tvi._mask, TVIF_HANDLE or TVIF_IMAGE or TVIF_SELECTEDIMAGE
              invoke   SendMessage,hMainTreeView,TVM_GETNEXTITEM,TVGN_ROOT,0
                 mov   tvi.hItem,eax
              invoke   SendMessage,hMainTreeView,TVM_GETNEXTITEM,TVGN_CHILD,eax
              .repeat
                  .if  eax != NULL
                          mov   tvi.hItem,eax
                          mov   tvi.imask,TVIF_TEXT or TVIF_IMAGE
                          mov   tvi.pszText,offset szBuffer
                          mov   tvi.cchTextMax,MAX_PATH
                       invoke   SendMessage,hMainTreeView,TVM_GETITEM,0,addr tvi
                       .if tvi.iImage==2
                           invoke MessageBox,0,offset szBuffer ,0,MB_OK
                       .endif
                  .endif
                  invoke   SendMessage,hMainTreeView,TVM_GETNEXTITEM,TVGN_NEXT,tvi.hItem
                     mov   tvi.hItem,eax
             .until (!eax)



The probelm is get the first rootnames then all Nodenames of the first root
then get the second rootnames then all nodenames of the second root
..
.
.

Please help

SOLVED

ragdog

Hi

I try to convert from c++ to masm32 GetItemByName from msdn

C++ Source

    HTREEITEM hItem;
    hItem = GetItemByName(hWndTreeCtrl, NULL, "Jeff");
    if (hItem != NULL)
        SendMessage(hWndTreeCtrl, TVM_SELECTITEM, TVGN_CARET,
                    (LPARAM)hItem);



My Masm32 source

GetItemByName PROTO :HWND,:DWORD,:DWORD

LOCAL  hItem:DWORD

invoke GetItemByName,hMainTreeView, NULL, CTEXT ("Jeff")
   mov   hItem,eax
.if (hItem != NULL)
    invoke SendMessage,hMainTreeView, TVM_SELECTITEM, TVGN_CARET, hItem
.endif


GetItemByName in c++


#include <windows.h>
#include <commctrl.h>

// Note: If you have items with more than 50 characters
// of text, you'll need to increase this value.
#define MAXTEXTLEN 50

HTREEITEM GetItemByName(HWND hWnd, HTREEITEM hItem,
                        LPCTSTR szItemName)
{
    // If hItem is NULL, start search from root item.
    if (hItem == NULL)
        hItem = (HTREEITEM)SendMessage(hWnd, TVM_GETNEXTITEM,
                                       TVGN_ROOT, 0);
    while (hItem != NULL)
    {
        char szBuffer[MAXTEXTLEN+1];
        TV_ITEM item;

        item.hItem = hItem;
        item.mask = TVIF_TEXT | TVIF_CHILDREN;
        item.pszText = szBuffer;
        item.cchTextMax = MAXTEXTLEN;
        SendMessage(hWnd, TVM_GETITEM, 0, (LPARAM)&item);

        // Did we find it?
        if (lstrcmp(szBuffer, szItemName) == 0)
            return hItem;

        // Check whether we have child items.
        if (item.cChildren)
        {
            // Recursively traverse child items.
            HTREEITEM hItemFound, hItemChild;

            hItemChild = (HTREEITEM)SendMessage(hWnd, TVM_GETNEXTITEM,
                                                TVGN_CHILD, (LPARAM)hItem);
            hItemFound = GetItemByName(hWnd, hItemChild, szItemName);

            // Did we find it?
            if (hItemFound != NULL)
                return hItemFound;
        }

        // Go to next sibling item.
        hItem = (HTREEITEM)SendMessage(hWnd, TVM_GETNEXTITEM,
                                       TVGN_NEXT, (LPARAM)hItem);
    }

    // Not found.
    return NULL;
}



GetItemByName My in Masm32

GetItemByName proc hWnd:HWND,hItem:DWORD,szItemName:DWORD
LOCAL item :TVITEM
LOCAL hItemFound:DWORD
LOCAL hItemChild:DWORD

    ;// If hItem is NULL, start search from root item.
    .if (hItem == NULL)
        invoke   SendMessage,hWnd, TVM_GETNEXTITEM,TVGN_ROOT, 0
           mov   hItem,eax
       .while (hItem != NULL)
                 mov   item.hItem,eax
                 mov   item.imask,TVIF_TEXT or TVIF_CHILDREN ;   
                 mov   item.pszText,offset szBuffer
                 mov   item.cchTextMax,MAX_PATH
              invoke   SendMessage,hWnd, TVM_GETITEM, 0, addr item
             
              ;// Did we find it?
              invoke   lstrcmp,addr szBuffer,szItemName
             .if eax==0
                 mov   eax,hItem
             ret
             .endif
             
             ; // Check whether we have child items.
             .if (item.cChildren)
                 invoke   SendMessage,hWnd, TVM_GETNEXTITEM,TVGN_CHILD, hItem
                    mov   hItemChild,eax
                 invoke   GetItemByName,hWnd, hItemChild, szItemName
                    mov   hItemFound ,eax
                   
                 ;// Did we find it?
                .if (hItemFound != NULL)
                    mov   eax, hItemFound;
                    ret
                .endif
             .endif
             
             ; // Go to next sibling item.
             invoke   SendMessage,hWnd, TVM_GETNEXTITEM,TVGN_NEXT,hItem
                mov   hItem,eax
       .endw
    .endif
    ret
GetItemByName endp


What if wrong this expand not the correct item child?

Regards,

japheth


The .ENDIF is at the wrong place:


GetItemByName proc hWnd:HWND,hItem:DWORD,szItemName:DWORD
LOCAL item :TVITEM
LOCAL hItemFound:DWORD
LOCAL hItemChild:DWORD

    ;// If hItem is NULL, start search from root item.
    .if (hItem == NULL)
        invoke   SendMessage,hWnd, TVM_GETNEXTITEM,TVGN_ROOT, 0
           mov   hItem,eax
    .endif
       .while (hItem != NULL)
                 mov   item.hItem,eax
                 mov   item.imask,TVIF_TEXT or TVIF_CHILDREN ;   
                 mov   item.pszText,offset szBuffer
                 mov   item.cchTextMax,MAX_PATH
              invoke   SendMessage,hWnd, TVM_GETITEM, 0, addr item
             
              ;// Did we find it?
              invoke   lstrcmp,addr szBuffer,szItemName
             .if eax==0
                 mov   eax,hItem
             ret
             .endif
             
             ; // Check whether we have child items.
             .if (item.cChildren)
                 invoke   SendMessage,hWnd, TVM_GETNEXTITEM,TVGN_CHILD, hItem
                    mov   hItemChild,eax
                 invoke   GetItemByName,hWnd, hItemChild, szItemName
                    mov   hItemFound ,eax
                   
                 ;// Did we find it?
                .if (hItemFound != NULL)
                    mov   eax, hItemFound;
                    ret
                .endif
             .endif
             
             ; // Go to next sibling item.
             invoke   SendMessage,hWnd, TVM_GETNEXTITEM,TVGN_NEXT,hItem
                mov   hItem,eax
       .endw
    ret
GetItemByName endp


ragdog

Thanks

A simply If ,Endif mistake ::)

ragdog

Hi

I read by Msdn it gives in the Commctrl.h TreeView Macros
Can any send me the actual Commctrl.h?


    * TreeView_CreateDragImage
    * TreeView_DeleteAllItems
    * TreeView_DeleteItem
    * TreeView_EditLabel
    * TreeView_EndEditLabelNow
    * TreeView_EnsureVisible
    * TreeView_Expand
    * TreeView_GetBkColor
    * TreeView_GetCheckState
    * TreeView_GetChild
    * TreeView_GetCount
    * TreeView_GetDropHilight
    * TreeView_GetEditControl
    * TreeView_GetExtendedStyle
    * TreeView_GetFirstVisible
    * TreeView_GetImageList
    * TreeView_GetIndent
    * TreeView_GetInsertMarkColor
    * TreeView_GetISearchString
    * TreeView_GetItem
    * TreeView_GetItemHeight
    * TreeView_GetItemPartRect
    * TreeView_GetItemRect
    * TreeView_GetItemState
    * TreeView_GetLastVisible
    * TreeView_GetLineColor
    * TreeView_GetNextItem
    * TreeView_GetNextSelected
    * TreeView_GetNextSibling
    * TreeView_GetNextVisible
    * TreeView_GetParent
    * TreeView_GetPrevSibling
    * TreeView_GetPrevVisible
    * TreeView_GetRoot
    * TreeView_GetScrollTime
    * TreeView_GetSelectedCount
    * TreeView_GetSelection
    * TreeView_GetTextColor
    * TreeView_GetToolTips
    * TreeView_GetUnicodeFormat
    * TreeView_GetVisibleCount
    * TreeView_HitTest
    * TreeView_InsertItem
    * TreeView_MapAccIDToHTREEITEM
    * TreeView_MapHTREEITEMtoAccID
    * TreeView_Select
    * TreeView_SelectDropTarget
    * TreeView_SelectItem
    * TreeView_SelectSetFirstVisible
    * TreeView_SetAutoScrollInfo
    * TreeView_SetBkColor
    * TreeView_SetBorder
    * TreeView_SetCheckState
    * TreeView_SetExtendedStyle
    * TreeView_SetHot
    * TreeView_SetImageList
    * TreeView_SetIndent
    * TreeView_SetInsertMark
    * TreeView_SetInsertMarkColor
    * TreeView_SetItem
    * TreeView_SetItemHeight
    * TreeView_SetItemState
    * TreeView_SetLineColor
    * TreeView_SetScrollTime
    * TreeView_SetTextColor
    * TreeView_SetToolTips
    * TreeView_SetUnicodeFormat
    * TreeView_ShowInfoTip
    * TreeView_SortChildren
    * TreeView_SortChildrenCB

MichaelW

The header files are available in the Platform SDK, like the one here, for example.
eschew obfuscation