Jalaj

February 17, 2007

WinAPI Elliptical Arc Functions

Filed under: Visual Basic, WinAPI — Jalaj @ 10:01 am

While AngleArc drew a circular arc, there are functions Arc and ArcTo that can help you draw an elliptical arc. Both the functions take same set of parameters and the output too is same for the functions. The Arc function exists for all versions of Windows but the Development team found a point of concern that led to introduction of the second function ArcTo which exists in Windows 2000 and above only.

The problem with the previous function was that unlike other drawing functions the Arc function did not update the current pen location of the device context and it remained where it was prior to calling the function, and all drawings functions continued from that point onwards. To maintain the backward compatibility and at the same time address the issue the ArcTo function was introduced.

The first parameter that the function takes is the handle to the device context. The next four parameters are the X and Y co-ordinates of Top-Left and Botton-Right corners of the rectangle that bounds the Ellipse of which the arc we are going to draw is a part of.

arc.jpg

The next two parameters are passed to determine the starting point of the arc. The point of intersection of the ellipse and the line joining the center point of the ellipse to the point passed by these parameter (extended if required) is taken as the starting point for drawing the arc.

Similarly the next two parameters are passed to determine the end point of the arc. The arc is drawn from the starting point to the end point traveling in anti-clockwise direction. If you give same co-ordinates for the starting as well as end point, you will end up with a full ellipse So you don’t need to learn another function to draw ellipse  )

Public Declare Function Arc Lib "gdi32" (ByVal hdc As Long, _
    ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, _
    ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long

As already described while the above function Arc will not change the current drawing point on the device context the function ArcTo defined below will change the current point to the end point of the arc.

Public Declare Function ArcTo Lib "gdi32" (ByVal hdc As Long, _
    ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, _
    ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long

2 Comments »

  1. [...] Filed under: WinAPI, Visual Basic — Jalaj @ 10:04 am As already described in WinAPI Elliptical Arc Functions the arc are drawn from the starting point to the end point in ConterClockwise (or Anti-Clockwise) [...]

    Pingback by GetArcDirection and SetArcDirection functions « Jalaj — February 23, 2007 @ 10:18 am

  2. [...] WinAPI Elliptical Arc Functions [...]

    Pingback by The Blog Revisited - 6 « Jalaj — October 31, 2007 @ 8:32 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.