mov eax,edi
do likewise with the value in lparam2. when we have the sizes of the two files, we can then compare them.
the rule of the comparison function is as follows:
- if the first item should precede the other, you must return a negative value in eax
- if the second item should precede the first one, you must return a positive value in eax
- if both items are equal, you must return zero in eax.
in this case, we want to sort the items according to their sizes in ascending order. thus we can simply subtract the size of the first item with that of the second one and return the result in eax.
.elseif sorttype==3
mov lvi.isubitem,0
invoke sendmessage,hlist,lvm_getitemtext,lparam1,addr lvi
invoke lstrcpy,addr buffer1,addr buffer
invoke sendmessage,hlist,lvm_getitemtext,lparam2,addr lvi
invoke lstrcmpi,addr buffer1,addr buffer
in case the user clicks the filename column, we must compare the names of the files. we first obtain the filenames and then compare them with lstrcmpi function. we can return the return value of lstrcmpi without any modification since it also uses the same rule of comparison, eg. negative value in eax if the first string is less than the second string.
when the items were sorted, we need to update the lparam values of all items to reflect the new indexes by calling updatelparam function.
invoke updatelparam
mov sizesortorder,1
this function simply enumerates all items in the listview control and updates the values in lparam with the new indexes. we need to do this else the next sort will not work as expected because our assumption is that the value in lparam is the index of the item.
.elseif [edi].code==nm_dblclk
invoke showcurrentfocus
.endif
when the user double-clicks at an item, we want to display a message box with the label of the item on it. we must check if the code in nmhdr is nm_dblclk. if it is, we can proceed to obtain the label and display it in a message box.
showcurrentfocus proc
local lvi:lv_item
local buffer[256]:byte
invoke sendmessage,hlist,lvm_getnextitem,-1, lvni_focused
how do we know which item is double-clicked? when an item is clicked or double-clicked, its state is set to "focused". even if many items are hilited (selected), only one of them has got the focus. our job than is to find the item that has the focus. we do this by sending lvm_getnextitem message to the listview control, specifying the desired state in lparam. -1 in wparam means search all items. the index of the item is returned in eax.
mov lvi.iitem,eax
mov lvi.isubitem,0
mov lvi.imask,lvif_text
lea eax,buffer
mov lvi.psztext,eax
mov lvi.cchtextmax,256