flat assembler
Message board for the users of flat assembler.

Index > Windows > TreeView

Author
Thread Post new topic Reply to topic
allan



Joined: 10 Sep 2005
Posts: 8
allan
I need some code for a Tree View. I wish to be able to right click a label in a Treeview and selec t popup menu to say Move Label Up - so that is is above its current sibling.

Any example code appreciated?
Post 14 Mar 2012, 23:22
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Ok. I wanted to help you by giving you the whole code but I'm tired and I think I've helped you enough.

All you have to do is swap the items using the indices in lparam structure member at offset 9.

Here's the code 98% done for you

Code:
;
; typedef 2012
;
;

format pe gui 4.0

include 'win32ax.inc'

entry   main

section '.code' code readable executable writeable

oldProc dd 0

msg     MSG
pt      POINT

proc    DlgProc hwnd, msg, wparam, lparam

        push    ebx   edi  esi

        cmp     [msg],  WM_NOTIFY
        je      .notify

        cmp     [msg],  WM_COMMAND
        je      .wmcmd

        cmp     [msg],  WM_CLOSE
        jne      pass

        push     0
        call     [ExitProcess]
.notify:
        mov      eax,   [lparam]
        mov      eax,   [eax+NMHDR.code]
        cmp       eax,   NM_RCLICK
        je       .right_click

        jmp     pass
.right_click:
        ;       open menu here
        push    pt
        call    [GetCursorPos]

        push    NULL
        push    [hwnd]  ; this window
        push    0       ; reserved
        push    [pt.y]     ; y
        push    [pt.x]     ; x
        push    TPM_CENTERALIGN + TPM_VCENTERALIGN + TPM_LEFTBUTTON
        push    [hMenu]
        call    [TrackPopupMenu]

        jmp     pass

.wmcmd:
        cmp     [wparam],       $120
        jne     pass

        invoke   GetDlgItem,[hwnd],100
        mov      ebx,   eax

        invoke   SendMessage,eax,TVM_GETNEXTITEM,TVGN_CARET,0

        cmp      eax, 0
        jz       pass   ;        returned null

        mov      dword[tempTvItem+(4*4)],  selected_item_text
        mov      dword[tempTvItem+(1*4)],  eax   ; handle to selected item

        invoke   SendMessage,ebx,TVM_GETITEM,0,tempTvItem

        mov      eax,   [tempTvItem+(9*4)]   ; selected index

        cinvoke wsprintfA,buff,fmt,eax

        invoke  MessageBox,[hwnd],buff,selected_item_text,MB_OK

pass:
        push    [lparam]
        push    [wparam]
        push    [msg]
        push    [hwnd]
        push    [oldProc]
        call    [CallWindowProc]

        pop     esi   edi  ebx

        ret
endp

buff db 101 dup(0)
fmt  db 'index: %d',0

icc:virtual at $$
        dd 8
        dd ICC_WIN95_CLASSES
end virtual

text2   db      'Tree view root item 2',0
text3   db      'Tree view root item 3',0
text    db      'Tree view root item 1',0
text_len = $ - text

selected_item_text  db text_len dup(0),0

selected_item_text1 db text_len dup(0),0

tempTvItem:
              dd   TVIF_TEXT + TVIF_PARAM;UINT      mask;    get text
              dd   0         ;HTREEITEM hItem;
              dd   0         ;UINT      state;
              dd   0         ;UINT      stateMask;
              dd   0         ;LPTSTR    pszText;
              dd   text_len  ;int       cchTextMax;  we just use the same length
              dd   0         ;int       iImage;
              dd   0         ;int       iSelectedImage;
              dd   0         ;int       cChildren;
              dd   0         ;LPARAM    lParam;


tvInsertStruct:          ; TVINSERTITEMSTRUCT
              dd   TVI_ROOT        ;hParent
              dd   TVI_ROOT        ;hInsertAfter
tvItem0:       ;  tree view item structure
              dd   TVIF_TEXT + TVIF_PARAM ;UINT      mask;
              dd   TVI_ROOT         ;HTREEITEM hItem;
              dd   0         ;UINT      state;
              dd   0         ;UINT      stateMask;
              dd   text      ;LPTSTR    pszText;
              dd   text_len  ;int       cchTextMax;
              dd   0         ;int       iImage;
              dd   0         ;int       iSelectedImage;
              dd   0         ;int       cChildren;
              dd   0         ;LPARAM    lParam;   We use these as indices


tvInsertStruct2:          ; TVINSERTITEMSTRUCT
              dd   0                   ;hParent
              dd   TVI_SORT            ;hInsertAfter
tvItem1:       ; tree view item structure
              dd   TVIF_TEXT + TVIF_PARAM;UINT      mask;
              dd   0             ;HTREEITEM hItem;
              dd   0         ;UINT      state;
              dd   0         ;UINT      stateMask;
              dd   text2      ;LPTSTR    pszText;
              dd   text_len  ;int       cchTextMax;
              dd   0         ;int       iImage;
              dd   0         ;int       iSelectedImage;
              dd   0         ;int       cChildren;
              dd   1         ;LPARAM    lParam;

tvInsertStruct3:             ; TVINSERTITEMSTRUCT
              dd   0         ;hParent
              dd   TVI_SORT        ;hInsertAfter
tvItem2:       ;  tree view item structure
              dd   TVIF_TEXT + TVIF_PARAM  ;UINT      mask;
              dd   TVI_ROOT         ;HTREEITEM hItem;
              dd   0         ;UINT      state;
              dd   0         ;UINT      stateMask;
              dd   text3     ;LPTSTR    pszText;
              dd   text_len  ;int       cchTextMax;
              dd   0         ;int       iImage;
              dd   0         ;int       iSelectedImage;
              dd   0         ;int       cChildren;
              dd   2         ;LPARAM    lParam;

hMenu         dd   0

menu_label    db   'Move up',0
len           =    $ - menu_label

main:
     push       ebp
     mov        ebp,    esp

     ; create our context menu
     call       [CreatePopupMenu]
     mov        [hMenu],       eax
     mov        ebx,           eax

     push       menu_label
     push       $120
     push       MF_STRING
     push       ebx
     call       [AppendMenu]

     push        icc
     call        [InitCommonControlsEx]

     push       0
     call       [GetModuleHandle]

     mov        ebx,    eax

    invoke CreateWindowEx,0,1000000000000010b,'Tree view stuff',WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_VISIBLE,400,100,400,400,0,0,ebx,0

    push        eax

    push        DlgProc
    push        GWL_WNDPROC
    push        eax
    call        [SetWindowLong]
    mov         [oldProc], eax

    pop         eax

    invoke      CreateWindowEx,0,'SysTreeView32',0,WS_CHILD+WS_VISIBLE+WS_BORDER,2,2,200,300,eax,100,ebx,0

    mov          ebx,   eax

                                                                   ; Insert some items. Root nodes only
    invoke       SendMessage,ebx,TVM_INSERTITEM,0,tvInsertStruct
    mov          dword[tvItem0+(1*4)],     eax        ;

    invoke       SendMessage,ebx,TVM_INSERTITEM,0,tvInsertStruct2
    mov          dword[tvItem1+(1*4)],     eax        ;

    invoke       SendMessage,ebx,TVM_INSERTITEM,0,tvInsertStruct3
    mov          dword[tvItem2+(1*4)],     eax        ;

_loop_:
    push        0
    push        0
    push        0
    push        msg
    call        [GetMessage]
    and         eax, -1
    jz          _quit   ;      -1 an error

    push        msg
    call        [TranslateMessage]

    push        msg
    call        [DispatchMessage]

    jmp         _loop_

_quit:
    mov         esp,    ebp
    pop         ebp
    ret


section '.idata' import data readable

library user32,'user32.dll', comctl32,'comctl32.dll',kernel32,'kernel32.dll'

include 'api/user32.inc'
include 'api/comctl32.inc'
include 'api/kernel32.inc'
    


Good luck and have fun.

EDIT: Link to API http://msdn.microsoft.com/en-us/library/bb773622(v=vs.85).aspx
Post 15 Mar 2012, 09:36
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek
Thanks, typedef. I was just thinking of investigating the TreeView. Nice asm-style, btw.
Post 16 Mar 2012, 20:38
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
You are welcome
Post 17 Mar 2012, 06:57
View user's profile Send private message Reply with quote
allan



Joined: 10 Sep 2005
Posts: 8
allan
Indexing lParam works when using TVM_SORTCHILDRENCB after.
Post 20 Mar 2012, 22:23
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
It works without that too. The lParam is just a user defined pointer. You can make it point to all kinds of data. i.e Linked lists, strings and what not. It doesn't matter if they are sorted or not as long as you know the index yourself(in your code).
Post 21 Mar 2012, 01:03
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek
This is a TreeControl Example, rewritten on FASM from C tutorial (found on codeproject), which, in turn, was written using Iczelion tutor.

Code is a bit messy, didn't optimize it.


Description: Tree Control example
Download
Filename: TreeCntrl.zip
Filesize: 13.19 KB
Downloaded: 191 Time(s)



Last edited by bzdashek on 01 Apr 2012, 16:02; edited 1 time in total
Post 31 Mar 2012, 12:42
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. Also on YouTube, Twitter.

Website powered by rwasa.