📄 mydrawview.cpp
字号:
// MyDrawView.cpp : implementation of the CMyDrawView class
//
#include "stdafx.h"
#include "MyDraw.h"
#include "MyDrawDoc.h"
#include "MyDrawView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView
IMPLEMENT_DYNCREATE(CMyDrawView, CScrollView)
BEGIN_MESSAGE_MAP(CMyDrawView, CScrollView)
//{{AFX_MSG_MAP(CMyDrawView)
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView construction/destruction
CMyDrawView::CMyDrawView()
{
// TODO: add construction code here
m_bDragging=false; // 初始化拖拽标记
m_hCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS); // 获得十字光标句柄
}
CMyDrawView::~CMyDrawView()
{
}
BOOL CMyDrawView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView drawing
void CMyDrawView::OnDraw(CDC* pDC)
{
CMyDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int nIndex=pDoc->GetNumLines(); // 取得线段的数量
TRACE("nIndex1 = %d \n", nIndex); // 调试程序用
//循环画出每一段线段
while(nIndex--) // 数组下标从0到nIndex-1
{
TRACE("nIndex2 = %d \n", nIndex); // 调试程序用
pDoc->GetLine(nIndex)->DrawLine(pDC); // 类CLine的成员函数
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView printing
BOOL CMyDrawView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView diagnostics
#ifdef _DEBUG
void CMyDrawView::AssertValid() const
{
CScrollView::AssertValid();
}
void CMyDrawView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CMyDrawDoc* CMyDrawView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDrawDoc)));
return (CMyDrawDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView message handlers
void CMyDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{
m_bDragging=false; // 清拖拽标记
ReleaseCapture(); // 释放鼠标,还原鼠标形状
}
// CScrollView::OnLButtonUp(nFlags, point);
}
void CMyDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{
CMyDrawDoc *pDoc=GetDocument(); // 获得文档对象的指针
ASSERT_VALID(pDoc); // 测试文档对象是否运行有效
CPoint ptOrg, ptStart, ptEnd;
ptOrg=GetScrollPosition(); // 获得当前工作区原点的坐标
ptStart=m_ptOrigin+ptOrg; // 加上原点的坐标来修正线段的坐标
ptEnd=point+ptOrg;
pDoc->AddLine(ptStart, ptEnd); // 加入线段到指针数组
CClientDC dc(this);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point); // 绘制线段
m_ptOrigin=point; // 新的起始点
}
// CScrollView::OnMouseMove(nFlags, point);
}
void CMyDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture(); // 捕捉鼠标
::SetCursor(m_hCross); // 设置十字光标
m_ptOrigin=point;
m_bDragging=TRUE; // 设置拖拽标记
// CScrollView::OnLButtonDown(nFlags, point);
}
void CMyDrawView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CSize sizeTotal;
sizeTotal.cx=sizeTotal.cy=1000; // 定义滚动视图的大小
SetScrollSizes(MM_TEXT, sizeTotal); // 设置滚动视图的映射模式和大小
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -