exp24_1view.cpp

来自「mfc实验例题也是高教得配套资料 刚找到得 这部分应该是自学的内容」· C++ 代码 · 共 154 行

CPP
154
字号
// Exp24_1View.cpp : implementation of the CExp24_1View class
//

#include "stdafx.h"
#include "Exp24_1.h"

#include "Exp24_1Doc.h"
#include "Exp24_1View.h"
#include "graphdlg.h"
#include "line.h"
#include "circle.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CExp24_1View

IMPLEMENT_DYNCREATE(CExp24_1View, CView)

BEGIN_MESSAGE_MAP(CExp24_1View, CView)
	//{{AFX_MSG_MAP(CExp24_1View)
	ON_COMMAND(ID_INPUT, OnGraph)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExp24_1View construction/destruction

CExp24_1View::CExp24_1View()
{
	// TODO: add construction code here

}

CExp24_1View::~CExp24_1View()
{
}

BOOL CExp24_1View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CExp24_1View drawing

void CExp24_1View::OnDraw(CDC* pDC)
{
	CExp24_1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	pDC->SelectStockObject(NULL_BRUSH);//选择空画刷,使图形透明
	POSITION pos;
	CElement *elem;
	pos = m_pViewList->GetHeadPosition();
	while(pos!=NULL){  //画出链表中所有图形
			elem = (CElement*)m_pViewList->GetAt(pos);
			elem->Draw(pDC);
			m_pViewList->GetNext(pos);
	}

}

/////////////////////////////////////////////////////////////////////////////
// CExp24_1View printing

BOOL CExp24_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CExp24_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CExp24_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CExp24_1View diagnostics

#ifdef _DEBUG
void CExp24_1View::AssertValid() const
{
	CView::AssertValid();
}

void CExp24_1View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CExp24_1Doc* CExp24_1View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExp24_1Doc)));
	return (CExp24_1Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CExp24_1View message handlers

void CExp24_1View::OnGraph() 
{
	// TODO: Add your command handler code here
		CGraphDlg dlg;
		if((dlg.DoModal())==IDOK){
		m_color = RGB(dlg.m_intRed,dlg.m_intGreen,dlg.m_intBlue);
		m_type = dlg.m_intType ; //设置类型
		if(m_type ==0){             //构造直线
			CLine *pLine = new CLine(dlg.m_intX1,dlg.m_intY1,dlg.m_intX2,dlg.m_intY2);
			pLine->SetColor(m_color);  //设置颜色
			m_position = m_pViewList->AddTail(pLine);   //添加至链表
		}
		else {  //构造圆
			CCircle *pCircle = new CCircle(dlg.m_intX1,dlg.m_intY1,dlg.m_intX2);
			pCircle->SetColor(m_color);  //设置颜色
			m_position = m_pViewList->AddTail(pCircle);   //添加至链表
		}
		}
		Invalidate();
	CExp24_1Doc* pDoc = GetDocument();
	pDoc->SetModifiedFlag();
	pDoc->UpdateAllViews(this);	
}

void CExp24_1View::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	CView::OnInitialUpdate();
	CExp24_1Doc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);

	m_pViewList = &(pDoc->m_elemList);
		m_position = m_pViewList->GetHeadPosition();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?