📄 zhanglu15view.cpp
字号:
// zhanglu15View.cpp : implementation of the CZhanglu15View class
//
#include "stdafx.h"
#include "zhanglu15.h"
#include "zhanglu15Doc.h"
#include "zhanglu15View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View
IMPLEMENT_DYNCREATE(CZhanglu15View, CView)
BEGIN_MESSAGE_MAP(CZhanglu15View, CView)
//{{AFX_MSG_MAP(CZhanglu15View)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_CREATE()
ON_WM_CHAR()
ON_WM_TIMER()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View construction/destruction
CZhanglu15View::CZhanglu15View()
{
// TODO: add construction code here
m_strLine="";
m_ptOrigin=0;
m_bDragging=false; // 初始化拖拽标记
// 获得十字光标句柄
m_hCross=AfxGetApp()->
LoadStandardCursor(IDC_CROSS);
}
CZhanglu15View::~CZhanglu15View()
{
}
BOOL CZhanglu15View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View drawing
void CZhanglu15View::OnDraw(CDC* pDC)
{
CZhanglu15Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int nIndex=pDoc->GetNumLines(); // 取得线段的数量
// 循环画出每一段线段
while(nIndex--) // 数组下标从0到nIndex-1
{
pDoc->GetLine(nIndex)->DrawLine(pDC);
// 类CLine的成员函数
}
}
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View printing
BOOL CZhanglu15View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CZhanglu15View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CZhanglu15View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View diagnostics
#ifdef _DEBUG
void CZhanglu15View::AssertValid() const
{
CView::AssertValid();
}
void CZhanglu15View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CZhanglu15Doc* CZhanglu15View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CZhanglu15Doc)));
return (CZhanglu15Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View message handlers
void CZhanglu15View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCaretPos(point);
m_strLine.Empty();
m_ptOrigin=point;
SetCapture(); // 捕捉鼠标
::SetCursor(m_hCross); // 设置十字光标
m_ptOrigin=point;
m_bDragging=TRUE; // 设置拖拽标记
CView::OnLButtonDown(nFlags, point);
}
void CZhanglu15View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{
m_bDragging=false; // 清拖拽标记
ReleaseCapture(); // 释放鼠标,还原鼠标形状
}
// CView::OnLButtonUp(nFlags, point);
}
void CZhanglu15View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{ CZhanglu15Doc *pDoc=GetDocument(); //获得文档对象指针
ASSERT_VALID(pDoc); //测试文档对象是否运行有效
pDoc->AddLine(m_ptOrigin, point); //加入线段到指针数组
CClientDC dc(this);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point); // 绘制线段
m_ptOrigin=point; // 新的起始点
}
CStatusBar*pFrame=(CStatusBar*)AfxGetMainWnd();
CStatusBar*pStatusBar=(CStatusBar*)pFrame->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CString strMousePoint;
strMousePoint.Format("%3d,%3d",point.x,point.y);
pStatusBar->SetPaneText(pStatusBar->CommandToIndex(IDS_INDICATOR_MOUSE),strMousePoint);
CView::OnMouseMove(nFlags, point);
}
int CZhanglu15View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CClientDC dc(this);//创建设备描述表
TEXTMETRIC tm;//定义文本信息结构体变量
dc.GetTextMetrics(&tm);//获得设备描述表中文本信息
CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);
//根据字体大小,创建合适的插入符
ShowCaret();//显示显示符
return 0;
}
void CZhanglu15View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
if(0x0d==nChar)
{
m_strLine.Empty();
m_ptOrigin.y+=tm.tmHeight;
}
else if(0x08==nChar)
{
COLORREF clr=dc.SetTextColor(dc.GetBkColor());
dc.TextOut(m_ptOrigin.x,m_ptOrigin.y,m_strLine);
m_strLine=m_strLine.Left(m_strLine.GetLength()-1);
dc.SetTextColor(clr);
}
else
{
m_strLine+=nChar;
}
CSize sz=dc.GetTextExtent(m_strLine);
CPoint pt;
pt.x=m_ptOrigin.x+sz.cx;
pt.y=m_ptOrigin.y;
SetCaretPos(pt);
dc.TextOut(m_ptOrigin.x,m_ptOrigin.y,m_strLine);
CView::OnChar(nChar, nRepCnt, nFlags);
}
//DEL void CZhanglu15View::OnIdcColor()
//DEL {
//DEL // TODO: Add your command handler code here
//DEL pDC->SetTextColor(RGB(255,0,0));//字体颜色
//DEL
//DEL }
void CZhanglu15View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CView::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -