📄 exp32_2view.cpp
字号:
// Exp32_2View.cpp : implementation of the CExp32_2View class
//
#include "stdafx.h"
#include "Exp32_2.h"
#include "Exp32_2Doc.h"
#include "Exp32_2View.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
/////////////////////////////////////////////////////////////////////////////
// CExp32_2View
IMPLEMENT_DYNCREATE(CExp32_2View, CView)
BEGIN_MESSAGE_MAP(CExp32_2View, CView)
//{{AFX_MSG_MAP(CExp32_2View)
ON_COMMAND(ID_GRAPH, 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()
/////////////////////////////////////////////////////////////////////////////
// CExp32_2View construction/destruction
CExp32_2View::CExp32_2View()
{
// TODO: add construction code here
}
CExp32_2View::~CExp32_2View()
{
}
BOOL CExp32_2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CExp32_2View drawing
void CExp32_2View::OnDraw(CDC* pDC)
{
CExp32_2Doc* 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);
}
}
/////////////////////////////////////////////////////////////////////////////
// CExp32_2View printing
BOOL CExp32_2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CExp32_2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CExp32_2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CExp32_2View diagnostics
#ifdef _DEBUG
void CExp32_2View::AssertValid() const
{
CView::AssertValid();
}
void CExp32_2View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CExp32_2Doc* CExp32_2View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExp32_2Doc)));
return (CExp32_2Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExp32_2View message handlers
void CExp32_2View::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(); //使视图重画,调用OnDraw函数
}
void CExp32_2View::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CExp32_2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
m_pViewList = &( pDoc->m_elemList);
m_position = m_pViewList->GetHeadPosition();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -