Solved

Dithered background?

Posted on 1998-08-14
4
210 Views
Last Modified: 2010-04-10
Hi,

I've been playing around with MSVC 1.5 for a couple of weeks now, and I was wondering how those dithered backgrounds are created.  As near as I can figure out, you start with a color, say blue (RGB(0,0,255)) and slice the background into small rectangles, darkening the blue (from 255 to 0) as you go, using a loop.  But, I haven't been able to find a way to re-define a CBrush object.  So, I have two questions:

1.  Am I even on the right track?

2.  If I'm right, how do you re-define a brush?

Thanks for any help.

Have Fun!
Bob Z.
0
Comment
Question by:ZeinerRJ
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 70 total points
ID: 1170299
1. You are on the right track, but there's an easier way (see 3)

2. To paint each rectangle do

CBrush myBrush ;
myBrush.CreateSolidBrush( RGB(0,0,ii) ) ; // where ii is blue intensity
CBrush * pOldBrush = pDC->SelectObject( &myBrush ) ;
pDC->Rectangle( &rect ) ; // rect is the rectangle to paint
pDC->SelectObject( pOldBrush ) ;

3. The easier way is to let MFC do the creation of the brushes for you
pDC->FillSolidRect( &rect, RGB(0,0,ii) ) ; // rect is the rectangle to paint, ii is the blue intensity



0
 

Author Comment

by:ZeinerRJ
ID: 1170300
Hmm,

#1 gives me a run-time error.  Apparently you can't run 'Create' statments more than once.

#2 gives me the following error:
'FillRect' : cannot convert parameter 2 from 'const unsigned long ' to 'class ::CBrush __near *'

Any other ideas, or any idea why the code bits aren't working?

Bob Z.
0
 

Author Comment

by:ZeinerRJ
ID: 1170301
My main problem was that I was trying to do the brush inside the loop.  When I created a routine to call, that fixed it.

It was nice to know I was on the right track.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1170302
I know this is old now - but the reasons are

#1 - you need to make sure the CBrush destructor is called at the end.  Eithrer move code to a function (as you did) - or new/delete the CBrush each time

#2 - FillSolidRect - NOT FillRect (this is a different function).   With FillSolidRect - MFC does the brush stuff for you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question