Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

In Windows Embedded CE, a brushis a graphic object for painting the interior of closed shapes. Drawing applications use brushes to paint shapes; word-processing applications use brushes to paint rules; CAD applications use brushes to paint the interiors of cross-section views; and spreadsheet applications use brushes to paint graphs.

When you call one of the functions that create a brush, such as CreatePatternBrush, it returns a handle to a logical brush. When you select the logical brush into the device context with the SelectObjectfunction, the device driver for the corresponding device creates the physical brush used for painting.

When you call a painting function, GDI maps a pixel in the brush bitmap to the window origin of the client area. The window origin is the upper-left corner of the window client area. The coordinates of the mapped pixel are called the brush  origin. The default brush origin is the upper-left corner of the brush bitmap, at the coordinates (0, 0). You can call the SetBrushOrgExfunction to change the location of the brush origin by a specified number of pixels. To make the changes effective, you must call the SelectObjectfunction to select the modified brush.

Windows Embedded CE supports three types of logical brushes: stock brushes, solid brushes, and pattern brushes.

The types of stock brushes include the white brush, black brush, gray brush, light gray brush, dark gray brush, and the null brush, which does not paint. Call the GetStockObjectfunction to select one of the stock brushes.

Windows Embedded CE maintains 21 stock brushes whose colors are used in window elements such as menus, scroll bars, and buttons. You can obtain a handle to a system stock brush with the GetSysColorBrushfunction. Furthermore, you can retrieve the color window element with the GetSysColorfunction, and set a color corresponding to a window element with the SetSysColorsfunction.

A solid brush contains 64 pixels of the same color in an 8 x 8 pixel square. You can call the CreateSolidBrushfunction to create a solid brush of a specified color. To paint with your solid brush, call SelectObjectto select it into a specified device context.

You can create a pattern brush from an application-defined bitmap or a device-independent bitmap. To create a logical pattern brush, you must create a bitmap and then call the CreatePatternBrushor CreateDIBPatternBrushPtfunction, supplying a handle that identifies the bitmap or DIB.

Windows Embedded CE does not support hatched brushes. However, you can achieve the effect of a hatched brush by calling the CreateDIBPatternBrushPtfunction to create a pattern brush with the hatch pattern that you want.

The following code example shows how to use brush functions.

Note:
To make the following code example easier to read, error checking is not included. Do not use this code example in a release configuration unless you have modified it to include secure error handling.
Copy Code
HDC hDC; 		// Handle to the display device context 
HRGN hRgn; 	// Handle to a region object  
HBRUSH hBrush; // Handle to a brush object 
RECT rect; 	// A RECT structure that contains the window's 
					// client area coordinates
static COLORREF g_crColor[] = {
					 
0x000000FF,0x0000FF00,0x00FF0000,0x0000FFFF,
					 
0x00FF00FF,0x00FFFF00,0x00FFFFFF,0x00000080,
					 
0x00008000,0x00800000,0x00008080,0x00800080,
					 
0x00808000,0x00808080,0x000000FF,0x0000FF00,
					 
0x00FF0000,0x0000FFFF,0x00FF00FF,0x00FFFF00};

// Retrieve the handle to a display device context for the client 
// area of the window (hwnd). 
if (!(hDC = GetDC (hwnd)))
  return;

// Retrieve the coordinates of the window's client area. 
GetClientRect (hwnd, &rect);

// Create a rectangular region.
hRgn = CreateRectRgn (0, 0, rect.right, rect.bottom);

// Create a solid brush.
hBrush = CreateSolidBrush (g_crColor[0]); 

// Fill the region out with the created brush.
FillRgn (hDC, hRgn, hBrush);

// Delete the rectangular region. 
DeleteObject (hRgn);

// Delete the brush object and free all resources associated with
it.
DeleteObject (hBrush);

// Release the device context.
ReleaseDC (hwnd, hDC);

return;

See Also