Solved

CDC Ellipse() and Rectangle() background fill

Posted on 2004-09-12
5
6,133 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 107
Best tools for Backup and restore of Wordpress site 6 58
has77  challenge 9 99
post4 challenge 28 113
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ā€¦
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

696 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