News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Adding items and subitems for listview

Started by gman, February 06, 2016, 05:01:14 PM

Previous topic - Next topic

gman

Hi,

I have been trying to grapple with listview to do the following:

1.  include a checkbox
2.  add items and their subitems into listview.

I have been able to display the the header columns but each time when I try to add a new item (with the subitems) only the column 0 is seen and all other subitems will not show up. I did the following:

fillLvwFn             proc
LOCAL lvi:LV_ITEM
                                        ;*---- Set column 0 to display checkbox
                  mov    lvi.state,2000h                   ; set checkbox
                  mov    lvi.stateMask,2000h                ; set state mask
                  invoke    SendMessage,hlvwpins,LVM_SETITEMSTATE,5,addr lvi

                  mov    lvi.state,000h                      ; set checkbox
                  mov    lvi.stateMask,000h                   ; set state mask
                  mov      lvi.imask,LVIF_TEXT or LVIF_PARAM ; include state
                    mov    eax,[ddLvwRow]                      ; get row number
                  mov      lvi.iItem,eax                     ; write into item number
                  mov      lvi.lParam,eax                     ; row # as parameter value
                  mov    lvi.iSubItem,0                     ; column 0
                  mov    lvi.pszText,offset szPinNo            ; string
                  invoke    SendMessage,hlvwpins, LVM_INSERTITEM,0, addr lvi   ; insert

                  ;*----   Column 1 - port #   ----
                  mov    lvi.state,0
                  mov      lvi.imask,LVIF_TEXT                ; include state
                  inc    lvi.iSubItem                     ; increment subitem number
                  mov    lvi.pszText,offset szPortNo            ; string
                  invoke    SendMessage,hlvwpins, LVM_SETITEM,0, addr lvi   ; insert
                                       ret
fillLvwFn             endp

It seems I have a issue understanding how to use the states or imask properly. Can you help pinpoint what's wrong with my coding for above code?

Thank you
gman

TouEnMasm


don't use number to initialise state,there is constants beginning by LVIS_ who can be used.
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774733(v=vs.85).aspx
Fa is a musical note to play with CL

sinsi

Have you tried using LVITEM instead of LV_ITEM?
Quote from: MSDNThis structure supersedes the LV_ITEM structure.
Initialising the struc with 0's might also make a difference.

TouEnMasm

If you don't know which structure to use:
http://masm32.com/board/index.php?topic=563.msg4563#msg4563
use LVITEM and the header made the choice for you
Fa is a musical note to play with CL

gman

Thanks for all your replies. I am learning listview controls and from the information gleaned from mas32.com/board and other sites, this was what I have managed.

1.  In setting the checkbox for state field, is it better to use or instruction. Note that I used LVM_SETITEMSTATE and not LVM_INSERTITEM or LVM_SETITEM
2.  The first column state was initialized with LVIF_TEXT or LVIF_PARAM using LVM_INSERTITEM.

This was the information I can get so far from the internet. I was hoping maybe, you guys are the experts that you can pinpoint my error or an example for a reference that I can use. I can get the listview to work with Free Pascal, with the checkboxes and subsequent subitems without any problem and to edit any of the subitems as well. I was thinking I can do the same with masm32.

Can you help with a reference or example for me to take note? Whether I remove the mov   lvi.state,0 or not, no subitems appear. If I do not set the checkbox value in state, the checkbox will not appear. I used icztutes as my guide for listview but there was no example for checkboxes.

I am still stuck with LV_ITEM. I suppose I have to migrate to LVITEM. Thanks you guys for your help so far, and I appreciate your comments. .. gman

fearless

Probably something to do with ddLvwRow, if its not starting at 0, your going to see items and subitems not being added. Plus might be handy to have a subitem variable to place into iSubItem

gman

Thanks fearless, 'for going where no one did'.

I set ddLvwRow (for Item) and another variable ddLvwCol for the SubItem as you suggested. The other subitem now shows up.

Question, what is the difference between

inc   lvi.SubItem

with

mov  eax,[ddLvwCol]
mov lvi.SubItem,eax

I presume they work in the same manner unless the assembler could not increment for a record structure.

Thanks very much for your help. .. gman


fearless

Its more to ensure that you know for certain that incrementing the iSubItem wouldnt be adding to an unknown value - as in basically assuming it would be correct. Using the variable or parameter (whichever) allows you to have more control of what you think it is going into iSubItem and for readability and for tracing errors - either in a debugger or using donkeys vKim debug output (http://www.masmforum.com/board/index.php?topic=16317.0)

I use that a lot in my projects and is very helpful in figuring out what is actually being used. I recommend downloading it and using it, it will help you in the long run.

Its pretty simple to use. The download is at the very end of that thread above. Here is the direct link to the library package: http://www.masmforum.com/board/index.php?action=dlattach;topic=16317.0;id=10334 - altho i think that version doesnt have the dbgwin.exe already compiled - so if anyone needs it ive uploaded an old package here: https://www.dropbox.com/s/84bf33xquh1j2jq/Debug3264.zip?dl=0

Copy debug32.inc to your include folder, debug32.lib to your lib folder and dbgwin.exe to your masm32 folder. Or wherever you want to suits for your environment.

I then use the following at the start of my projects:

.686
.MMX
.XMM
.model flat,stdcall
option casemap:none

include windows.inc
include kernel32.inc
include user32.inc
include gdi32.inc

includelib kernel32.lib
includelib user32.lib
includelib gdi32.lib

DEBUG32 EQU 1

IFDEF DEBUG32
    PRESERVEXMMREGS equ 1
    Includelib M:\Masm32\lib\Debug32.lib
    DBG32LIB equ 1
    DEBUGEXE textequ <'M:\Masm32\DbgWin.exe'>
    Include M:\Masm32\include\debug32.inc
ENDIF


Change any drive or path information above to match your own development environment. for example if you have everything on a C:\Dev\Masm folder (C:\Dev\Masm\bin, C:\Dev\Masm\lib, C:\Dev\Masm\bin) then you might have this:

IFDEF DEBUG32
    PRESERVEXMMREGS equ 1
    Includelib C:\Dev\Masm\lib\Debug32.lib
    DBG32LIB equ 1
    DEBUGEXE textequ <'C:\Dev\Masm\DbgWin.exe'>
    Include C:\Dev\Masm\include\debug32.inc
ENDIF


include any other libs and include files as normal. When you want to disable the debug part, just comment out the line: DEBUG32 EQU 1, the debug library and include file wont to be included when compiling then, due to the IFDEF DEBUG32 not resolving to a defined equate.

Then in your code you can happily use some of the debug macros. The easiest one to use is PrintDec, i recommened surrounding the debug macros with IFDEF DEBUG32, again so they can be included or excluded when you leave the DEBUG32 EQU 1 uncommented or when you comment it out.

So an example of usage might be:

                  IFDEF DEBUG32
                       PrintDec ddLvwRow                  ; print out value of ddLvwRow to dbgwin's window
                  ENDIF
                  mov    eax, ddLvwRow                    ; get row number
                  mov    lvi.iItem,eax                    ; write into item number
                  mov    lvi.lParam,eax                   ; row # as parameter value
                  mov    eax, ddLvwRowSubItem
                  mov    lvi.iSubItem, eax
                  IFDEF DEBUG32
                       PrintDec ddLvwRow                  ; print out again, why not
                       PrintDec ddLvwRowSubItem           ; print out subitem - assuming we have a variable or parameter called ddLvwRowSubItem?
                       PrintDec lvi.iItem                 ; print out whats stored in iItem
                       PrintDec lvi.iSubitem              ; print out whts stored in iSubItem
                  ENDIF
                  mov    lvi.pszText,offset szPinNo       ; string


hope that helps you

gman

Hi fearless,

Thank you very much for the help to use the debugger. I have tried using it and I have never been able to view it in source listing mode (like in codeview - debugger (MS)). I will try this out.

The issue that I had in not able to display the items/subitems is due to the subitem counter. I could not determine what was wrong because I was not able to debug my code.

Thank you again. Appreciate your help and now I can use debugger to check out my problem. .. gman