EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+

#Previous question #Index of VC++/WIN32/MFC Questions #Next question


An artist takes different brushes to fill or draw different objects. A brush in Win32 is a graphical tool that a Win32-based application uses to fill the interior of polygons, ellipses, and paths.

Applications and usage

Drawing applications use brushes to paint shapes; word processing applications use brushes to paint rules; computer-aided design (CAD) applications use brushes to paint the interiors of cross-section views; and spreadsheet applications use brushes to paint the sections of pie charts and the bars in bar graphs.

Brush APIs

Brush is a GDI object. Each device context should associate a brush object for drawing. However there are default system brush for each screen and printer devices. Windows GDI subsystem returns a handle to the brush or HBRUSH for all create brush functions. SelectObject() the generic API for associating brush to a device context. DeleteObject() can be called for cleanup the brush object from memory.

  • CreateSolidBrush - Creates a brush with a solid color
  • CreateHatchBrush - Creates a brush with a hatch pattern and color
  • CreatePatternBrush - Creates a brush with a bitmap pattern
  • CreateDIBPatternBrushPt - Creates a brush with the pattern from a DIB
  • CreateBrushIndirect - Creates a brush with a specified style, color, and pattern
  • GetSysColorBrush - Gets a handle to a brush that corresponds to a color index

Brush class

MFC wraps these above API and HBRUSH member in a class called CBrush. Attributes of brush can be given in overloaded constructors or corresponding functions can be called. Here is the prototype and public member fucntions.

class CBrush : public CGdiObject


	CBrush(COLORREF crColor);           /* CreateSolidBrush */
	CBrush(int nIndex, COLORREF crColor); /* CreateHatchBrush */
	CBrush(CBitmap* pBitmap);          /* CreatePatternBrush */

	BOOL CreateSolidBrush(COLORREF crColor);
	BOOL CreateHatchBrush(int nIndex, COLORREF crColor);
	BOOL CreateBrushIndirect(const LOGBRUSH* lpLogBrush);
	BOOL CreatePatternBrush(CBitmap* pBitmap);
	BOOL CreateDIBPatternBrush(HGLOBAL hPackedDIB, UINT nUsage);
	BOOL CreateDIBPatternBrush(const void* lpPackedDIB, UINT nUsage);
	BOOL CreateSysColorBrush(int nIndex);

	operator HBRUSH() const;
	int GetLogBrush(LOGBRUSH* pLogBrush);


/* Example of how to use CBrush */
void CMyWnd::OnPaint()
	RECT rect;
	/* Create Solid Brush */
	CBrush Brush(RGB(255,0,0));
	/* Brush.CreateSolidBrush(RGB(255,0,0));*/
	CDC *dc = BeginPaint(&ps);
	dc->SelectObject(&Brush); /* Associate Brush to DC */
	dc->Rectangle(&rect); /* Inner filling with solid red */

You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

#Programming Windows, Fifth Edition (Developer Reference)
#Programming Applications for Microsoft Windows (Microsoft Programming Series)
#Programming Windows with MFC, Second Edition
#Visual C++ Programming
#Programming Microsoft Visual C++, Fifth Edition

* #1 webmaster Tue 29 Apr/2014 02:22:57(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.


Your message goes here:

My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.