News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Fill a listbox 40*faster

Started by jj2007, November 29, 2009, 02:07:05 AM

Previous topic - Next topic

jj2007

We use LB_ADDSTRING to add items to a listbox. This is amazingly fast for reasonable item counts, say: up to a 1000, but if you want to display the 22,000 lines of \masm32\include\windows.inc in a listbox, it will become slow - the standard technique will need over one second.

Here is a way to display e.g. windows.inc 40 times faster, using WM_SETREDRAW*) and LB_INITSTORAGE*) in the correct order:

Quote   invoke SendMessage, hListbox, WM_SETREDRAW, 0, 0      ; A: stop the screen updating (the order is very important!)
   invoke SendMessage, hListbox, LB_RESETCONTENT, 0, 0      ; B: clear the listbox
   invoke SendMessage, hListbox, LB_INITSTORAGE, ctEnd, bytes   ; C: tell the OS what you need: how many lines, how many bytes
   .Repeat
         invoke SendMessage, hListbox, LB_ADDSTRING, 0, L$(ct)   ; add string items (any method is ok; L$ is MasmBasic)
         inc ct
   .Until ct>=ctEnd
   invoke SendMessage, hListbox, WM_SETREDRAW, 1, 0      ; D: turn on screen updating

*): See posts of Sinsi and MichaelW - thanks :thumbu

hutch--

Well done JJ, looks like a good technique.  :U
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

sinsi

According to MSDN you might need a call to RedrawWindow after re-enabling drawing if the listbox has non-client areas (e.g. border).
Light travels faster than sound, that's why some people seem bright until you hear them.

jj2007

"might" indeed. MSDN also recommends InvalidateRect for the same job, and the almost useless LockWindowUpdate instead of WM_SETREDRAW. Besides, why repaint the non-client areas if only the contents (i.e. the client area) has changed? But test yourself... if it flickers or refuses to show content, let me know (pathname is \Masm32\include\Windows.inc, so you will have to extract it somewhere on your Masm32 drive).

Jimg

I know I haven't been paying attention for a couple of months, but what is this?
The first time I press "push me" nothing happens.
The second time, I get a single "ENDIF"
the ".asc" is pretty useless.
What's going on here?

jj2007

Quote from: Jimg on November 29, 2009, 03:24:58 PM
I know I haven't been paying attention for a couple of months, but what is this?
The first time I press "push me" nothing happens.
The second time, I get a single "ENDIF"
the ".asc" is pretty useless.
What's going on here?


The *.exe loads (alternating) \masm32\include\windows.inc or \masm32\include\winextra.inc. This should fail only if you launch it from a drive different from your masm32 installation. Typically that happens if Masm32 is on D:, temp is on C:, and you double-click from WinZip...

> The second time, I get a single "ENDIF"
That is truely odd. On my machine, Win XP SP2, the two files fill that listbox. Which OS are you running? Do you get an error message saying "could not open..."?

> the ".asc" is pretty useless.
Sorry - *.asm attached.

Jimg

Thanks, I'll have to look into it.
masm32 is in the root of my F: drive
I didn't see any reference to temp in the code, but mine is in the root of my K: drive.
I dropped your new exe in the root of F: and ran it.
This time, I get a single long line for each file with the crlf's represented as block characters.
I'm assuming this is a stand-alone exe and doesn't require a masmbasic dll or something.
Sorry to cause trouble, I was just interested in a timing.

jj2007

Quote from: Jimg on November 30, 2009, 02:16:59 PM
Thanks, I'll have to look into it.
masm32 is in the root of my F: drive
I didn't see any reference to temp in the code, but mine is in the root of my K: drive.
I dropped your new exe in the root of F: and ran it.
This time, I get a single long line for each file with the crlf's represented as block characters.
I'm assuming this is a stand-alone exe and doesn't require a masmbasic dll or something.
Sorry to cause trouble, I was just interested in a timing.

> crlf's represented as block characters
You are not causing trouble, Jim. This is very odd, as it runs smoothly on my two machines. Does anybody else observe similar problems?


Jimg

How about making me a quickie to print out the number of lines found in the file.  It sure looks like it is treating the whole file as one line.

jj2007

Here is your quickie :bg

Ficko

Do this would work for LISTVIEW too?

jj2007

Quote from: Ficko on December 03, 2009, 04:23:36 PM
Do this would work for LISTVIEW too?

If you find the sm hListbox, LB_ADDSTRING, 0, L$(n) equivalent, why not? I have no experience with listviews...

Jimg

When I run it, it says linecount 1.

It's being read somewhere in masmbasic, right?


Ficko

Quote from: jj2007 on December 03, 2009, 05:06:28 PM
Quote from: Ficko on December 03, 2009, 04:23:36 PM
Do this would work for LISTVIEW too?

If you find the sm hListbox, LB_ADDSTRING, 0, L$(n) equivalent, why not? I have no experience with listviews...


The problem there is no equivalent for "LB_INITSTORAGE" so adding a new item to a listview forces new memory allocation.
Awful slow. :(