CDC::Chord
更新 : 2007 年 11 月
弦 (楕円と線分が交わってできる閉じられた領域) を描画します。
BOOL Chord(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int x4,
int y4
);
BOOL Chord(
LPCRECT lpRect,
POINT ptStart,
POINT ptEnd
);
パラメータ
x1
弦に外接する四角形の左上隅の x 座標 (論理単位)。y1
弦に外接する四角形の左上隅の y 座標 (論理単位)。x2
弦に外接する四角形の右下隅の x 座標 (論理単位)。y2
弦に外接する四角形の右下隅の y 座標 (論理単位)。x3
弦の描画始点の x 座標 (論理単位)。y3
弦の描画始点の y 座標 (論理単位)。x4
弦の終点の x 座標 (論理単位)。y4
弦の終点の y 座標 (論理単位)。lpRect
外接する四角形 (論理単位)。このパラメータには、LPRECT または CRect オブジェクトを渡すことができます。ptStart
弦の描画始点の x 座標および y 座標 (論理単位)。この点は、正確に弦の線上になくてもかまいません。このパラメータには、POINT 構造体または CPoint オブジェクトを渡すことができます。ptEnd
弦の描画終点の x 座標および y 座標 (論理単位)。この点は、正確に弦の線上になくてもかまいません。このパラメータには、POINT 構造体または CPoint オブジェクトを渡すことができます。
戻り値
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。
解説
パラメータ (x1, y1) と (x2, y2) には、それぞれ、弦を構成する楕円を囲む四角形の左上隅と右下隅の座標を指定します。パラメータ (x3, y3) と (x4, y4) は、楕円と交わる線分の両端の点の座標を指定します。弦は現在選択されているペンで描画され、現在選択されているブラシで塗りつぶされます。
Chord 関数を使って描画される図形は、右下隅の座標まで拡張されます。ただし右下隅の座標は含みません。つまり、図形の高さは y2 - y1、図形の幅は x2 - x1 になります。
使用例
void CDCView::DrawChord(CDC* pDC)
{
// Fill the client area with a circle. The circle is
// blue and filled with blue, but has a chord cut out
// of it from 3 o'clock to 6 o'clock. That chord is
// red and filled with a red diagonal hatch.
// Get the client area.
CRect rectClient;
GetClientRect(rectClient);
// Make a couple of pens and similar brushes.
CPen penBlue, penRed;
CBrush brushBlue, brushRed;
CBrush* pOldBrush;
CPen* pOldPen;
brushBlue.CreateSolidBrush(RGB(0, 0, 255));
brushRed.CreateHatchBrush(HS_FDIAGONAL, RGB(255, 0, 0));
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 with a solid blue fill.
pOldPen = pDC->SelectObject(&penBlue);
pOldBrush = pDC->SelectObject(&brushBlue);
pDC->Chord(rectClient,
CPoint(rectClient.right, rectClient.CenterPoint().y),
CPoint(rectClient.CenterPoint().x, rectClient.right));
// Draw the remaining quarter chord from 6 o'clock
// to 3 o'clock, counterclockwise, in a red pen
// with the hatched brush.
pDC->SelectObject(&penRed);
pDC->SelectObject(&brushRed);
// Keep the same parameters, but reverse start and
// end points.
pDC->Chord(rectClient,
CPoint(rectClient.CenterPoint().x, rectClient.right),
CPoint(rectClient.right, rectClient.CenterPoint().y));
// Restore the previous pen.
pDC->SelectObject(pOldPen);
}
必要条件
ヘッダー : afxwin.h