void CRestartManagerDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CRestartManagerDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CArray<CBubble,CBubble&>& m_Array = pDoc->GetBubbleArray();
// 以当前鼠标点击点为圆心,随机半径构造一个CBubble对象,并添加到文档中
m_Array.Add( CBubble( point, rand()%30 ));
// 更新视图显示
Invalidate();
CView::OnLButtonDown(nFlags, point);
}
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CRestartManagerDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CArray<CBubble,CBubble&>& m_Array = pDoc->GetBubbleArray();
// 以当前鼠标点击点为圆心,随机半径构造一个CBubble对象,并添加到文档中
m_Array.Add( CBubble( point, rand()%30 ));
// 更新视图显示
Invalidate();
CView::OnLButtonDown(nFlags, point);
}
然后,我们将这些数据在视图中显示出来:
void CRestartManagerDemoView::OnDraw(CDC* pDC)
{
CRestartManagerDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
// 从文档中得到数据
CArray<CBubble,CBubble&>& m_Array = pDoc->GetBubbleArray();
// 显示数据
for(int nIndex = 0; nIndex < m_Array.GetSize(); ++nIndex )
{
CBubble tempBubble = m_Array.GetAt( nIndex );
pDC->Ellipse(tempBubble.m_nCenterPoint.x - tempBubble.m_fR,
tempBubble.m_nCenterPoint.y - tempBubble.m_fR,
tempBubble.m_nCenterPoint.x + tempBubble.m_fR,
tempBubble.m_nCenterPoint.y + tempBubble.m_fR);
}
}
{
CRestartManagerDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
// 从文档中得到数据
CArray<CBubble,CBubble&>& m_Array = pDoc->GetBubbleArray();
// 显示数据
for(int nIndex = 0; nIndex < m_Array.GetSize(); ++nIndex )
{
CBubble tempBubble = m_Array.GetAt( nIndex );
pDC->Ellipse(tempBubble.m_nCenterPoint.x - tempBubble.m_fR,
tempBubble.m_nCenterPoint.y - tempBubble.m_fR,
tempBubble.m_nCenterPoint.x + tempBubble.m_fR,
tempBubble.m_nCenterPoint.y + tempBubble.m_fR);
}
}
这样,我们就实现了一个简单的支持重启管理器的文档视图类型的MFC应用程序。这个程序可以通过鼠标在视图中点击向文档中添加数据,然后这些数据可以保存和重新打开。void CRestartManagerDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CRestartManagerDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CArray<CBubble,CBubble&>& m_Array = pDoc->GetBubbleArray();
// 以当前鼠标点击点为圆心,随机半径构造一个CBubble对象,并添加到文档中
m_Array.Add( CBubble( point, rand()%30 ));
// 更新视图显示
Invalidate();
CView::OnLButtonDown(nFlags, point);
}
然后,我们将这些数据在视图中显示出来:
void CRestartManagerDemoView::OnDraw(CDC* pDC)
{
CRestartManagerDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
// 从文档中得到数据
CArray<CBubble,CBubble&>& m_Array = pDoc->GetBubbleArray();
// 显示数据
for(int nIndex = 0; nIndex < m_Array.GetSize(); ++nIndex )
{
CBubble tempBubble = m_Array.GetAt( nIndex );
pDC->Ellipse(tempBubble.m_nCenterPoint.x - tempBubble.m_fR,
tempBubble.m_nCenterPoint.y - tempBubble.m_fR,
tempBubble.m_nCenterPoint.x + tempBubble.m_fR,
tempBubble.m_nCenterPoint.y + tempBubble.m_fR);
}
}
// TODO: 在此添加消息处理程序代码和/或调用默认值
CRestartManagerDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CArray<CBubble,CBubble&>& m_Array = pDoc->GetBubbleArray();
// 以当前鼠标点击点为圆心,随机半径构造一个CBubble对象,并添加到文档中
m_Array.Add( CBubble( point, rand()%30 ));
// 更新视图显示
Invalidate();
CView::OnLButtonDown(nFlags, point);
}
然后,我们将这些数据在视图中显示出来:
void CRestartManagerDemoView::OnDraw(CDC* pDC)
{
CRestartManagerDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
// 从文档中得到数据
CArray<CBubble,CBubble&>& m_Array = pDoc->GetBubbleArray();
// 显示数据
for(int nIndex = 0; nIndex < m_Array.GetSize(); ++nIndex )
{
CBubble tempBubble = m_Array.GetAt( nIndex );
pDC->Ellipse(tempBubble.m_nCenterPoint.x - tempBubble.m_fR,
tempBubble.m_nCenterPoint.y - tempBubble.m_fR,
tempBubble.m_nCenterPoint.x + tempBubble.m_fR,
tempBubble.m_nCenterPoint.y + tempBubble.m_fR);
}
}
这样,我们就实现了一个简单的支持重启管理器的文档视图类型的MFC应用程序。这个程序可以通过鼠标在视图中点击向文档中添加数据,然后这些数据可以保存和重新打开。