Click to See Complete Forum and Search --> : Redrawing while scrolling


Sean
May 18th, 1999, 01:02 AM
I have just implemented scrolling in my MDI application, but it is very slow, because of how it redraws the window. My scrolling doesn't use 'RectVisible' or 'InvalidateRect' - because I'm don't understand how to use them - but I'm sure that they, or some other functions, could speed up my scrolling. Could somebody please explain how my scrolling should be done, or maybe point me to a relevent CodeGuru paper?

Thank you,
Sean.

James Dunning
May 18th, 1999, 02:32 AM
Why not derive your View classes from CScrollView, you will find that the scrolling is handled for you.

regards
j..

Jason Teagle
May 18th, 1999, 03:02 AM
RectVisible(), when passed a rectangle, will determine if ANY part of that is in the area of the window which needs to be repainted (the part which has been uncovered by another window, or has just been scrolled into view, etc.). If it says that some part is visible, you will need to draw that part; if it says none of it is visible, you can safely not bother to draw that part. The clipping region that the help talks about is the area which needs painting; you CAN draw outside of this, but it won't have any effect other than to take time. Note that for this routine, 'visible' means that it will actually be redrawn; 'not visible' doesn't necessarily mean that you can't see it here.

For example, say you are drawing a diagram which shows how objects in your code relate to each other; you would have a series of boxes (the objects) joined by lines. When you go to paint the window, for each box you would call RectVisible() with its position and size as a rect, and only bother to redraw it if the routine says it is 'visible'. For each line you could check the rectangle that encolses the two ends; or you could just draw it anyway if there aren't too many.

InvalidateRect() causes the system to add the rectangle you specify to the area which needs repainting; if necessary, it sends a WM_PAINT message to signal that it needs doing. You should only need to use this if you have just created something new which is currently not visible; causing the display to repaint will make it visible. You should pass the smallest possible rectangle that will display your new item to this function, to minimize the amount of repaint needed.

In our above example, if a new object was added, you would have to call InvalidateRect() with a rect that describes where the new box will go in the window to get it shown for the first time.

Does this help?