MFC基礎之橢圓、多邊形及餅圖


void CGraphView::OnLButtonDown(UINT nFlags, CPoint point)
this

{spa

// TODO:  在此添加消息處理程序代碼和/或調用默認值code

CClientDC dc(this);ip


//dc.Rectangle(10, 10, 200, 100);//畫矩形,參數爲左上角座標和右下角座標it


CRect rect(10, 10, 100, 100);class

dc.Rectangle(rect);//畫矩形程序

//dc.Ellipse(rect);//矩形內畫橢圓im


//dc.Arc(10, 10, 200, 100, 0, 0, 80, 200);//畫圓弧,橢圓的一部分,(0, 0)是原點 它與橢圓中心連線img

//10, 10, 200, 100決定矩形//80是橫座標, 200是縱座標, (80, 200)餘橢圓中心連線di

//兩條線之間的橢圓部分就是圓弧

//dc.Arc(10, 10, 200, 100, 80, 200, 0, 0);//另外一部分圓弧


CPoint p1(300, 10000);

CPoint p2(-500, -500);

dc.Arc(rect, p1, p2);


//畫餅形圖

dc.Pie(rect, p1, p2);

CView::OnLButtonDown(nFlags, point);


//畫弦

dc.Chord(rect, p1, p2);

}

void CGraphView::OnPaint()

{

CPaintDC dc(this); // device context for painting

// TODO:  在此處添加消息處理程序代碼

// 不爲繪圖消息調用 CView::OnPaint()


int nRevenues[4] = { 125, 376, 252, 184 };

CRect rect;

GetClientRect(&rect);//獲得客戶區大小


dc.SetViewportOrg(rect.Width()/2, rect.Height()/2);//改變原點

int nTotal = 0;

for (int i = 0; i < 4; i++)

nTotal += nRevenues[i];


int x1 = 0;

int y1 = -1000;


int nSum = 0;


for (int i = 0; i < 4; i++)

{

nSum += nRevenues[i];

double rad = ((double)(nSum * 2 * PI / (double)nTotal) + PI);//默認垂直向下爲正

int x2 = (int)(sin(rad) * 1000);

int y2 = (int)(cos(rad) * 1000 * 3)/4;

dc.Pie(-200, -150, 200, 150, x1, y1, x2, y2);

x1 = x2;

y1 = y2;

}

}

相關文章
相關標籤/搜索