⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s8_9view.cpp

📁 四川大学教学的MFC的ppt 以及源代码
💻 CPP
字号:
// s8_9View.cpp : implementation of the CS8_9View class
//

#include "stdafx.h"
#include "s8_9.h"

#include "s8_9Doc.h"
#include "s8_9View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CS8_9View

IMPLEMENT_DYNCREATE(CS8_9View, CView)

BEGIN_MESSAGE_MAP(CS8_9View, CView)
	//{{AFX_MSG_MAP(CS8_9View)
	ON_WM_LBUTTONDOWN()
	ON_WM_CHAR()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CS8_9View construction/destruction

CS8_9View::CS8_9View()
{
	// TODO: add construction code here
	m_oCaretPosition.x = m_oCaretPosition.y = 0;	//初始化插入符位置
	m_oMousePosition.x = m_oMousePosition.y = 0;	//初始化鼠标单击位置
}

CS8_9View::~CS8_9View()
{
}

BOOL CS8_9View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CS8_9View drawing

void CS8_9View::OnDraw(CDC* pDC)
{
	CS8_9Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	TEXTMETRIC sTextMetric;			
	pDC->GetTextMetrics(&sTextMetric);
	CreateSolidCaret(sTextMetric.tmAveCharWidth/8, sTextMetric.tmHeight);
	pDC->TextOut(m_oMousePosition.x, m_oMousePosition.y, pDoc->m_strText);
	CSize oSize = pDC->GetTextExtent(pDoc->m_strText);
	HideCaret();
	m_oCaretPosition.x = m_oMousePosition.x + oSize.cx;		//插入符横坐标
	m_oCaretPosition.y = m_oMousePosition.y;				//插入符纵坐标
	SetCaretPos(m_oCaretPosition);
	ShowCaret();
}

/////////////////////////////////////////////////////////////////////////////
// CS8_9View printing

BOOL CS8_9View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CS8_9View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CS8_9View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CS8_9View diagnostics

#ifdef _DEBUG
void CS8_9View::AssertValid() const
{
	CView::AssertValid();
}

void CS8_9View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CS8_9Doc* CS8_9View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CS8_9Doc)));
	return (CS8_9Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CS8_9View message handlers

void CS8_9View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CS8_9Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	pDoc->m_strText.Empty();		
	m_oMousePosition = point;		//将鼠标单击位置赋值给m_oMousePosition
	Invalidate();

	CView::OnLButtonDown(nFlags, point);
}

void CS8_9View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	CS8_9Doc* pDoc = GetDocument();	
	ASSERT_VALID(pDoc);			
	pDoc->m_strText += nChar;	
	Invalidate();				
	
	CView::OnChar(nChar, nRepCnt, nFlags);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -