flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved] TreeView insert item trouble

Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
this is my routine:
Code:
.Insert:
                mov     [tvi.mask],TVIF_TEXT
                mov     [tvi.pszText],'test'
                mov     [tvi.cchTextMax],4

                mov     [tvins.hParent],TVI_ROOT
                mov     [tvins.hInsertAfter],TVI_ROOT
                mov     eax,[tvi]
                mov     [tvins.item],eax
                invoke  SendMessage,[hTreeView],TVM_INSERTITEM,0,tvins
             ret    

Whats wrong? The item seems inserted, but i can't see the text.

_________________
Sorry if bad english.


Last edited by Teehee on 14 Jan 2010, 17:25; edited 2 times in total
Post 08 Jan 2010, 21:51
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
Here a compilable code to help you help me:
Code:
; Template for program using standard Win32 headers

format PE GUI 4.0
entry start

include 'win32ax.inc'

section '.text' code readable executable

  start:
        sub     esp, sizeof.INITCOMMONCONTROLSEX
        mov     dword [esp+INITCOMMONCONTROLSEX.dwSize],sizeof.INITCOMMONCONTROLSEX
        mov     dword [esp+INITCOMMONCONTROLSEX.dwICC],ICC_TREEVIEW_CLASSES
        invoke  InitCommonControlsEx,esp
        add     esp, sizeof.INITCOMMONCONTROLSEX

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc
        test    eax,eax
        jz      error

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,250,300,NULL,NULL,[wc.hInstance],NULL
        test    eax,eax
        jz      error

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        cmp     eax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
        cmp     [wmsg],WM_CREATE
        je      .wmcreate
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
        jmp     .finish

  ;
  ; Create TreeView ---------------------------------------------
  ;

  .wmcreate:
                invoke  GetClientRect,[hwnd],rect
                invoke  CreateWindowEx,0,TREEVIEW_CLASS,0,\
                        WS_VISIBLE + WS_CHILD +\
                        TVS_HASLINES + TVS_HASBUTTONS + TVS_EDITLABELS,\
                        0,0,[rect.right],[rect.bottom],[hwnd],NULL,[wc.hInstance],NULL
                mov     [hTreeView],eax
                call .Insert

        xor     eax,eax
        jmp     .finish

  .Insert:
                mov     [tvi.mask],TVIF_TEXT
                mov     [tvi.pszText],txt
                mov     [tvi.cchTextMax],4

                mov     [tvins.hParent],TVI_ROOT
                mov     [tvins.hInsertAfter],TVI_ROOT
                mov     eax,[tvi]
                mov     [tvins.item],eax
                invoke  SendMessage,[hTreeView],TVM_INSERTITEM,0,tvins
             ret

  .finish:
        pop     edi esi ebx
        ret
endp

section '.data' data readable writeable
  struct TVITEM
    mask           dd ?
    hItem          dd ?
    state          dd ?
    stateMask      dd ?
    pszText        dd ?
    cchTextMax     dd ?
    iImage         dd ?
    iSelectedImage dd ?
    cChildren      dd ?
    lParam         dd ?
    ;iIntegral      dd ?  ; EX
    ;uStateEx       dd ?
    ;hwnd           dd ?
    ;iExpandedImage dd ?
    ;               dd ?
  ends

  struct TVINSERTSTRUCT
         hParent      dd ?
         hInsertAfter dd ?
         item         TVITEM
  ends

  tvins  TVINSERTSTRUCT
  tvi    TVITEM

  hTreeView dd ?

  txt db 'test',0

  ;
  ; main Wnd
  ;

  _class TCHAR 'TreeViewTest',0
  _title TCHAR 'TreeView test',0
  _error TCHAR 'Startup failed.',0

  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

  msg MSG
  rect RECT

section '.idata' import data readable writeable

    library kernel32,'KERNEL32.DLL', user32,'USER32.DLL', comctl32,'COMCTL32.DLL', gdi32,'GDI32.DLL'
    include 'API\KERNEL32.INC'
    include 'API\USER32.INC'
    include 'API\COMCTL32.INC'
    include 'API\GDI32.INC'    


Please help, the Treeview does not show the item text.
- MSDN insstruct
Post 09 Jan 2010, 15:26
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
This does not work:
Code:
.Insert: 
                mov     [tvi.mask],TVIF_TEXT 
                mov     [tvi.pszText],txt

                mov     [tvins.hParent],TVI_ROOT 
                mov     [tvins.hInsertAfter],TVI_ROOT 
                mov     eax,[tvi] 
                mov     [tvins.item],eax 
                invoke  SendMessage,[hTreeView],TVM_INSERTITEM,0,tvins 
             ret    

This work:
Code:
.Insert:
                mov     [tvins.hParent],TVI_ROOT
                mov     [tvins.hInsertAfter],TVI_ROOT
                mov     [tvins.item.mask],TVIF_TEXT
                mov     [tvins.item.pszText],txt
                invoke  SendMessage,[hTreeView],TVM_INSERTITEM,0,tvins
             ret    
Confused
Post 09 Jan 2010, 19:51
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
The second one is how you're supposed to create a root item. The first one is missing a mov [tvins.item.pszText],txt.

Here's a better example that'll create a root item and 2 subitems:
Code:
mov [tvins.hParent],TVI_ROOT
mov [tvins.hInsertAfter],TVI_ROOT 
mov [tvins.item.mask],TVIF_TEXT
mov [tvins.item.pszText],txt
invoke SendMessage,[hTreeView],TVM_INSERTITEM,0,tvins

mov [tvins.hParent],eax 
mov [tvins.hInsertAfter],TVI_LAST 
mov [tvins.item.pszText],subtxt1
invoke SendMessage,[hTreeView],TVM_INSERTITEM,0,tvins

mov [tvins.item.pszText],subtxt2
invoke SendMessage,[hTreeView],TVM_INSERTITEM,0,tvins

mov [tvins.item.pszText],subtxt3
invoke SendMessage,[hTreeView],TVM_INSERTITEM,0,tvins
    
Post 09 Jan 2010, 21:49
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
I'm trying to get a item info. I tried many things but I can't.
This is what i'm doing:
Code:
invoke  SendMessage,[hTreeView],TVM_GETNEXTITEM,TVGN_CARET,0

mov     [tvis.item.mask],TVIF_TEXT
mov     [tvis.item.hItem],eax
mov     [tvis.item.pszText],buff ; buff db 255 dup 0
mov     [tvis.item.cchTextMax],255
invoke  SendMessage,[hTreeView],TVM_GETITEM,0,tvis.item
invoke  MessageBox,0,tvis.item.pszText,0,0 ; <- (see img)    


Description:
Filesize: 3.78 KB
Viewed: 1310 Time(s)

msg.JPG


Post 14 Jan 2010, 16:22
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Teehee,

tvis.item.pszText is an address of a pointer (to buff, which appears to be at 403169). You apparently need [tvis.item.pszText] for MessageBox.
Post 14 Jan 2010, 17:20
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
omg, baldr... that's it! Thanks! Smile
I always confuse that! Confused
Post 14 Jan 2010, 17:24
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.