I've spent a few hours working on a somewhat intractable bug.
The guy who created the program I'm modifying created an owner-draw control that is a multi-column list (it does other things as well). We're having some trouble with redraw leaving bands of grey across the control. Intermittantly, of course.
I've learned how to generate the problem pretty reliably. I've established that the problem is not inside the WM_PAINT handler (by replacing almost the entire handler with a simple routine that gets the entire client rect and fills it with a colored rectangle). Problem still there.
It finally occurs to me to change that colored rectangle's color every time I draw it. That makes it plain that the entire control is not being redrawn every time (sensible -- no need to redraw portions that haven't changed). That should work, assuming that the invalid rectangle is correct and the redraw code correctly redraws everything necessary. Wait -- I know the problem still occurs even if I just draw a rectangle over the entire control, so IF this is the problem, it's happening because the invalid rectangle is..well, invalid -- that is, the invalid rectangle (aka the Update Rect) is not correct.
Turns out that I can modify the UpdateRect inside a WM_PAINT handler simply by calling InvalidateRect. To test, I simply InvalidateRect the whole client rect of the control. Slows drawing down, but it appears to make sure that the necessary parts of the control do, in fact, get updated.
I don't know for sure where the UpdateRect is coming from when there is a problem: Windows provides it (because the common error condition is when another window, not belonging to my application, is moved over the control). And it appears that under some conditions, Windows is not providing the correct information.
Gaaaaaahhhhh!! :-)
Posted by: Jon | 2004.11.02 at 10:02 AM