void CMyDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bDraw=false;
CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
m_penWidth=pFrame->m_pWidth; //获得画笔的宽度
m_nColor=pFrame->m_Color; //获取画笔的颜色
CClientDC dc(this);
CPen pen(PS_SOLID,m_penWidth,m_nColor); //创建一个选定宽度和颜色的画笔
CPen* pOldpen=dc.SelectObject(&pen); //将画笔选入设备环境
CBrush* pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); //透明的画刷
CBrush* pOldBrush=dc.SelectObject(pBrush); //避免图形的覆盖现象
switch(pFrame->m_DrawType)
{
case 2: //画直线
dc.MoveTo(m_ptOrigin);
dc.LineTo(point); //所画直线并不与上一条直线的终点相连
break;
case 3://画矩形
dc.Rectangle(m_ptOrigin.x,m_ptOrigin.y,point.x,point.y);
break;
case 4://画椭圆
dc.Ellipse(m_ptOrigin.x,m_ptOrigin.y,point.x,point.y);
break;
case 6:
if(((point.x>m_ptOrigin.x)&&(point.y>m_ptOrigin.y)) || ((point.x<m_ptOrigin.x)&&(point.y<m_ptOrigin.y)))
{
point.y = m_ptOrigin.y (point.x-m_ptOrigin.x);
dc.Ellipse(CRect(m_ptOrigin,point));
break;
}
else
{
point.y = m_ptOrigin.y-(point.x-m_ptOrigin.x);
dc.Ellipse(CRect(m_ptOrigin,point));
break;
}
}
dc.SelectObject(pOldpen); //恢复原来的画笔和画刷
dc.SelectObject(pOldBrush); //恢复原来的透明画刷
CMyDrawGraph *pGraph = new CMyDrawGraph(pFrame->m_DrawType,m_ptOrigin,point,m_penWidth,m_nColor,m_strLine);
CMyDrawDoc *pDoc = GetDocument();//将所画图形记录在数组类
pDoc->m_bArray.Add(pGraph);
OnPrepareDC(&dc);
dc.DPtoLP(&m_ptOrigin);
dc.DPtoLP(&point);
CScrollView::OnLButtonUp(nFlags, point);
}
评论