Can't get a simple listview to work. Am I missing something obvious?
Posted on 2002-07-18 08:29:46 by grv575
You must use LVM_ADDITEM for the Subitem 0. For Subitem 1-n use LVM_INSERTITEM.
Before you add Subitem 1-n, create columns with LVM_INSERTCOLUMN.
Posted on 2002-07-18 09:11:58 by bazik
Don't see a LVM_ADDITEM on msdn :\
Posted on 2002-07-18 09:16:51 by grv575
Oh, I was using a listbox control and listview messages :)
Posted on 2002-07-18 09:32:13 by grv575
grv575,

try to add
mov lvi.cchTextMax,255

before call LVM_INSERTITEM

hope it help
hi B7
Posted on 2002-07-18 09:47:56 by Bit7
Hi!

Am at home now... here we go:



; .data
szListViewClass db "SysListView32", 0
szServer db "Server", 0
szPlayers db "Players", 0
szMission db "Mission", 0
szVersion db "Version", 0
szTimeLeft db "Time left", 0
szAddress db "Address", 0


; .code
invoke CreateWindowEx, WS_EX_CLIENTEDGE, addr szListViewClass, 0,
LVS_SHOWSELALWAYS or LVS_REPORT or WS_CHILD or WS_VISIBLE,
102, 0, 592, 200, hWin, 0, 400000h, 0
mov hListServer, eax

invoke SendMessage, hListServer, WM_SETFONT, hFont, 0
invoke SendMessage, hListServer, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT


mov lvc.imask, LVCF_TEXT or LVCF_WIDTH
mov lvc.lx, 210
mov lvc.pszText, offset szServer
invoke SendMessage, hListServer, LVM_INSERTCOLUMN, 0, addr lvc

mov lvc.imask, LVCF_TEXT or LVCF_WIDTH
mov lvc.lx, 50
mov lvc.pszText, offset szPlayers
invoke SendMessage, hListServer, LVM_INSERTCOLUMN, 1, addr lvc

mov lvc.imask, LVCF_TEXT or LVCF_WIDTH
mov lvc.lx, 120
mov lvc.pszText, offset szMission
invoke SendMessage, hListServer, LVM_INSERTCOLUMN, 2, addr lvc

mov lvc.imask, LVCF_TEXT or LVCF_WIDTH
mov lvc.lx, 50
mov lvc.pszText, offset szVersion
invoke SendMessage, hListServer, LVM_INSERTCOLUMN, 3, addr lvc

mov lvc.imask, LVCF_TEXT or LVCF_WIDTH
mov lvc.lx, 50
mov lvc.pszText, offset szTimeLeft
invoke SendMessage, hListServer, LVM_INSERTCOLUMN, 4, addr lvc

mov lvc.imask, LVCF_TEXT or LVCF_WIDTH
mov lvc.lx, 90
mov lvc.pszText, offset szAddress
invoke SendMessage, hListServer, LVM_INSERTCOLUMN, 5, addr lvc

.elseif uMsg == WM_NOTIFY
mov edi, lParam
assume edi:ptr NMHDR
mov eax, [edi].hwndFrom

.if eax == hListServer
.if [edi].code == NM_CLICK

invoke RtlZeroMemory, addr szBufferAddress, 32
invoke SendMessage, hListServer, LVM_GETNEXTITEM, -1, LVNI_FOCUSED
mov lvi.iItem, eax
mov lvi.iSubItem, 5
mov lvi.imask, LVIF_TEXT
mov eax, offset szBufferAddress
mov lvi.pszText, eax
mov lvi.cchTextMax, 32
invoke SendMessage, hListServer, LVM_GETITEM, 0, addr lvi
; szBufferAddress contains the value of subitem 5 now


And to add something (I had the wrong constant in mind ;) ):



AddServer proc pServer :DWORD, pPlayers :DWORD, pMission :DWORD, pVersion :DWORD, pTimeLeft :DWORD, pAddress :DWORD

invoke SendMessage, hListServer, LVM_GETITEMCOUNT, 0, 0
mov nCount, eax

mov lvi.imask, LVIF_TEXT
push nCount
pop lvi.iItem
mov lvi.iSubItem, 0
push pServer
pop lvi.pszText
invoke lstrlen, pServer
mov lvi.cchTextMax, eax
invoke SendMessage, hListServer, LVM_INSERTITEM, 0, addr lvi

mov lvi.imask, LVIF_TEXT
push nCount
pop lvi.iItem
mov lvi.iSubItem, 1
push pPlayers
pop lvi.pszText
invoke lstrlen, pPlayers
mov lvi.cchTextMax, eax
invoke SendMessage, hListServer, LVM_SETITEM, 0, addr lvi

mov lvi.imask, LVIF_TEXT
push nCount
pop lvi.iItem
mov lvi.iSubItem, 2
push pMission
pop lvi.pszText
invoke lstrlen, pMission
mov lvi.cchTextMax, eax
invoke SendMessage, hListServer, LVM_SETITEM, 0, addr lvi
[...]


Hope this helps!

bAZiK
Posted on 2002-07-18 10:06:14 by bazik