I need to save to a file the content of a listview .. I use
'GetSaveFileName' & 'CreateFile' ... and now??.

thx.
Posted on 2002-05-31 04:33:02 by hunter
read it out? btw do you mean list-VIEW or list-BOX? if it's
a list-box then look up the LB_??? messages in your api-ref.
the LVM_??? msg's are reserved for the list_VIEW control
but it's nearly the same...

(vb style) pseudo-code would be:



filehandle = _lcreat("test.txt",0)

count = sendmessage(lb_handle,LB_GETCOUNT,0,0)

for index=0 to count
len = sendmessage(lb_handle,LB_GETTEXT,index,addr Buffer)
_lwrite(filehandle, addr Buffer, len)
next index

_lclose(filehandle)


if you want only ONE item in a LINE then you have to
insert crlf chars (db 13, 10) at the end of an item...
Posted on 2002-05-31 04:53:12 by mob
Hi

After CreateFile, allocate a block of memory you need with GlobalAlloc so you can write all the data in the listview in one go. To calculate the size you'll need you can implement some kind of byte counter as you input the items into the listview in the first place. i.e. if you format the text with wsprintf before using LVM_INSERTITEM, the return value is the length of the text (add 1 for null terminator). If you will add tabs or spaces between the listview items in your text output, increase the size of the memory block accordingly. GlobalLock returns a pointer pMemory to the first byte of the memory block.

LVM_GETITEMTEXT in a nested loop will retrieve each listview column and row entry, which you can insert into the memory block beginning at pMemory. Adding a byte 09h will insert a tab between the column entries, and a word 0A0Dh will insert a hard return at the end of the row.

Then you should be able to do one complete WriteFile of the entire memory block, closing handles and deallocating memory afterwards. Hope this helps.

Kayaker
Posted on 2002-05-31 11:19:08 by Kayaker
Hi,

you might want to take a look at the source I attached to this post.

It is far from good, but it works for me and I don't have time to work on it at the moment.

Greets
YaWNS aka Stefan K.
Posted on 2002-05-31 12:37:15 by YaWNS