Seems that there is not too much out there...
Im playing with Iczelion tutorial 31... it seems to work pretty well but as this code is a little old ... would you recommend me to use it or there is better routines out here?
any info or code about auto size column headers?
When you create the listview (or later) youe one of the following flags, LVS_SORTASCENDING OR LVS_SORTDECENDING.
Paul
This sorts the listview the first time you add items, doesnt it?... Im using the iczelin code adapted to my program to sort the items when you click on a header. I realized that the "arrow" that some apps shows in the header is not something that windows does automatically.. any info about this?
Quote from: dacid on February 01, 2010, 07:37:53 PM
This sorts the listview the first time you add items, doesnt it?... Im using the iczelin code adapted to my program to sort the items when you click on a header. I realized that the "arrow" that some apps shows in the header is not something that windows does automatically.. any info about this?
You can add an icon to the column when you create it and you can modify the icon by sending the listview the message LVM_SETCOLUMN and set the LVCF_IMAGE to the new image in LVCOLUMN
You should really download the Platform SDK if you can it is a big help!
dacid,
Visit Donkey's Stable:
http://www.quickersoft.com/donkey/
Filled with knowledge and good code. Everything I needed for ListViews I got from his example. Click on "GoAsm Projects" and scroll down to ListView. The code is in GoAsm style, but it will be easy to change to your assembler of choice. I think it will do everything you asked for, except AutoSize the columns, and I would love to know how to do that.
Thanks again, Donkey!!
hth,
farrier
Quote from: farrier on February 01, 2010, 10:21:22 PM
I think it will do everything you asked for, except AutoSize the columns, and I would love to know how to do that.
Something like this?
; set column 1 width
invoke SendMessage, hLVMain, LVM_SETCOLUMNWIDTH, 0, LVSCW_AUTOSIZE
; column 2
invoke SendMessage, hLVMain, LVM_SETCOLUMNWIDTH, 1, LVSCW_AUTOSIZE_USEHEADER
yes, it works pretty well here. thanks gunner.
thanks farrier for the link.
Gunner,
Yes! The strange thing is that I use LVM_SETCOLUMNWIDTH many places in a few programs, but I never paid attention to the "Auto" features. Thanks!
farrier
Hey, another question :red .. Im using CreatePopupMenu and AppendMenu to create a right-click menu over the listview... Im triying the same way I do in the Window Menu:
MENUITEM "&Refresh\tF5",IDM_REFRESH
szRefresh "&Refresh\tF5",0
But it shows the "\tF5" instead of right-align the "F5" string.
Try szRefresh "&Refresh", 9, "F5", 0
thank you!
What msg sends the listview to announce when the user select a item or multiple items?
EDIT: I fount it: LVN_ITEMCHANGED
Can I make a Window menu (defined in .RC file) with some items disabled?
MENUITEM "&Refresh\tF5",IDM_REFRESH
Or I must disable in WM_CREATE ?
Now im triyin to copy a complete line of the listview to the clipboard.. I use GlobalAlloc & GlobalLock but when I call LV_GETITEM in a .WHILE to get the text of every SubItem to addr returned by GlobalLock obviously I overwrite every previous item and the LV_GETITEM call doesnt return the size of the text. Ideas?
Wait, you confused me.... that is you on the other board right, just a diff nick? Post your code so we can see where your problem is
Use LVM_GETITEMTEXT, it will return the number of characters written to the buffer which you can use to update the pointer in order to append the next string returned. At least I think that's what you want to do, I am a bit confused by the question.
Gunner: Yes.
Donkey: Thats exactly what im trying to do...
invoke OpenClipboard,hWnd
invoke EmptyClipboard
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,512
mov hMemory,eax
invoke GlobalLock,hMemory
xor ecx,ecx
.WHILE ecx!=4
push eax
push ecx
mov lvitem.iSubItem,ecx
mov lvitem.imask,LVIF_TEXT
mov lvitem.pszText,eax
mov lvitem.cchTextMax,511
invoke SendMessage,hListView,LVM_GETITEMTEXT,Index,ADDR lvitem
mov edx,eax
pop ecx
pop eax
add eax,edx
inc ecx
.ENDW
invoke GlobalUnlock,hMemory
invoke SetClipboardData,CF_TEXT,hMemory
invoke CloseClipboard
What do you think about this code? Its ok? How can I add a blank space between subitems? I
and another question :red .. how i can get all selected items to copy to clipboard? a loop with LVM_GETNEXTITEM & LVNI_FOCUSED ?
Hi dacid,
With your code, first I would use other registers than ECX and EAX, EBX and EDI are much better for this application as they are not overwritten by the SendMessage call, eliminating the need to preserve them with push/pop. To add a space just mov a 0x20 byte into the string after the call to SendMessage...
invoke GlobalLock,hMemory
mov edi,eax
xor ebx,ebx
mov esi, 511
.WHILE ebx!=4
mov lvitem.iSubItem,ebx
mov lvitem.imask,LVIF_TEXT
mov lvitem.pszText,edi
mov lvitem.cchTextMax,esi
invoke SendMessage,hListView,LVM_GETITEMTEXT,Index,ADDR lvitem
add edi,eax
sub esi,eax
mov BYTE PTR [edi],20h ; insert a space
inc edi ; update the pointer
dec esi
inc ebx
.ENDW
Also, by keeping cchTextMax fixed you are allowing the possibility of a bufffer overflow exploit, the size of the buffer passed should reflect the size remaining, I used ESI for that purpose.
Edgar
dacid,
This won't answer your question directly, but ...
I mainly use listview to display a range of choices from a database: customer; item; transaction; etc. When an item is added to the listview, I include the record number as one of the items in the listview. This way, when the user selects an item from the listview, I can use the record number to retrieve all the items from the original database. The advantage to this, is that all the items from the database don't have to be included in the listview, and you only need to include the few items in the listview that make it easy for the user to select on particular record.
hth,
farrier
Thak you very much donkey!!
Farrier I will take your idea in consideration!
Now the next step, copy to clipboard all selected items...
invoke OpenClipboard,hWnd
invoke EmptyClipboard
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,4096
mov hMemory,eax
invoke GlobalLock,hMemory
mov edi,eax
invoke SendMessage,hListView,LVM_GETSELECTEDCOUNT,0,0
mov nselected,eax
.WHILE nselected!=0
invoke SendMessage,hListView,LVM_GETNEXTITEM,-1,LVNI_SELECTED
.IF eax!=-1
mov Index,eax
xor ebx,ebx
mov esi,4095
.WHILE ebx!=4
mov lvitem.iSubItem,ebx
mov lvitem.imask,LVIF_TEXT
mov lvitem.pszText,edi
mov lvitem.cchTextMax,esi
invoke SendMessage,hListView,LVM_GETITEMTEXT,Index,ADDR lvitem
add edi,eax
sub esi,eax
mov BYTE PTR [edi],20h ; insert a space
inc edi ; update the pointer
dec esi
inc ebx
.ENDW
.ENDIF
dec nselected
.ENDW
invoke GlobalUnlock,hMemory
invoke SetClipboardData,CF_TEXT,hMemory
invoke CloseClipboard
This copy the same item over and over again... Seems that I dont understand how LVM_GETNEXTITEM works...
I just fixed it this way:
mov Index,-1
.WHILE nselected!=0
invoke SendMessage,hListView,LVM_GETNEXTITEM,Index,LVNI_SELECTED
This seems to work ... but Im not sure this code is "ok"
Looks good to me. Be sure to preserve the values of EBX, EDI and ESI, this is usually done in the PROC statement:
MyProcedure PROC uses EBX EDI ESI SomeParam:DWORD
...
MyProcedure ENDP
Edgar
Yep, thanks. Im triying to "draw" the arrows in the columns when the user clicks on it... Im looking at your example "CustomListview" but I use MASM and this code:
mov hditem.mask,HDI_FORMAT+HDI_IMAGE
mov hditem.fmt,HDF_IMAGE+HDF_STRING+HDF_BITMAP_ON_RIGHT
gives me this error:
error A2081: missing operand after unary operator
Do youk know why?
QuoteDo youk (sic) know why?
Yes, as a matter of fact I do, hditem.mask is not allowed in masm, it uses the keyword MASK. I think Hutch changes it to imask, you'll have to check windows.inc.
Oops, yes, it is "imask"