CDC::Arc以及画一个电抗器

    xiaoxiao2023-03-28  6

    参考:MSDN

    Draws an elliptical arc.//画一个椭圆曲线

    语法

    BOOL Arc( int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4 ); BOOL Arc( LPCRECT lpRect, POINT ptStart, POINT ptEnd );

    参数

    x1

    Specifies the x-coordinate of the upper-left corner of the bounding rectangle (in logical units).//矩形边界的x1

    y1

    Specifies the y-coordinate of the upper-left corner of the bounding rectangle (in logical units).//矩形边界的y1

    x2

    Specifies the x-coordinate of the lower-right corner of the bounding rectangle (in logical units).//矩形边界的x2

    y2

    Specifies the y-coordinate of the lower-right corner of the bounding rectangle (in logical units).//矩形边界的y2

    x3

    Specifies the x-coordinate of the point that defines the arc's starting point (in logical units). This point does not have to lie exactly on the arc.

    //曲线的起点x3,不需要这个点在曲线上

    y3

    Specifies the y-coordinate of the point that defines the arc's starting point (in logical units). This point does not have to lie exactly on the arc.

    //曲线的起点y3,不需要这个点在曲线上

    x4

    Specifies the x-coordinate of the point that defines the arc's endpoint (in logical units). This point does not have to lie exactly on the arc.

    //曲线的终点x4,不需要这个点在曲线上

    y4

    Specifies the y-coordinate of the point that defines the arc's endpoint (in logical units). This point does not have to lie exactly on the arc.

    //曲线的终点y4,不需要这个点在曲线上

    lpRect

    Specifies the bounding rectangle (in logical units). You can pass either an LPRECT or a CRect object for this parameter.

    ptStart

    Specifies the x- and y-coordinates of the point that defines the arc's starting point (in logical units). This point does not have to lie exactly on the arc. You can pass either a POINT structure or a CPoint object for this parameter.

    ptEnd

    Specifies the x- and y-coordinates of the point that defines the arc's ending point (in logical units). This point does not have to lie exactly on the arc. You can pass either a POINT structure or a CPoint object for this parameter.

    返回值

    Nonzero if the function is successful; otherwise 0.//执行成功返回值非0,否则返回0

    备注

    The arc drawn by using the function is a segment of the ellipse defined by the specified bounding rectangle.

    曲线是被矩形限制的椭圆的一部分。

    The actual starting point of the arc is the point at which a ray drawn from the center of the bounding rectangle through the specified starting point intersects the ellipse. The actual ending point of the arc is the point at which a ray drawn from the center of the bounding rectangle through the specified ending point intersects the ellipse. The arc is drawn in a counterclockwise direction. Since an arc is not a closed figure, it is not filled. Both the width and height of the rectangle must be greater than 2 units and less than 32,767 units.

    曲线是由如下方式分割的椭圆的一段:由矩形的中心点分别做经过起点、终点的两根射线,将椭圆分为两部分。从起点射线开始,经逆时针旋转到达终点射线的椭圆的一段曲线。

    曲线没有填充属性,矩形的宽和高必须在2~32767之间

    示例

    C++ void CDCView::DrawArc(CDC* pDC) { // Fill the client area with a thin circle. The circle's // interior is not filled. The circle's perimeter is // blue from 6 o'clock to 3 o'clock and red from 3 // o'clock to 6 o'clock. // Get the client area. CRect rectClient; GetClientRect(rectClient); // Make a couple of pens. CPen penBlue; CPen penRed; CPen* pOldPen; penBlue.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(0, 0, 255)); penRed.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(255, 0, 0)); // Draw from 3 o'clock to 6 o'clock, counterclockwise, // in a blue pen. pOldPen = pDC->SelectObject(&penBlue); pDC->Arc(rectClient, CPoint(rectClient.right, rectClient.CenterPoint().y), CPoint(rectClient.CenterPoint().x, rectClient.right)); // Draw from 6 o'clock to 3 o'clock, counterclockwise, // in a red pen. pDC->SelectObject(&penRed); // Keep the same parameters, but reverse start // and end points. pDC->Arc(rectClient, CPoint(rectClient.CenterPoint().x, rectClient.right), CPoint(rectClient.right, rectClient.CenterPoint().y)); // Restore the previous pen. pDC->SelectObject(pOldPen); }

    要求

    Header: afxwin.h

    请参阅

    CDC 类 层次结构图 CDC::Chord Arc POINT 结构 RECT 结构

    //画电抗器代码

    void CFunction::DrawVerinductance(CDC *pDC,int i,COLORREF col_pen,CRect rect) { CPen pen(PS_SOLID,i,col_pen),*pOldPen; pOldPen=pDC->SelectObject(&pen);         //这里画4个小圆弧 for (int j=0;j<4;j++) { CRect rt; rt.left=rect.left; rt.top=rect.top+j*rect.Height()/4; rt.right=rect.right; rt.bottom=rt.top+rect.Height()/4; pDC->Arc(rt,CPoint(rt.right,rt.bottom),CPoint(rt.left,rt.top)); } DrawLine(pDC,i,col_pen,CPoint(rect.right+2,rect.top),CPoint(rect.right+2,rect.bottom));//圆弧上画一条直线 pDC->SelectObject(pOldPen); pen.DeleteObject(); }

    转载请注明原文地址: https://ju.6miu.com/read-1209315.html
    最新回复(0)