?
Solved

CDC Ellipse() and Rectangle() background fill

Posted on 2004-09-12
5
Medium Priority
?
6,403 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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

719 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