Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To draw a circle 1

Status
Not open for further replies.

ebuBekir

Technical User
Sep 6, 2001
22
0
0
DE
Hi All!
I have following problem with my Win32 Application:

I want to draw a circle into my window and I have the parameters for it (x, y, radius).
I have found DrawCircle in MSDN like:

Syntax
object.DrawCircle x, y, radius, [color, aspect]

When I tried it I got an error ('DrawCircle' : undeclared identifier).
Thanks for your help! :cool:
 
Well, in a win32 App I'd say that would be the GDI Ellipse() function. You can draw a neat little circle like this:

Ellipse(dc,0,0,100,100);

With MFC it'd be

CRect rect(0,0,100,100);
dc.Ellipse(rect);
 
Thanks Dave,
I already tried this, but the circle I can draw is a little bit shifted. Seems to be that the coordinates are converted to int. I already tried to convert to long, but could not manage yet.
pParameters[0] : x0
pParameters[1] : y0
pParameters[2] : radius

RECT rect;
rect.left = (long)( x1 + p_pProfile->pParameters[0]-p_pProfile->pParameters[2] );
rect.right = (long)( x1 + p_pProfile->pParameters[0]+p_pProfile->pParameters[2] );
rect.top = (long)( y1 + p_pProfile->pParameters[1]-p_pProfile->pParameters[2] );
rect.bottom = (long)( y1 + p_pProfile->pParameters[1]+p_pProfile->pParameters[2] );
dc->Ellipse(&rect);

This way it is too inaccurate. :cool:
 
Hmm, well, first of all my graphics knowledge is almost non-existent. I once wrote a simple graphics app with MFC, but I find writing DCOM server apps a lot easier :) If you really want to get into this using the native Windows API I suggest getting a copy of Petzold's Programming Windows.

As far as your example is concerned, I'm not sure quite what you mean by shifted. The default mapping mode is MM_TEXT i.e., pixels, which is maybe OK if you're just writing to the screen. My example draws a pretty good circle about 1" across at the top left of the window using defaults on a 1024*768 17" display.

Also, you don't say what your parameters are. Ellipse takes ints (and an int is the same size as a long in VC++) so you don't have much choice there, although of course you can change the mapping mode to get more (and device independent) resolution. You can change the axis scaling which can distort things a bit, depending...Rounding a float to an int/long in C++ just truncates the bit after the decimal point; Unless you're multiplying or dividing I don't think rounding errors are going to be very noticeable. You can always just add 0.5 before converting.
 
The parameters are resulting from a searching procedure. Although the parameters are allright, the circle does not fit onto the shape (circle) that I have searched for. As you already mentioned Ellipse takes integers for parameters. I suppose this is the reason that the circle drawn above the original one, is shifted. Adding 0.5 did not help. It's the same.
Anyway, thanks for your help.
:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top