Scrolling

Efficient scrolling is important for achieving good performance with scrollable windows, especially with document-based programs. The key to efficient scrolling is to not draw the entire contents of a window every time a paint message is received (which is usually what is done in sample code), but to draw only the portion of the window that is invalid. You can determine the invalid area by looking at the rcPaint rectangle in the PAINTSTRUCT or with the CDC::GetClipBox function in MFC. (If you are using MFC, note that scrolling is usually accomplished by changing the view's window origin. You need to subtract the window origin from the clip box to get the invalid region relative to the top of the document.)

TIP
Improve drawing and scrolling performance by redrawing only the invalid area.

How you determine exactly what part of the document to draw given an invalid rectangle is the difficult part, and it is completely dependent upon the document you are drawing. Let's take drawing a simple HTML page as an example. The screen shot here shows an HTML page in Microsoft Internet Explorer with H1, H2, and H3 headings and some text.

click to view at full size.

If you look carefully, you will notice that each item displayed is an integral number of normal text lines in height. For example, the H1 and H2 headers are twice the size of a normal text line, and all spacing between headings and paragraphs is the size of a normal text line. If you maintain this simple relationship between formatted HTML text and its position on the screen, it's easy to determine the lines that need to be painted. In general, avoid designing documents and views where there is not a simple relationship between the document and its view.



Developing User Interfaces for Microsoft Windows
Developing User Interfaces for Microsoft Windows
ISBN: 0735605866
EAN: 2147483647
Year: 2005
Pages: 334

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net