?
Solved

Dithered background?

Posted on 1998-08-14
4
Medium Priority
?
224 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

765 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