Click here to Skip to main content
15,885,767 members
Articles / Desktop Programming / MFC

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

Rate me:
Please Sign up or sign in to vote.
3.32/5 (31 votes)
27 Aug 2003 90.8K   2.9K   30   13
A cool GDI pattern brush tool with C++ source code. You can create a new office XP style pattern fill mode quickly.

Image 1

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

C++
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.


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralColor and Transparency Pin
foufou27-Apr-08 0:11
foufou27-Apr-08 0:11 
GeneralReally a nice article Pin
Sarath C21-May-06 19:28
Sarath C21-May-06 19:28 
GeneralRe: Really a nice article Pin
joyjjjz25-Sep-08 17:20
joyjjjz25-Sep-08 17:20 
GeneralA little imagination goes a long way!! Pin
WREY29-Aug-03 16:51
WREY29-Aug-03 16:51 
It never ceases to amaze me, how a lot of people miss out on some truly inspiring opportunities, simply due to the lack of a little imagination.

I'm not talking about imagination in the ridiculous sense. I'm talking about imagination in the sense such that you have something from which to work, and you want to get from Point A to Point B. How do you come up with a plan, or figure out a way of achieving that goal? IOW, mix logic and practicality with a little imagination to get what you want.

History is replete with some of the best minds, from explorers, inventors, scientists, artists, (etc.), of coming up with some really astounding thoughts and ideas that lead to some truly magnificent discoveries, expansion of science, and enjoyment in the arts, simply from mixing some imagination with what they were doing, or proposed doing.

In science for example, Uranium 239, Plutonium, Einsteinium, Fermium (and a bunch of other similar chemical elements), were NOT created by nature. They were "man made". IOW, these heavy chemical elements can be thought of as kind of "super elements", because they were created from a more basic chemical element.

So look at what the author of this article has done. He has provided a "basic element" (of sort) from which other "super elements" can be obtained. To show an example of that, from his "basic element" he has created a "super element" known as a "brush", and he has done so, programmatically. This means, we can also programmatically create other "super elements" like a "pen", a "bitmap" (etc.) by using and extending his techniques.

He has provided us with the means of how to do it, and why would anyone NOT take note of that, I can only attribute as due to the lack of a little imagination.

Speaking for myself, I am thankful for what he has contributed and I say to him, "Thank you, and well done!!"

Cool | :cool: Cool | :cool:

William

Fortes in fide et opere!
GeneralUsability suggestion Pin
YoSilver28-Aug-03 23:05
YoSilver28-Aug-03 23:05 
GeneralRe: Usability suggestion Pin
ucc80129-Aug-03 0:09
ucc80129-Aug-03 0:09 
GeneralGreat tool! Pin
Anonymous28-Aug-03 4:03
Anonymous28-Aug-03 4:03 
GeneralRe: Great tool! Pin
Warren Stevens28-Aug-03 7:13
Warren Stevens28-Aug-03 7:13 
GeneralAnonymous = comment by author Pin
dog_spawn28-Aug-03 14:58
dog_spawn28-Aug-03 14:58 
GeneralRe: Anonymous = comment by author Pin
.dan.g.28-Aug-03 17:24
professional.dan.g.28-Aug-03 17:24 
Generalheh Pin
dog_spawn28-Aug-03 18:52
dog_spawn28-Aug-03 18:52 
GeneralRe: heh Pin
Ernest Laurentin29-Aug-03 4:10
Ernest Laurentin29-Aug-03 4:10 
GeneralSuggestion Pin
dog_spawn28-Aug-03 3:45
dog_spawn28-Aug-03 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.