News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Listview Count checked item

Started by ragdog, October 14, 2010, 10:14:58 PM

Previous topic - Next topic

ragdog

Hi

I Try for my listview with checkbox a counter
For count the checked item



.const
LVIS_CHECKED      equ 2000h
LVIS_UNCHECKED    equ 1000h

.elseif uMsg==WM_NOTIFY
            invoke OnNotify,hWnd,wParam,lParam


OnNotify proc uses edi esi ebx hWnd:HWND,wParam:dword, lParam:dword
LOCAL lvi :LV_ITEM
LOCAL ItemCount :DWORD
LOCAL   hItem :DWORD

       mov   edi,lParam
    assume   edi:ptr NMHDR
   mov   eax,[edi].hwndFrom
 
.if eax==hList
.if [edi].code == LVN_ITEMCHANGED
             invoke    SendMessage, hList, LVM_GETITEMCOUNT, 0, 0
       .if eax!=0
mov ItemCount,eax
xor ebx, ebx

.while ebx<ItemCount
      mov lvi.iItem, ebx
                   invoke    SendMessage, hList, LVM_GETITEMSTATE, ebx, LVIS_STATEIMAGEMASK
                   .if eax==LVIS_CHECKED    ; If checked item
                       invoke    MessageBox,0,0,0,MB_OK
                    .endif
                    inc    ebx
            .endw
     .endif
       .endif
    .endif
    assume edi: nothing
   ret
OnNotify endp



Thanks in forward

Tedd

This isn't correct: .if eax==LVIS_CHECKED

The item state is a set of state-flags, and more than one may be set, so you can't just compare against a single value. You need to check only the bits you're interested in.


test eax,LVIS_CHECKED
.if (!ZERO?)
    ;item is checked
.else
    ;item not checked
.endif

No snowflake in an avalanche feels responsible.

ragdog

#2
Thanks for your reply

invoke    SendMessage, hList, LVM_GETITEMSTATE, ebx, LVIS_STATEIMAGEMASK
The return value is 1000 for item not checked and 2000 for checked

Ok i try your function

Here is my new code this works it must only add a counter for how many items is checked ::)
must i add a check for if item clicked or anything?


OnNotify proc uses edi esi ebx hWnd:HWND,wParam:dword, lParam:dword
LOCAL lvi :LV_ITEM
LOCAL ItemCount :DWORD
LOCAL   hItem :DWORD

    push ebx
    mov ebx,lParam
    .if [ebx].NMHDR.idFrom==1001
  .if [ebx].NMHDR.code==LVN_ITEMCHANGED
           invoke    SendMessage, hList,LVM_GETITEMSTATE,[ebx].NMLISTVIEW.iItem,LVIS_STATEIMAGEMASK
                 test    eax,LVIS_CHECKED
                 .if (!ZERO?)
                        ;item checked
                       inc SelectCnt
                       invoke wsprintf,addr  hItem,CTEXT ("%01u/32"),SelectCnt
                       invoke SetDlgItemText,hWnd,1005,addr  hItem
                    .else
                         ;item not checked
                         dec SelectCnt
                       invoke wsprintf,addr  hItem,CTEXT ("%01u/32"),SelectCnt
                       invoke SetDlgItemText,hWnd,1005,addr  hItem
                  .endif
       .endif
    .endif
    assume edi: nothing
   ret
OnNotify endp