次の方法で共有


CRect::CenterPoint

更新 : 2007 年 11 月

左右の座標を加算した後 2 で割り、上下の座標を加算した後 2 で割って CRect の中心座標を計算します。

CPoint CenterPoint( ) const throw( );

戻り値

CRect の中心座標が入っている CPoint オブジェクトを返します。

使用例

// Code from this OnPaint() implementation can be pasted into your own application
// to draw lines that would look like a letter "Y" within your dialog. 
void CMyDlg::OnPaint()
{
   CPaintDC dc(this); // device context for painting

   // get the size and position of the client area of 
   // your window

   CRect rect;
   GetClientRect(&rect);

   // Move the current pen to the top left of the window. We call the
   // TopLeft() member of CRect here and it returns a CPoint object we
   // pass to the override of CDC::MoveTo() that accepts a CPoint.

   dc.MoveTo(rect.TopLeft());

   // Draw a line from the top left to the center of the window.
   // CenterPoint() gives us the middle point of the window as a
   // CPoint, and since CDC::LineTo() has an override that accepts a
   // CPoint, we can just pass it along.

   dc.LineTo(rect.CenterPoint());

   // Now, draw a line to the top right of the window. There's no
   // CRect member which returns a CPoint for the top right of the
   // window, so we'll reference the CPoint members directly and call
   // the CDC::LineTo() override which takes two integers.

   dc.LineTo(rect.right, rect.top);

   // The top part of the "Y" is drawn. Now, we'll draw the stem. We
   // start from the center point.

   dc.MoveTo(rect.CenterPoint());

   // and then draw to the middle of the bottom edge of the window.
   // We'll get the x-coordinate from the x member of the CPoint
   // returned by CenterPoint(), and the y value comes directly from
   // the rect.

   dc.LineTo(rect.CenterPoint().x, rect.bottom);
}

必要条件

ヘッダー : atltypes.h

参照

参照

CRect クラス

階層図

CRect::Width

CRect::Height

CRect::Size

CRect::TopLeft

CRect::BottomRight

CRect::IsRectNull

CPoint クラス

その他の技術情報

CRect のメンバ