mov lvi.psztext,eax
we will set the subitem associated with the item just inserted into the second column. a subitem can only have a label. thus we specify lvif_text in imask. then we specify the column that the subitem should reside in isubitem. in this case, we set it to 1 by incrementing isubitem. the label we will use is the size of the file. however, we must convert it to a string first by calling wsprintf. then we put the address of the string into psztext.
invoke sendmessage,hlist,lvm_setitem, 0,addr lvi
assume edi:nothing
ret
showfileinfo endp
when all necessary fields in lv_item are filled, we send lvm_setitem message to the listview control, passing to it the address of the lv_item structure. note that we use lvm_setitem, not lvm_insertitem because a subitem is considered as a property of an item. thus we *set* the property of the item, not inserting a new item.
when all items are inserted into the listview control, we set the text and background colors of the listview control.
rgb 255,255,255
invoke sendmessage,hlist,lvm_settextcolor,0,eax
rgb 0,0,0
invoke sendmessage,hlist,lvm_setbkcolor,0,eax
rgb 0,0,0
invoke sendmessage,hlist,lvm_settextbkcolor,0,eax
i use rgb macro to convert the red, green,blue values into eax and use it to specify the color we need. we set the foreground and background colors of the text with lvm_settextcolor and lvm_settextbkcolor messages. we set the background color of the listview control by sending lvm_setbkcolor message to the listview control.
invoke getmenu,hwnd
mov hmenu,eax
invoke checkmenuradioitem,hmenu,idm_icon,idm_list, idm_report,mf_checked
we will let the user chooses the views he wants via the menu. thus we must obtain the menu handle first. to help the user track the current view, we put a radio button system in our menu. the menu item that reflects the current view will be preceded by a radio button. that's why we call checkmenuradioitem. this function will put a radio button before a menu item.
note that we create the listview control with width and height equal to 0. it will be resized later whenever the parent window is resized. this way, we can ensure that the size of the listview control will always match that of the parent window. in our example, we want the listview control to fill the whole client area of the parent window.
.elseif umsg==wm_size
mov eax,lparam
mov edx,eax
and eax,0ffffh
shr edx,16
invoke movewindow,hlist, 0, 0, eax,edx,true
when the parent window receives wm_size message, the low word of lparam contains the new width of the client area and the high word the new height. then we call movewindow to resize the listview control to cover the whole client area of the parent window.
when the user selects a view in the menu. we must change the view in the listview control accordingly. we accomplish this by setting a new style in the listview control with setwindowlong.
.elseif umsg==wm_command
.if lparam==0
invoke getwindowlong,hlist,gwl_style
and eax,not lvs_typemask
the first thing we do is to obtain the current styles of the listview control. then we clear the old view style from the returned style flags. lvs_typemask is a constant that is the combined value of all 4 view style constants (lvs_icon+lvs_smallicon+lvs_list+lvs_report). thus when we perform and operation on the current style flags with the value "not lvs_typemask", it amounts to clearing away the current view style.
in designing the menu, i cheat a little. i use the view style constants as the menu ids.
idm_icon equ lvs_icon
idm_smallicon equ lvs_smallicon
idm_list equ lvs_list
idm_report equ lvs_report
thus when the parent window receives wm_command message, the desired view style is in the low word of wparam as the menu id.
mov edx,wparam
and edx,0ffffh
we have the desired view style in the low word of wparam. all we have to do is to zero out the high word.
push edx