Solved

Drawing

Posted on 1999-01-01
4
1,259 Views
Last Modified: 2013-11-20
I have a dialog box that I would like to draw circles all over, something like a screen saver, but smaller.  I can't figure out how to draw a simple circle tho!  What is the deal?  How do I draw a circle?
0
Comment
Question by:abc021397
  • 3
4 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1327111
To draw a circle, you want to use the CDC::Ellipse function.  If you have any questions on how to use it, please feel free to ask.

You can also use the API function Ellipse where you provide it a handle to a device context.
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 200 total points
ID: 1327112
1. Go the dialog class source file

2. Press Ctrl-W to bring up class wiz

3. Double click on WM_PAINT in RHS list box (make sure the dialog name is selected in LHS list).  Press Edit Code

You should see

code like

void CMyDialog::OnPaint()
{
      CPaintDC dc(this); // device context for painting
      
      // Do not call CDialog::OnPaint() for painting messages
}

4. Replace the // Do not call...etc comment with your painting code.

5. To draw circles use the CDC class member (CDC is base class for CPaintDC) Ellipse as thresher says

example:

cdc.Ellipse( 0, 0, 100, 100 ) ;

The first 2 parameters are the x,y coord of the top left of rectangle containing the ellipse (0,0 is top left of the dialog).  The 3rd and 4th parameters are width and height of the box containing the ellipse.   Making the 3rd and 4th parameters the same makes the box into a square, and the ellipse into a circle.

The coord are measured in pixels (the dots making up your screen), so it may not appear exactly circular if you have a screen with non-square pixels.  You can adjust the width/height separately rto give circular appearance.

More in comment below..



0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1327113
6. The ellipse fills in the circle with the current brush, and draws the edge in the current pen.  By default (a white brush for the interior, and a single pixel black pen for the edge).

Change the edge by creating and selecting a different pen, e.g. CreatePen the SelectObject

Change the interior by creating and selecting a different brush, e.g. CreateSolidBrush then SelectObject

You can also use stock pens and stock brushes.e.g. GetStockObject

If you create a pen or brush with API (not MFC functions) (as opposed to using a stock one) you must also DeleteObject it when done.

Here's code to use a red pen, and a blue brush

// create pens and brushes
CPen pen ;
CBrush brush ;
pen.CreatePen( PS_SOLID, 1, RGB(255,0,0) ) ;
CPen * poldpen = dc.SelectObject( &pen ) ;
brush.CreateSolidBrush( RGB(0,0,255) ) ;
CBrush * poldbrush = dc.SelectObject( &brush ) ;

// draw circle
dc.Ellipse( 0,0,100,100 ) ;

// restore brushes
dc.SelectObject( poldbrush ) ;
dc.SelectObject( poldpen ) ;



0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1327114
Here's code to use a red pen, and a NULL (i.e. leave alone the interior) brush

         // create pens and brushes
         CPen pen ;
         CBrush * pbrush ;
         pen.CreatePen( PS_SOLID, 1, RGB(255,0,0) ) ;
         CPen * poldpen = dc.SelectObject( &pen ) ;
         pbrush = CBrush::FromHandle( (HBRUSH)GetStockObject(NULL_BRUSH) ) ;
         CBrush * poldbrush = dc.SelectObject( pbrush ) ;

         // draw circle
         dc.Ellipse( 0,0,100,100 ) ;

         // restore brushes
         dc.SelectObject( poldbrush ) ;
         dc.SelectObject( poldpen ) ;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 85
string initialization in java 11 110
withoutTen challenge 14 99
Detect file exist or not 3 130
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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

912 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

16 Experts available now in Live!

Get 1:1 Help Now