用MFC畫橢圓

來源:互聯網
上載者:User

標籤:介面   mfc   圖形   

    編寫一個單一文件介面程式,該程式在使用者區能以在兩個矩形的相交地區為外接矩形畫一個橢圓。效果如下:

 

 

1)用MFC AppWizard[exe],建立一個名稱為RecRec的單文檔應用程式。

2)在視圖類CRecRecView的聲明中,添加兩個成員變數: 

public:CRect m_rRect2;CRect m_rRect1;

3)在視圖類CRecRecView的建構函式CRecRecView()中,初始化資料成員:

CRecRecView::CRecRecView():m_rRect1(50,50,250,200),m_rRect2(100,120,300,350){// TODO: add construction code here}

4)在視圖類的OnDraw函數中,寫入如下代碼:

void CRecRecView::OnDraw(CDC* pDC){CRecRecDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereCClientDC dc(this);//建立一個空畫刷CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));//將畫刷選入裝置描述表CBrush *pOldBrush = dc.SelectObject(pBrush);int x1,y1;int x2,y2;dc.Rectangle(m_rRect1);dc.Rectangle(m_rRect2);//選出交叉地區的左上方if(m_rRect1.left<m_rRect2.left)x1=m_rRect2.left;elsex1=m_rRect1.left;if(m_rRect1.top<m_rRect2.top)y1=m_rRect2.top;elsey1=m_rRect1.top;//選出交叉地區的右下角if(m_rRect1.right<m_rRect2.right)x2=m_rRect1.right;elsex2=m_rRect2.right;if(m_rRect1.bottom<m_rRect2.bottom)y2=m_rRect1.bottom;elsey2=m_rRect2.bottom;//以交叉地區為橢圓的外接矩形pDC->Ellipse(x1,y1,x2,y2);}




 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.