📄 画图view.cpp
字号:
// 画图View.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "画图.h"
#include "画图Doc.h"
#include "画图View.h"
#include "StudentInfo1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_WIDTH2, OnWidth2)
ON_COMMAND(ID_WIDTH4, OnWidth4)
ON_COMMAND(ID_GREEN, OnGreen)
ON_COMMAND(ID_LINE, OnLine)
ON_COMMAND(ID_RECT, OnRect)
ON_COMMAND(ID_RED, OnRed)
ON_WM_PAINT()
ON_COMMAND(ID_STUDENT, OnStudent)
ON_UPDATE_COMMAND_UI(ID_SJ, OnUpdateSj)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction
CMyView::CMyView()
{
// TODO: add construction code here
tuxing=1;
}
CMyView::~CMyView()
{
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMyView printing
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMyDoc *pDoc=GetDocument();
pDoc->l.SetStart(point);
pDoc->l.SetEnd(point);
pDoc->r.SetStart(point);
pDoc->r.SetEnd(point);
e=s=point;
pDoc->UpdateAllViews(this,0,NULL);
CView::OnLButtonDown(nFlags, point);
}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMyDoc *pDoc=GetDocument();
pDoc->l.SetEnd(point);
CClientDC dc(this);
w=pDoc->l.GetWidth();
c=pDoc->l.GetColor();
CPen pen(PS_SOLID,w,c),*oldPen;
oldPen=dc.SelectObject(&pen);
if(tuxing==1)
{
dc.MoveTo(s);
pDoc->l.SetEnd(point);
dc.LineTo(pDoc->l.GetEnd());
pDoc->UpdateAllViews(this,0,NULL);
}
else if(tuxing==2)
{
dc.Rectangle(pDoc->r.GetStart().x,pDoc->r.GetStart().y,pDoc->r.GetEnd().x,pDoc->r.GetEnd().y);
}
CView::OnLButtonUp(nFlags, point);
}
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMyDoc *pDoc=GetDocument();
CClientDC dc(this);
CPen pen(PS_SOLID,w,RGB(255,0,0)),*oldPen;
oldPen=dc.SelectObject(&pen);
dc.SetROP2(R2_NOT);
if(nFlags==MK_LBUTTON)
{
if(tuxing==1)
{
dc.MoveTo(s);
dc.LineTo(pDoc->l.GetEnd());
dc.MoveTo(s);
dc.LineTo(point);
pDoc->l.SetEnd(point);
pDoc->UpdateAllViews(this,0,NULL);
}
else if(tuxing==2)
{
dc.Rectangle(pDoc->r.GetStart().x,pDoc->r.GetStart().y,pDoc->r.GetEnd().x,pDoc->r.GetEnd().y);
dc.Rectangle(pDoc->r.GetStart().x,pDoc->r.GetStart().y,point.x,point.y);
pDoc->r.SetEnd(point);
}
}
dc.SelectObject(oldPen);
CView::OnMouseMove(nFlags, point);
}
void CMyView::OnWidth2()
{
// TODO: Add your command handler code here
CMyDoc *p=GetDocument();
p->l.SetWidth(2);
}
void CMyView::OnWidth4()
{
// TODO: Add your command handler code here
CMyDoc *p=GetDocument();
p->l.SetWidth(4);
}
void CMyView::OnGreen()
{
// TODO: Add your command handler code here
CMyDoc *p=GetDocument();
COLORREF c=RGB(0,255,0);
p->l.SetColor(c);
}
void CMyView::OnLine()
{
// TODO: Add your command handler code here
tuxing=1;
}
void CMyView::OnRect()
{
// TODO: Add your command handler code here
tuxing=2;
}
BOOL CMyView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// TODO: Add your specialized code here and/or call the base class
return CView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
void CMyView::OnRed()
{
// TODO: Add your command handler code here
CMyDoc *p=GetDocument();
COLORREF c=RGB(255,0,0);
p->l.SetColor(c);
}
void CMyView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CView::OnPaint() for painting messages
}
void CMyView::OnStudent()
{
// TODO: Add your command handler code here
CStudentInfo1 stu;
CMyDoc *pdoc=GetDocument();
CClientDC dc(this);
if(stu.DoModal()==IDOK)
{
CString n=stu.m_name;
dc.TextOut(0,0,n);
}
}
void CMyView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
CMyDoc *pDoc=GetDocument();
s=pDoc->l.GetStart();
e=pDoc->l.GetEnd();
c=pDoc->l.GetColor();
w=pDoc->l.GetWidth();
UpdateData(FALSE);
}
void CMyView::OnUpdateSj(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -