📄 exp33_1view.cpp
字号:
// Exp33_1View.cpp : implementation of the CExp33_1View class
//
#include "stdafx.h"
#include "Exp33_1.h"
#include "Exp33_1Doc.h"
#include "Exp33_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
/////////////////////////////////////////////////////////////////////////////
// CExp33_1View
IMPLEMENT_DYNCREATE(CExp33_1View, CView)
BEGIN_MESSAGE_MAP(CExp33_1View, CView)
//{{AFX_MSG_MAP(CExp33_1View)
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()
/////////////////////////////////////////////////////////////////////////////
// CExp33_1View construction/destruction
CExp33_1View::CExp33_1View()
{
// TODO: add construction code here
}
CExp33_1View::~CExp33_1View()
{
}
BOOL CExp33_1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CExp33_1View drawing
void CExp33_1View::OnDraw(CDC* pDC)
{
CExp33_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);
}
}
/////////////////////////////////////////////////////////////////////////////
// CExp33_1View printing
BOOL CExp33_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CExp33_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CExp33_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CExp33_1View diagnostics
#ifdef _DEBUG
void CExp33_1View::AssertValid() const
{
CView::AssertValid();
}
void CExp33_1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CExp33_1Doc* CExp33_1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExp33_1Doc)));
return (CExp33_1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExp33_1View message handlers
void CExp33_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();
CExp33_1Doc* pDoc = GetDocument();
pDoc->SetModifiedFlag(); //为文档设置修改标志
pDoc->UpdateAllViews(this); //更新文档的所有视图类
}
void CExp33_1View::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CExp33_1Doc* 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 + -