invoke sendmessage,hlist, lvm_insertcolumn, 1 ,addr lvc
the remaining code is simple. put the address of the label in psztext and the width in lx. then send lvm_insertcolumn message to the listview control, specifying the column number and the address of the structure.
when the columns are inserted, we can fill items in the listview control.
invoke fillfileinfo
fillfileinfo has the following code.
fillfileinfo proc uses edi
local finddata:win32_find_data
local fhandle:dword
invoke findfirstfile,addr filenamepattern,addr finddata
we call findfirstfile to obtain the information of the first file that matches the search criteria. findfirstfile has the following prototype:
findfirstfile proto pfilename:dword, pwin32_find_data:dword
pfilename is the address of the filename to search for. this string can contain wildcards. in our example, we use *.*, which amounts to search for all the files in the current folder.
pwin32_find_data is the address of the win32_find_data structure that will be filled with information about the file (if found).
this function returns invalid_handle_value in eax if no matching file is found. otherwise it returns a search handle that will be used in subsequent findnextfile calls.
.if eax!=invalid_handle_value
mov fhandle,eax
xor edi,edi
if a file is found, we store the search handle in a variable and then zero out edi which will be used as the index into the items (row number).
.while eax!=0
test finddata.dwfileattributes,file_attribute_directory
.if zero?
in this tutorial, i don't want to deal with the folders yet so i filter them out by checking dwfileattributes for files which have file_attribute_directory flag set. if they are found, i skip to call findnextfile.
invoke showfileinfo,edi, addr finddata
inc edi
.endif
invoke findnextfile,fhandle,addr finddata
.endw
we insert the name and size of the file into the listview control by calling showfileinfo function. then we increase the current row number in edi. lastly we proceed to call findnextfile to search for the next file in the current folder until findnextfile returns 0 (meaning no more file is found).
invoke findclose,fhandle
.endif
ret
fillfileinfo endp
when all files in the current folder are enumerated, we must close the search handle.
now let's look at the showfileinfo function. this function accepts two parameters, the index of the item (row number) and the address of win32_find_data structure.
showfileinfo proc uses edi row:dword, lpfind:dword
local lvi:lv_item
local buffer[20]:byte
mov edi,lpfind
assume edi:ptr win32_find_data
store the address of win32_find_data structure in edi.
mov lvi.imask,lvif_text+lvif_param
push row
pop lvi.iitem
mov lvi.isubitem,0
we will supply the label of the item and the value in lparam so we put lvif_text and lvif_param flags into imask. next we set the iitem to the row number passed to the function and since this is the main item, we must fillisubitem with 0 (column 0).
lea eax,[edi].cfilename
mov lvi.psztext,eax
push row
pop lvi.lparam
next we put the address of the label, in this case, the name of the file in win32_find_data structure, into psztext. because we will implement sorting in the listview control, we must fill lparam with a value. i choose to put the row number into this member so i can retrieve the item info by its index.
invoke sendmessage,hlist, lvm_insertitem,0, addr lvi
when all necessary fields in lv_item are filled, we send lvm_insertitem message to the listview control to insert the item into it.
mov lvi.imask,lvif_text
inc lvi.isubitem
invoke wsprintf,addr buffer, addr template,[edi].nfilesizelow
lea eax,buffer