Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dithered background?

Posted on 1998-08-14
4
Medium Priority
?
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 210 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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.
Suggested Courses

604 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