Assembly code snippets

Back to the snippets overview

Details

TitleCheckboxes in a listview control
AuthorThomas
Submitted by:Thomas
Date added:2002-03-23 14:18:13
Date modified:2002-03-23 14:18:13

Comments

This snippet describes how to add checkboxes to a listview control. Checkboxes can be added by using an extended style and state images. Old versions of comctl32.dll may not support this style.

Snippet

After you created the listview, set the extended style. I use the following code,
as directly specifying dwExStyle did not work for me:

---
; Set checkboxes extended style
invoke  SendMessage, hListView,LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_CHECKBOXES
---

When inserting items, you can set the initial state of the checkbox by settting the
state image index in the state member of the LV_ITEM structure.

---
; assumes tempItem is a LV_ITEM structure:
mov tempItem.stateMask, LVIS_STATEIMAGEMASK  ; you may want to set more bits here
mov tempItem.state,(INDEX SHL 12)
---
INDEX can be 0,1 or 2:
 0 = no checkbox
 1 = unchecked checkbox
 2 = checked checkbox