Solved

CDC Ellipse() and Rectangle() background fill

Posted on 2004-09-12
5
5,880 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
  • 2
5 Comments
 
LVL 48

Expert Comment

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

Accepted Solution

by:
AlexFM earned 125 total points
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 30
substring method in java 1 79
java ^ examples 8 57
wordappend challenge 8 84
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

17 Experts available now in Live!

Get 1:1 Help Now