你好,看到你回答一个问题,有MFC画图的保存和打开的源程序,能发给我学习下吗?谢谢~~
发布网友
发布时间:2022-04-27 00:51
我来回答
共2个回答
热心网友
时间:2023-11-14 17:02
重新定义一个类,用这个类来保存画图的类型,起点,终点:
class CGraph
{
public:
UINT m_dwsytle;
CPoint m_dnpt;
CPoint m_uppt;
CGraph();
CGraph(UINT style,CPoint dnpt,CPoint uppt);
virtual ~CGraph();
};
CGraph::CGraph(UINT style,CPoint dnpt,CPoint uppt)
{
m_dwsytle=style;
m_dnpt=dnpt;
m_uppt=uppt;
}
为VIEW类增加:
CPtrArray m_ptrArray;
void CGraphicView::OnLButtonUp(UINT nFlags, CPoint point)中的代码增加下面代码:
CGraph *pgraph=new CGraph(m_dwstyle,m_dnpt,point);
m_ptrArray.Add(pgraph);
void CGraphicView::OnDraw(CDC* pDC)
{
CGraphicDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CClientDC dc(this);
CBrush *pBrush=(CBrush*)dc.SelectStockObject(NULL_BRUSH);
int count=m_ptrArray.GetSize();
for (int i=0;i<count;i++)
{
switch (((CGraph*)m_ptrArray.GetAt(i))->m_dwsytle)
{
case 1:
dc.SetPixel(((CGraph*)m_ptrArray.GetAt(i))->m_dnpt,RGB(255,0,0));
break;
case 2:
dc.MoveTo(((CGraph*)m_ptrArray.GetAt(i))->m_dnpt);
dc.LineTo(((CGraph*)m_ptrArray.GetAt(i))->m_uppt);
break;
case 3:
dc.Rectangle(CRect(((CGraph*)m_ptrArray.GetAt(i))->m_dnpt,
((CGraph*)m_ptrArray.GetAt(i))->m_uppt));
break;
case 4:
dc.Ellipse(CRect(((CGraph*)m_ptrArray.GetAt(i))->m_dnpt,
((CGraph*)m_ptrArray.GetAt(i))->m_uppt));
break;
default:
break;
}
}
dc.SelectObject(pBrush);
// TODO: add draw code for native data here
}
就可以了。
热心网友
时间:2023-11-14 17:02
你邮箱?