News:

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

TreeView Example

Started by devilhorse, November 11, 2010, 05:23:46 AM

Previous topic - Next topic

devilhorse

Does any one have an example of a they have created with EasyCode  for a visual project? The code is used does not show the attached images or the treeview lines using the code below.

frmMainProjectTree Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
   Local tvinsert:TV_INSERTSTRUCT
   LOCAL hBitmap:DWORD
   Local tvhit:TV_HITTESTINFO
   Local hImageList:DWord
   Local hParent:DWord
   Local hIcon:DWord
   Local me:DWord


   m2m me, hWnd

   Select uMsg, Eax
   Case WM_CREATE


       ;---------- [First, initialize the image list you will need.] ----------
      Invoke ImageList_Create, 16, 16, TRUE, 2, 10
      Mov hImageList, Eax

      ;---------- [Load the bitmap and add it to the image lists] -----------
      Invoke LoadBitmap, App.Instance, IDB_TREE
      Mov hBitmap, Eax

      Invoke ImageList_Add, Addr hImageList, Addr hBitmap, NULL
      Invoke DeleteObject, hBitmap

      ;---------- [Associate the image lists with the list view.] -----------

      Invoke SendMessage, me, TVM_SETIMAGELIST, 0, hImageList

      ;---------- [Fill the tree] ----------
      ;Invoke SendMessage, hWnd, TVM_DELETEITEM, 0, TVI_ROOT
      mov tvinsert.hParent,NULL
      mov tvinsert.hInsertAfter,TVI_ROOT
      mov tvinsert.item.imask,TVIF_TEXT+TVIF_IMAGE+TVIF_SELECTEDIMAGE
      mov tvinsert.item.pszText,offset Parent
      mov tvinsert.item.iImage,0
      Mov tvinsert.item.iSelectedImage, 1

      Invoke SendMessage, me, TVM_INSERTITEM, 0, Addr tvinsert
      mov hParent,eax
      mov tvinsert.hParent,eax
      mov tvinsert.hInsertAfter,TVI_LAST
      Mov tvinsert.item.pszText, Offset Child1

      Invoke SendMessage, me, TVM_INSERTITEM, 0, Addr tvinsert
      mov tvinsert.item.pszText,offset Child2
      Invoke SendMessage, me, TVM_INSERTITEM, 0, Addr tvinsert

   Return TRUE
      EndSw
   Return FALSE
frmMainProjectTree EndP

Ramon Sala

Hi devilhorse,

I've been analyzing the code you posted and I saw that you are sending the treeview messages to the main window, not to the treeview control. So, at the begining of the WM_CREATE message get the treeview handle by writing the following lines (I assume the treeview control is named TreeView1):

      Invoke GetWindowItem, me, IDC_FRMMAINPROJECTTREE_TREEVIEW1
      Mov Treeview, Eax


Then send all treeview messages to the 'Treeview' handle:

      Invoke SendMessage, Treeview, TVM_SETIMAGELIST, TVSIL_NORMAL, hImageList
      ...
      Invoke SendMessage, Treeview, TVM_INSERTITEM, 0, Addr tvinsert
      ...
      Invoke SendMessage, Treeview, TVM_INSERTITEM, 0, Addr tvinsert
      ...



Also, you are not passing the right parameters to the ImageList_Add function. Instead, you are passing their addresses. For the ImageList_Add function to work properly, remove the 'Addr' operator from the 'hImageList' and 'hBitmap' parameters so that the line looks like this:

      Invoke ImageList_Add, hImageList, hBitmap, NULL


Finally, if you want the expand/collapse buttons to appear, make sure the 'HasButtons', 'HasLines' and 'LinesAtRoot' properties of the TreeView control are set to TRUE.

Regards,

Ramon

Greetings from Catalonia