so after the listview control is created, you should insert one or more columns into it. columns are not necessary if you don't plan to switch the listview control into report view. in order to insert a column, you need to create a lv_column structure, fill it with necessary information, specify the column number and then send the structure to the listview control with lvm_insertcolumn message.
local lvc:lv_column
mov lvc.imask,lvcf_text+lvcf_width
mov lvc.psztext,offset heading1
mov lvc.lx,150
invoke sendmessage,hlist, lvm_insertcolumn,0,addr lvc
the above code snippet demonstrates the process. it specifies the column header text and its width then send lvm_insertcolumn message to the listview control. it's that simple.
items and subitems
items are the main entries in the listview control. in views other than report view, you will only see items in the listview control. subitems are details of the items. an item may have one or more associated subitems. for example, if the item is the name of a file, then you can have the file attributes, its size, the date of file creation as subitems. in report view, the leftmost column contains items and the remaining columns contain subitems. you can think of an item and its subitems as a database record. the item is the primary key of the record and the subitems are fields in the record.
at the bare minimum, you need some items in your listview control: subitems are not necessary. however, if you want to give the user more information about the items, you can associate items with subitems so the user can see the details in the report view.
you insert an item into a listview control by sending lvm_insertitem message to it. you also need to pass the address of an lv_item structure to it in lparam. lv_item has the following definition:
lv_item struct
imask dd ?
iitem dd ?
isubitem dd ?
state dd ?
statemask dd ?
psztext dd ?
cchtextmax dd ?
iimage dd ?
lparam dd ?
iindent dd ?
lv_item ends
| field name | meanings |
|---|---|
| imask | a collection of flags indicating which members in this structure are valid for this call. in general, this field is similar to imask member of lv_column above. check your win32 api reference for more detail on the available flags. |
| iitem | the index of the item this structure refers to. the index is zero-based. you can think of this field as containing the "row" number of a table. |
| isubitem | the index of the subitem associated with the item specified by iitem above. you can think of this field as containing the "column" of a table. for example, if you want to insert an item into a newly created listview control, the value in iitem would be 0 (because this item is the first one), and the value in isubitem would also be 0 (we want to insert the item into the first column). if you want to specify a subitem associated with this item, the iitem would be the index of the item you want to associate with (in the above example, it's 0), the isubitem would be 1 or greater, depending on which column you want to insert the subitem into. for example, if your listview control has 4 columns, the first column will contain the items. the remaining 3 columns are for subitems. if you want to insert a subitem into the 4th column, you need to specify the value 3 in isubitem. |
| state |
this member contains flags that reflect the status of the item. the state of an item can change because of the user's actions or it can be modified by our program. the state includes whether the item has the focus/is hilited/is selected for cut operation/is selected. in addition to the state flags, it can also contains one-based index into the overlay image/state image for use by the item. |
| statemask | since the state member above can contain the state flags, overlay image index , and state image index, we need to tell windows which value we want to set or retrieve. the value in this field is for such use. |
| psztext | the address of an asciiz string that will be used as the label of the item in the case we want to set/insert the item. in the case that we use this structure to retrieve the item's property, this member must contain the address of a buffer that will be filled with the label of the item. |
| cchtextmax | this field is used only when you use this structure to receive info about an item. in this case, this field contains the size in bytes of the buffer specified in psztext above. |
| iimage | the index into the imagelist containing the icons for the listview control. this index points to the icon to be used with this item. |
| lparam | a user-defined value that will be used when you sort items in the listview control. in short, when you tell the listview control to sort the items, the listview control will compare the items in pairs. it will send the lparam values of both items to you so you can decide which of the two should be listed first. if you're still hazy about this, don't worry. you'll learn more about sorting later. |