65.9K
CodeProject is changing. Read more.
Home

A Cool GDI Pattern Brush Tool with C++ Source Code

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.32/5 (31 votes)

Aug 28, 2003

viewsIcon

92368

downloadIcon

2997

A cool GDI pattern brush tool with C++ source code. You can create a new office XP style pattern fill mode quickly.

Introduction

This article shows how to use a pattern brush to give your application a similar look and feel, and it also includes a pattern brush bits tool. With this tool, you can create a new style of pattern brush very quickly.

How to Use It

The steps for usage are as follows:

  • Run application brushtool.exe.
  • Click on the left design panel to draw a style, you can click >> button to preview the style.
  • Click copy button to copy the bits to clipboard.
  • Call the following code to use the pattern brush. (You can paste the brush bits to the red field.)

Code

WORD m_bitsBrush1[8] = { 0xee,0xed,0xeb,0xe7,0xef,0xff,0xff,0xff };

CBrush brush,*pOldbrush;
CBitmap bm;
bm.CreateBitmap(8,8,1,1,m_bitsBrush1);

LOGBRUSH logBrush;
logBrush.lbStyle = BS_PATTERN;
logBrush.lbHatch = (int) bm.GetSafeHandle();
logBrush.lbColor = RGB(0,0,0);

brush.CreateBrushIndirect(&logBrush);
int savedc = dc.SaveDC();
pOldbrush=dc.SelectObject(&brush);
dc.SetBkMode(TRANSPARENT); 
dc.SetBkColor(RGB(255,255,255));
dc.Rectangle(&rcNew);
dc.SelectObject(pOldbrush); 
brush.DeleteObject();
bm.DeleteObject();
dc.RestoreDC(savedc);

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.