用MFC画椭圆

来源:互联网 发布:oracle sql 重复数据 编辑:程序博客网 时间:2024/05/02 04:22

    编写一个单文档界面程序,该程序在用户区能以在两个矩形的相交区域为外接矩形画一个椭圆。效果如下:

 

 

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);}




 

4 0
原创粉丝点击