Search code examples
c++winapilistboxownerdrawn

C++ Winapi Owner drawn listbox animation


I've got an owner-drawn listbox, in which I would like to draw an animation of some progress. A picture of what I've got so far will say a lot I believe:

Listbox

Each file is added to the listbox when dropped on the DRAG HERE area, where a new thread is created and encryption/decryption process is started. The enc/dec process saves a progress value (in percents) to a variable given, of how much job is done.
As the progress grows by one, I'm redrawing the listbox.

if(progress - prevProgress > 1.0)
{
    InvalidateRect(Listbox, &ListboxProgressRect, TRUE);
    UpdateWindow(Listbox);
    prevProgress = progress;
}

The problem is that each item is redrawn even when only one item ought to be redrawn. The ListboxProgressRect area in fact includes the most right 40 pixels of the listbox times the listbox height.

I would like to handle the drawing entirely in WM_PAINT with subclassed Ctrl, but I don't know how would I draw the items and the scrollbar feature. An editbox and a button next to the progress bar would be nice as well.

Should I subclass the listbox and handle all the drawing? If so, how can I draw the scrollbar (and make it work)?


Solution

  • You only want to redraw one item, so you should only invalidate one item.

    Trouble is, you don't know where the item is. The listbox does. So ask it.

    Send LB_GETITEMRECT.