GDIViewView 绘制
void CMyGDIViewView::OnDraw(CDC* pDC)
{
CMyGDIViewDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CRect rc;
GetClientRect(rc);
pDC->SetMapMode(MM_LOENGLISH);
DrawTree(pDC, rc.right / 2, -rc.bottom, (double)rc.bottom * 0.2, 1.57, 10);
}
int CMyGDIViewView::DrawTree(CDC* pDC, int xStart, int yStart, double length, double angle, int num)
{
int xEnd, yEnd;
if(num == 0) return 1;
xEnd = xStart + (int)(length * cos(angle));
yEnd = yStart + (int)(length * sin(angle));
//
pDC->MoveTo(xStart, yStart);
pDC->LineTo(xEnd, yEnd);
//left
DrawTree(pDC, xEnd, yEnd, length * 0.6, angle + 0.624, num - 1);
//middle
DrawTree(pDC, xEnd, yEnd, length * 0.85, angle + 0.08, num - 1);
//right
DrawTree(pDC, xEnd, yEnd, length * 0.65, angle - 0.6, num - 1);
return 1;
}