Solved

Dithered background?

Posted on 1998-08-14
4
203 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

777 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