I want to reuse DrawPie function to draw 4 same pies, but it was unexpected. I don't understand what have been happening.
I divide the client area by 4, then pass each rect to DrawPie.

I suspect setWindowOrigin or setViewportOrigin is needed.

application image: http://i240.photobucket.com/albums/f...214/post-1.jpg

Code:
void CMainWindow::DrawPie(CDC *pDC, CRect &rect)
{
	// prepare to draw pie
	CBrush brush;
	brush.CreateHatchBrush(HS_BDIAGONAL, RGB(255, 0, 0));
	CBrush *pOldBrush = pDC->SelectObject(&brush);

	CPoint startPoint = rect.BottomRight();
	CPoint endPoint = rect.BottomRight();
	startPoint.y /= 2;
	endPoint.x /= 2;

	// draw pie
	pDC->Pie(&rect, startPoint, endPoint);

	pDC->SelectObject(pOldBrush);
}

void CMainWindow::OnPaint()
{
	CPaintDC dc(this);
	CRect rect;
	GetClientRect(&rect);	
	
	
	int leftCenter = rect.left / 2;
	int topCenter = rect.top / 2;
	int rightCenter = rect.right / 2;
	int bottomCenter = rect.bottom / 2;

	COLORREF clrColors[] = {RGB(100, 0, 0), RGB(0, 100, 0), RGB(0, 0, 100), RGB(100, 0, 100)};
	int widthIncrement = rect.right / 2;
	int heightIncrement = rect.bottom / 2;
	int k = 0;
	for(int i = 0; i < rect.bottom; i += heightIncrement)
		for(int j = 0; j < rect.right; j += widthIncrement)
		{
			CPoint leftTop(j, i);
			CPoint rightBottom(j + widthIncrement, i + heightIncrement);

			CRect rect;
			rect.TopLeft() = leftTop;
			rect.BottomRight() = rightBottom;

			CBrush brush;
			brush.CreateSolidBrush(clrColors[k++]);
			CBrush *pOldBrush = dc.SelectObject(&brush);
			dc.Rectangle(rect);

			DrawPie(&dc, rect);
			dc.SelectObject(pOldBrush);
		}	
}
Thank you