OK, if anybody still cares, here's the latest and greatest. @Swordfish, notice that scrolling is now fully implemented, including thumb-tracking. (Wasn't hard to get working; I just wasn't tracking it properly in my paint handler.) Also notice that long items now are drawn with ellipsis (...) at the end if they're wider than their "cell". This is due to using
DrawText() rather than
ExtTextOut() (see below for some gory details).
It's getting close; I'm not ready to release the code into the wild yet, because I don't want to have to go chasing versions all over the place as I continue to tweak things and go through my todo list:
- Proper memory management (halfway there, but still not robust)
- Keyboard interface (none currently)
- Maybe make it resizeable?
- Take Greenhorn's suggestion and store instance data pointer in the control's "extra bytes"
Anyhow, play around with it as usual. Next time I'll explain the programming interface for adding items and solicit comments on it.
Regarding drawing text: I learnt something about this. I was using
ExtTextOut(), which works OK, except I wanted to add text ellipsis (...) for items that don't fit in their cell. So I tried
DrawText(), which has this capability. At first I couldn't get anything at all to show. I was using the following flags:
DT_END_ELLIPSIS or DT_LEFT or DT_TOP or DT_NOPREFIX
Nothing. I searched online and found a couple discussions of why this function doesn't work sometimes, but no solutions that made it work for me.
Then I went back to the documentation and noticed some additional flags. One of them,
DT_SINGLELINE, says it "Displays text on a single line". I hadn't figured I needed this--isn't this the default?--but when I added it, things started to work. Way to go, Micro$oft, for incomplete explanations of your API!
Moral of the story: if things don't work, after consulting the oracle (the Intertubes), it pays to experiment.