Chapter 64 Brushes

64.1 About Brushes

A brush is a graphics tool that a Windows application uses to paint the interior of polygons, ellipses, paths, and individual characters in a string of text. Drawing applications use brushes to paint shapes and text. Word processing applications use brushes to paint rules and text. CAD applications use brushes to paint the interior of cross-section views. And, spreadsheet applications use brushes to paint the sections of a pie chart or the bars in a bar graph.

There are two types of brushes: logical and physical. A logical brush is a description of an 8-by-8 pixel bitmap that an application will use to paint text and objects. (For more information about bitmaps, see Chapter 63, “Bitmaps.”) A physical brush is the actual bitmap which a device driver creates based on an application's logical brush.

When an application calls one of the functions which creates a brush, it obtains a handle that identifies a logical brush. When that application passes the logical brush handle to the SelectObject function, the device driver for the corresponding display or printer creates the physical brush—an 8-by-8 pixel bitmap.

When an application calls a drawing function that paints an object, Windows begins the paint operation by positioning the brush in the upper-left corner of the client area of the application's window, Windows then copies the brush across the client area forming a pattern that is eight pixels high. The copy operation continues, row by row, until the entire client area has been filled. However, the brush pattern is only visible within the boundaries of the specified object.

When Windows positions the brush at the start of the paint operation, it maps a pixel in the brush's bitmap to the window origin of the applications client area. The coordinates of the pixel which it maps are called the brush origin. The default brush origin is located in the upper-left corner of the brush at the coordinate (0,0).

The following illustration shows a five-pointed star that was filled with an application-defined brush. The illustration shows a zoomed image of the brush as well as the location to which it was mapped at the beginning of the paint operation:

Zoomed-Image of Brush

There are four types of brushes: solid, stock, hatch, and pattern. The following illustration shows four identical circles—each filled with one of the four types of brushes:

The Four Types of Brushes