Solved

CDC Ellipse() and Rectangle() background fill

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 189
Host to IP 7 80
Separate into files by filename 12 87
Replacement selected text 2 63
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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