Re: [Win32lib] Listview speed

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hey, I liked this idea. I've corrected the (many ;-O ) bugs in the example
you sent and enclosed it in a demo program.

-----------------
object VOID
include win32lib.ew
include sort.e
without warning

constant w = createEx(Window,"test load", 0, 0, 0, 400, 0400, 0, 0),
         lv = createEx(ListView, {"English","Digit", "Thai"}, w, 10, 10,
300, 300, LVS_REPORT , 0),
         bt = createEx(Button, "English", w, 10, 340, 60, 25, 0, 0)

global procedure loadLVInfo(atom id, sequence alldata)
    atom hWnd
    atom LV_ITEM
    sequence data
    integer msg

    hWnd = getHandle(id)

    VOID = w32Func( xSendMessage, {hWnd, LVM_DELETEALLITEMS, 0, 0})
    LV_ITEM = acquire_mem(0,  SIZEOF_LVITEM )
    store( LV_ITEM, LVITEM_mask, LVIF_TEXT )

    for i = 1 to length(alldata) do
        store( LV_ITEM, LVITEM_iItem, i-1)
        store( LV_ITEM, LVITEM_lParam, i )
        data = alldata[i]
        for j = 1 to length(data) do
            store( LV_ITEM, LVITEM_iSubItem, j-1 )
            store( LV_ITEM, LVITEM_pszText, data[j] )
            store( LV_ITEM, LVITEM_cchTextMax, length(data[j]) )
            if j = 1 then
                msg = LVM_INSERTITEM
            else
                msg = LVM_SETITEM
            end if
            VOID = w32Func( xSendMessage, { hWnd, msg, j-1, LV_ITEM } )
        end for

    end for

    release_mem(LV_ITEM)
end procedure

sequence theData theData = {}
integer theDir theDir = 1

theData = append(theData, {"One", "1", "neung"})
theData = append(theData, {"Two", "2", "song"})
theData = append(theData, {"Three", "3", "sam"})
theData = append(theData, {"Four", "4", "si"})
theData = append(theData, {"Five", "5", "ha"})
theData = append(theData, {"Six", "6", "hok"})
theData = append(theData, {"Seven", "7", "jet"})
theData = append(theData, {"Eight", "8", "baht"})
theData = append(theData, {"Nine", "9", "kow"})
theData = append(theData, {"Ten", "10", "sip"})


loadLVInfo(lv, theData)


------------------------------------------------
function mysort(object p1, object p2)
------------------------------------------------
    object l1,l2

    if theDir = 1 then
        l1 = p1[1]
        l2 = p2[1]

    elsif theDir = 2 then
        l1 = value(p1[2])
        l1 = l1[2]

        l2 = value(p2[2])
        l2 = l2[2]
    else
        l1 = p1[3]
        l2 = p2[3]

    end if

    return compare(l1, l2)
end function

constant bttext = {"English", "Digit", "Thai"}
------------------------------------------------
procedure onClick_bt(integer self, integer event, sequence parms)
------------------------------------------------
    theData = custom_sort(routine_id("mysort"), theData)
    loadLVInfo(lv, theData)

    theDir += 1
    if theDir = 4 then
        theDir = 1
    end if

    setText(bt, bttext[theDir])

end procedure
setHandler(bt, w32HClick, routine_id("onClick_bt"))


WinMain(w, 0)

-----------------
Derek.

----- Original Message -----
From: <euman at bellsouth.net>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, June 15, 2002 9:23 AM
Subject: [Win32lib] Listview speed


>
> Hello Matt Lewis and all,
>
> The (below) procedure is faster for loading Items into a listview
> however, I havent figured out how I plan to sort the data using this
> routine. I'll work on this some more tonight.
>
> You also can not sort the listview using the current Win32lib sort
> algorythm and this procedure, perhaps someone who knows the lib
> better would do this.
>
> If your plans are to not allow sorting then this will be a better choice
> for speed.
>
> -- add to Win32lib
> global procedure LoadLVInfo(atom id, sequence alldata)
> integer howmany
>   handle = getHandle(id)
>   howmany = length(alldata)
>   for i = 1 to howmany do
>      LV_ITEM = acquire_mem(0,  SIZEOF_LVITEM )
>      store( LV_ITEM, LVITEM_mask, LVIF_TEXT )
>      store( LV_ITEM, LVITEM_iItem, i-1)
>      data = alldata(i)
>      subitem = 0
>      for x = 1 to length(data) do
>         store( LV_ITEM, LVITEM_iSubItem, subitem )
>         store( LV_ITEM, LVITEM_pszText, data[x] )
>         store( LV_ITEM, LVITEM_cchTextMax, length(data[x]) )
>         subitem += 1
>         if subitem = 1 then
>           junk = w32Func( xSendMessage, { handle, LVM_INSERTITEM, 0,
LV_ITEM } )
>         else
>           junk = w32Func( xSendMessage, { handle, LVM_SETITEM, i-1,
LV_ITEM } )
>         end if
>       end for
>       store( LV_ITEM, LVITEM_lParam, i )
>       release_mem(LV_ITEM)
>   end for
> end procedure
>
> P.S this routine would be faster if hacked.
> e.g straight pokes( ) instead of store( ) and/or, inlining the routine in
your program.
>
> Good Day!
>
> Euman
> euman at bellsouth.net
>
> ==================================================================
> The information contained in this message may be confidential
> and is intended to be exclusively for the addressee. Should you
> receive this message unintentionally, please do not use the contents
> herein and notify the sender immediately by return e-mail.
> ==================================================================
>
>
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu