Seems that the above combination doesn't work although I cannot find any docs about that. If I set the extended style LVS_EX_CHECKBOXES the listview frees a little space on the left (report view) for the image to display as it should be, but I never get any request LVN_GETDISPINFO with bit LVIF_STATE set. So no images are drawn.

Setting images with LVN_GETDISPINFO/LVIF_IMAGE works, but has some limitations I dont want to accept yet.

Any ideas?
Posted on 2002-07-08 08:27:03 by japheth
Did you set the ex. style with ListView_SetExtendedListViewStyle? I've had problems with setting it as extended style for CreateWindowEx..

Thomas
Posted on 2002-07-08 08:35:47 by Thomas
Hi Thomas,

yes I set the extended style with ListView_SetExtendedListViewStyle.

In fact, my app was working fine until I decided to switch to virtual listviews because of speed. Yes, it is faster now, but seems I have to "swallow some toads" (hope this is understandable - the other disadvantage of virtual listviews is sorting must be done by hand).
Posted on 2002-07-08 11:18:44 by japheth
I've never heard the phrase 'swallow some toads', but it sounds like a good way to describe virtual listviews ;-) I lost my checkboxes too! I don't know if this is what you tried, but I think you need to create a State image list with INDEXTOSTATEIMAGEMASK of 2 checkbox icon images, I assume to replace the ones normally created by the control with the LVS_EX_CHECKBOXES style.


LVS_EX_CHECKBOXES
Enables check boxes for items in a list-view control. When set to this style, the control creates and sets a state image list with two images using DrawFrameControl. State image 1 is the unchecked box, and state image 2 is the checked box. Setting the state image to zero removes the check box altogether.


Once you've created the image list hopefully you can set the state of the checkboxes with
;------------------------------------------
; (INDEX SHL 12) INDEX can be 0,1 or 2:
;0 = no checkbox
;1 = unchecked checkbox
;2 = checked checkbox
mov lvi.stateMask, LVIS_STATEIMAGEMASK
mov lvi.state,(2 SHL 12)
invoke SendMessage, _hListView, LVM_SETITEMSTATE, lvi.iItem, ADDR lvi.LV_ITEM
;---------------------------------------------

I don't know if the checkboxes will still respond as normal to a mouse click and you can use BN_CLICKED to handle the users selection, this might be another toad to swallow...


btw Japheth, thanks for the suggestion of using NM_RCLICK to handle the popup menu on a virtual listview, it works nicely. I had tried it but rejected it initially because it doesn't return the mouse hot spot like WM_CONTEXT does, but I got it with this



.if [edi].hwndFrom == eax && [edi].code == NM_RCLICK

invoke GetMessagePos ; returns cursor position in screen coordinates
mov ebx, eax ; x/y pos of window
and ebx, 0000ffffh ; ebx = LOWORD(lparam) = x pos
shr eax, 16 ; eax = HIWORD(lparam) = y pos

invoke TrackPopupMenu, hPopupMenu, 0, ebx, eax, 0, hMainWindow, NULL



The other problem with how to ensure that WM_NOTIFY is called for every item in the listview rather than just for the on-screen items when RedrawWindow is called, can be solved with sending an SB_PAGEDOWN message for the number of pages you have.



;--------------------------------------------------------
; WM_NOTIFY with the LVN_GETDISPINFO notification code
; will be called for each item in listview in response to the scrolling.
;--------------------------------------------------------
; sif SCROLLINFO <sizeof SCROLLINFO>

invoke GetScrollInfo, hListView, SB_VERT, addr sif

mov edi, sif.nPage ; number of rows per page (indexed to 0)
mov eax, sif.nMax ; maximum scrolling position = number of rows (indexed to 0)
xor edx, edx
div edi ; rows / (rows/page)

mov edi, eax ; whole number result of division = # pages to scroll
mov esi, 0

.while esi < edi

invoke SendMessage, hListView, WM_VSCROLL, SB_PAGEDOWN, NULL
inc esi
.endw


The only problem with this is the last item on a page becomes the first item on the next page, so you end up with a few duplicate WM_NOTIFY messages you may have to filter depending on what you're doing.


You said setting images with LVN_GETDISPINFO/LVIF_IMAGE works but has some limitations you dont want to accept yet. What kind of limitations?

Kayaker
Posted on 2002-07-08 20:12:12 by Kayaker
Kayaker,

thanks for the reply. I can confirm I've done the checkbox stuff as you have described in your post. Although I think that sending message LVM_SETITEMSTATE for image states is useless, because windows keeps track of selection and focus state only in virtual listviews (tried it anywhere).

One limitation of using LVN_GETDISPINFO/LVIF_IMAGE are IMO that once you have set an image for an item windows will reserve space for it on the report view and until now I haven't found a way to get rid of it (except for recreating the listview window). I wanted to dynamically show/hide the images, which was easy with LVS_EX_CHECKBOXES style.

japheth
Posted on 2002-07-09 02:35:01 by japheth