?? exp31_2view.cpp
字號:
// Exp31_2View.cpp : implementation of the CExp31_2View class
//
#include "stdafx.h"
#include "Exp31_2.h"
#include "Exp31_2Doc.h"
#include "Exp31_2View.h"
#include "graphdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExp31_2View
IMPLEMENT_DYNCREATE(CExp31_2View, CView)
BEGIN_MESSAGE_MAP(CExp31_2View, CView)
//{{AFX_MSG_MAP(CExp31_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()
/////////////////////////////////////////////////////////////////////////////
// CExp31_2View construction/destruction
CExp31_2View::CExp31_2View()
{
// TODO: add construction code here
}
CExp31_2View::~CExp31_2View()
{
}
BOOL CExp31_2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CExp31_2View drawing
void CExp31_2View::OnDraw(CDC* pDC)
{
CExp31_2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPen pen(PS_SOLID,0,m_color); //構(gòu)造當(dāng)前顏色的畫筆
CPen *oldPen;
oldPen = pDC->SelectObject(&pen); //為CDC選中當(dāng)前畫筆
if(m_type == 0){ //畫直線
pDC->MoveTo(m_start);
pDC->LineTo(m_end);
}
else if(m_type ==1){ //畫圓
CRect rect(m_start.x - m_radius,m_start.y -m_radius,
m_start.x + m_radius,m_start.y + m_radius);
pDC->Ellipse(&rect);
}
pDC->SelectObject(oldPen);
}
/////////////////////////////////////////////////////////////////////////////
// CExp31_2View printing
BOOL CExp31_2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CExp31_2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CExp31_2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CExp31_2View diagnostics
#ifdef _DEBUG
void CExp31_2View::AssertValid() const
{
CView::AssertValid();
}
void CExp31_2View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CExp31_2Doc* CExp31_2View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExp31_2Doc)));
return (CExp31_2Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExp31_2View message handlers
void CExp31_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_start.x = dlg.m_intX1 ;
m_start.y = dlg.m_intY1;
m_type = dlg.m_intType ; //確定類型
if(m_type ==0){ //直線
m_end.x = dlg.m_intX2 ;
m_end.y = dlg.m_intY2;
}
else m_radius = dlg.m_intX2; //圓
}
Invalidate(); //使視圖重畫,調(diào)用OnDraw函數(shù)
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -