flat assembler
Message board for the users of flat assembler.
Index
> Windows > [solved] TreeView insert item trouble |
Author |
|
Teehee 09 Jan 2010, 15:26
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 |
|||
09 Jan 2010, 15:26 |
|
Teehee 09 Jan 2010, 19:51
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 |
|||
09 Jan 2010, 19:51 |
|
ManOfSteel 09 Jan 2010, 21:49
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 |
|||
09 Jan 2010, 21:49 |
|
Teehee 14 Jan 2010, 16:22
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)
|
||||||||||
14 Jan 2010, 16:22 |
|
baldr 14 Jan 2010, 17:20
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. |
|||
14 Jan 2010, 17:20 |
|
Teehee 14 Jan 2010, 17:24
omg, baldr... that's it! Thanks!
I always confuse that! |
|||
14 Jan 2010, 17:24 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.