Solved

Dithered background?

Posted on 1998-08-14
4
183 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now