News:

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

No Image In Treeview

Started by devilhorse, June 10, 2006, 04:47:44 AM

Previous topic - Next topic

devilhorse

Here is my code for a visual project in easy code. The text and the lines show up in the treeview but the images do not show up. What am i doing wrong?

.Const
TVM_SETBKCOLOR         Equ  TV_FIRST + 29
TVM_SETTEXTCOLOR       equ  TV_FIRST + 30
TVM_SETLINECOLOR       equ  TV_FIRST + 40
TVM_SETINSERTMARKCOLOR Equ  TV_FIRST + 37


.Data?
hInstance      HINSTANCE ?
hwndTreeView   DD ?
hParent      dd ?
hImageList   dd ?
hDragImageList      DD ?
ContentsFolder DD ?

.Data
Parent      DB "Contents", 0
Child1      DB "Contents", 0
Child2      DB "child2", 0
Child3     Byte "child3"
Parent2 Byte "Parent2"
DragMode      DD FALSE

.Code

MainWndProcedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM

   Local tvinsert:TV_INSERTSTRUCT
   Local hBitmap:DWord
   Local tvhit:TV_HITTESTINFO

.If uMsg == WM_CREATE
   Invoke InitCommonControls
   Invoke ShowWindow, hWnd, SW_SHOWMAXIMIZED
   Invoke SendDlgItemMessage, hWnd, IDC_MAINWND_TREEVIEW1, TVM_SETBKCOLOR, 0, 00E1F0FFH

;---------- [Get the Imagelist] ----------

   Invoke ImageList_Create, 16, 16, ILC_COLOR16, 2, 10
   Mov hImageList, Eax
   Invoke LoadBitmap, hInstance, IDB_TREE
   Mov hBitmap, Eax
   Invoke ImageList_Add, hImageList, hBitmap, NULL
   Invoke DeleteObject, hBitmap
   Invoke SendDlgItemMessage, hWnd, IDC_MAINWND_TREEVIEW1, TVM_SETIMAGELIST, 0, hImageList

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


Invoke SendDlgItemMessage, hWnd, IDC_MAINWND_TREEVIEW1, TVM_INSERTITEM, 0, Addr tvinsert
      Mov hParent, Eax
      mov tvinsert.hParent,eax
      Mov tvinsert.hInsertAfter, TVI_LAST
      mov tvinsert.item.pszText,offset Child1
      

Invoke SendDlgItemMessage, hWnd, IDC_MAINWND_TREEVIEW1, TVM_INSERTITEM, 0, Addr tvinsert
      Mov tvinsert.hParent, Eax
      Mov tvinsert.hInsertAfter, TVI_LAST
      Mov tvinsert.item.pszText, Offset Child2

Invoke SendDlgItemMessage, hWnd, IDC_MAINWND_TREEVIEW1, TVM_INSERTITEM, 0, Addr tvinsert


            .ElseIf uMsg == WM_CLOSE
      Invoke IsModal, hWnd
      .If Eax
         Invoke EndModal, hWnd, IDCANCEL
         Return TRUE
      .EndIf
   .EndIf
   Return FALSE
MainWndProcedure EndP

MainWndTreeView1 Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM




   Return FALSE

MainWndTreeView1 EndP





Ramon Sala

Hi devilhorse,

Your hInstance variable has no value, so that's the reason why resources cannot be loaded. You should assign the application instance value to the hInstance variable before trying to load any resource, but it is not necessary as Easy Code has the App object which returns different values (see the Easy Code help). For example, the App.Instance returns the instance value. Just replace hInstance with App.Instance along your code and the problem is solved.

Thanks for using Easy Code,

Ramon
Greetings from Catalonia