Solved

CDC Ellipse() and Rectangle() background fill

Posted on 2004-09-12
5
6,273 Views
Last Modified: 2013-11-20
I have to do a simple assignment for a class that requires the user to be able to give the parameters of a rectangle or circle and have them draw on the screen.  I am done with it except for one point.  When I use the CDC Ellipse() and Rectangle() functions, they are drawing a soild background color.  I would prefer that they use a "transparent" background and allow what is already drawn in the DC to show behind them.

Here is code I am using to draw:

void Rect::Draw(CDC* pDC, CPoint drawOrigin)
{
      CPen shapePen(PS_SOLID,2,this->m_shapeColor);
      CPen* oldPen = pDC->SelectObject(&shapePen);
      pDC->Rectangle(
            this->m_upperLeft.x + drawOrigin.x,
            this->m_upperLeft.y + drawOrigin.y,
            this->m_bottomRight.x + drawOrigin.x,
            this->m_bottomRight.y + drawOrigin.y
      );
      pDC->SelectObject(oldPen);
}

void Circle::Draw(CDC* pDC, CPoint drawOrigin)
{
      CPen shapePen(PS_SOLID,2,this->m_shapeColor);
      CPen* oldPen = pDC->SelectObject(&shapePen);
      pDC->Ellipse(
            this->m_center.x - this->m_radius + drawOrigin.x,
            this->m_center.y - this->m_radius + drawOrigin.y,
            this->m_center.x + this->m_radius + drawOrigin.x,
            this->m_center.y + this->m_radius + drawOrigin.y
      );
      pDC->SelectObject(oldPen);
}

Is there a simple way to make a transparent background for the shapes with this code?  I say simple because I don't think the solid background is going to lose me any points, so I am not going to implement a solution unless it can be done relatively painlessly.

Thanks for the help,

~ Justin
0
Comment
Question by:newstandard
[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
5 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 12041449
CPen shapePen(PS_NULL, 1, this->m_shapeColor);
CPen* oldPen = pDC->SelectObject(&shapePen);
...
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 12041469
Sorry, ignore my previous post.

void Rect::Draw(CDC* pDC, CPoint drawOrigin)
{
     CPen shapePen(PS_SOLID,2,this->m_shapeColor);
     CPen* oldPen = pDC->SelectObject(&shapePen);

     CBrush brush;
     brush.CreateStockObject(NULL_BRUSH);
     CBrush* oldBrush =  (CBrush*)pDC->SelectObject(&brush);

     pDC->Rectangle(
          this->m_upperLeft.x + drawOrigin.x,
          this->m_upperLeft.y + drawOrigin.y,
          this->m_bottomRight.x + drawOrigin.x,
          this->m_bottomRight.y + drawOrigin.y
     );

     pDC->SelectObject(oldBrush);
     pDC->SelectObject(oldPen);
}
0
 

Author Comment

by:newstandard
ID: 12042811
aah okay.  i didn't realize the brush was responsible for the fill of the shape.  i will give that a shot.

~ Justin
0

Featured Post

Myth Busting: MongoDB Scalability (it scales!)

I was talking with one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. He mentioned to me that several customers have been telling him that “MongoDB doesn’t scale!” MongoDB’s scalability was in question?

My response was, “Is that a joke?"

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

628 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