📄 myview.cpp
字号:
// MyView.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "My.h"
#include "MyDoc.h"
#include "MyView.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_COMMAND(ID_WIDTH1, OnWidth1)
ON_UPDATE_COMMAND_UI(ID_WIDTH1, OnUpdateWidth1)
ON_COMMAND(ID_WIDTH3, OnWidth3)
ON_UPDATE_COMMAND_UI(ID_WIDTH3, OnUpdateWidth3)
ON_COMMAND(ID_WIDTH5, OnWidth5)
ON_UPDATE_COMMAND_UI(ID_WIDTH5, OnUpdateWidth5)
ON_COMMAND(ID_WIDTH7, OnWidth7)
ON_UPDATE_COMMAND_UI(ID_WIDTH7, OnUpdateWidth7)
ON_COMMAND(ID_COLOR, OnColor)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}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():m_pointFrom(0,0), m_pointTo(0,0)
{
m_bCaptured = FALSE;
m_colorCurr = RGB(255, 0, 0);
m_nCurrWidth = 3;
// TODO: add construction code here
}
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
for(int i=0; i<pDoc->m_nCount; i++)
pDoc->m_lineList[i].DrawLine(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// 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::OnWidth1()
{
// TODO: Add your command handler code here
m_nCurrWidth = 1;
}
void CMyView::OnUpdateWidth1(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nCurrWidth == 1);
}
void CMyView::OnWidth3()
{
// TODO: Add your command handler code here
m_nCurrWidth = 3;
}
void CMyView::OnUpdateWidth3(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nCurrWidth == 3);
}
void CMyView::OnWidth5()
{
// TODO: Add your command handler code here
m_nCurrWidth = 5;
}
void CMyView::OnUpdateWidth5(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nCurrWidth == 5);
}
void CMyView::OnWidth7()
{
// TODO: Add your command handler code here
m_nCurrWidth = 7;
}
void CMyView::OnUpdateWidth7(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nCurrWidth == 7);
}
void CMyView::OnColor()
{
// TODO: Add your command handler code here
CColorDialog dlg(m_colorCurr);
if(dlg.DoModal() == IDOK)
m_colorCurr = dlg.GetColor();
}
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_pointFrom = m_pointTo = point;
SetCapture();
m_bCaptured = TRUE;
CView::OnLButtonDown(nFlags, point);
}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bCaptured)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
m_pointTo = point;
m_bCaptured = FALSE;
ReleaseCapture();
pDoc->m_lineList[pDoc->m_nCount] = CLine(m_pointFrom,m_pointTo, m_colorCurr, m_nCurrWidth);
pDoc->m_nCount++;
pDoc->SetModifiedFlag();
pDoc->UpdateAllViews(this);
Invalidate();
}
CView::OnLButtonUp(nFlags, point);
}
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bCaptured)
{
CClientDC dc(this);
dc.SetROP2(R2_NOT);
dc.MoveTo(m_pointFrom);
dc.LineTo(m_pointTo);
m_pointTo = point;
dc.MoveTo(m_pointFrom);
dc.LineTo(m_pointTo);
}
CView::OnMouseMove(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -