1.6.8 Brush Alignment

Brush alignment is particularly important on the system display where scrolling and moving are commonplace. A brush is a pattern of bits with a minimum size of 8-by-8 bits. GDI paints with a brush by repeating the pattern again and again within a given rectangle or region. If the region is moved by an arbitrary amount—for example, if the window is scrolled—and the brush is used again to fill empty areas around the original area, there is no guarantee that the original pattern and the new pattern will be aligned. For example, if the scroll moves the original filled area up one pixel, the intersection of the original area and any new painting will be out of alignment by one pixel, or bit. Depending on the pattern, this may have an undesirable visual effect. For more information about brushes, see Chapter 2, “Graphics Device Interface.”

To ensure that a brush is aligned after a window is moved, an application must take the following steps:

1.Call the SelectObject function to select a different brush to be the current brush.

2.Call the SetBrushOrg function to realign the current brush.

3.Call the UnrealizeObject function to realign the origin of the original brush when it is selected next. (UnrealizeObject should not be used on stock objects, only on brushes created by the application.)

4.Call the SelectObject function to select the original brush.