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

📄 textview.cpp

📁 这些源代码
💻 CPP
字号:
// TextView.cpp : implementation of the CTextView class
//

#include "stdafx.h"
#include "Text.h"

#include "TextDoc.h"
#include "TextView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTextView

IMPLEMENT_DYNCREATE(CTextView, CView)

BEGIN_MESSAGE_MAP(CTextView, CView)
	//{{AFX_MSG_MAP(CTextView)
	ON_WM_HSCROLL()
	ON_WM_VSCROLL()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CTextView construction/destruction

CTextView::CTextView()
{
	m_nFirstVisible = 0;
	m_Font.CreatePointFont (100, "Courier New");
}

CTextView::~CTextView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTextView drawing

void CTextView::OnDraw(CDC* pDC)
{
}

/////////////////////////////////////////////////////////////////////////////
// CTextView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTextView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTextView message handlers

void CTextView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	RECT	rClip;
	GetClientRect (&rClip);
	switch (nSBCode)
	{
		case SB_BOTTOM:			//	Scrolls to the lower right.
		case SB_ENDSCROLL:		//	Ends scroll.
			return;
		case SB_LINEDOWN:		//	Scrolls one line down.
			++m_siHorz.nPos;
			if (m_siHorz.nPos > m_siHorz.nMax)
				m_siHorz.nPos = m_siHorz.nMax;
			else
				ScrollWindowEx (-1, 0, NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
			break;
		case SB_LINEUP:			//	Scrolls one line up.
			--m_siHorz.nPos;
			if (m_siHorz.nPos < 0)
				m_siHorz.nPos = 0;
			else
				ScrollWindowEx (1, 0, NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
			break;
		case SB_PAGEDOWN:		//	Scrolls one page left.
			if (m_siHorz.nPos >= m_siHorz.nMax)
				return;
			ScrollWindowEx (-((int) m_siHorz.nPage / 2), 0, NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
			m_siHorz.nPos += m_siHorz.nPage / 2;
			if (m_siHorz.nPos > m_siHorz.nMax)
				m_siHorz.nPos = m_siHorz.nMax;
			break;
		case SB_PAGEUP:			//	Scrolls one page up.
			if (m_siHorz.nPos == 0)
				return;
			ScrollWindowEx (m_siHorz.nPage / 2, 0, NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
			m_siHorz.nPos -= m_siHorz.nPage / 2;
			if (m_siHorz.nPos < 0)
				m_siHorz.nPos = 0;
			break;
		case SB_THUMBPOSITION:	//	The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter indicates the position of the scroll box at the end of the drag operation.
		case SB_THUMBTRACK:		//	The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The nPos parameter indicates the position that the scroll box has been dragged to.
			ScrollWindowEx (m_siHorz.nPos - nPos, 0, NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
			m_siHorz.nPos = nPos;// HIWORD(wParam);
			break;
		case SB_TOP:				//	Scrolls to the upper left.
			return;
			break;
	}
	SetScrollInfo (SB_HORZ, &m_siHorz, true);
}

void CTextView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	RECT	rClip;
	GetClientRect (&rClip);
	switch (nSBCode)
	{
	int		Pos, Scroll;
		case SB_BOTTOM:			//	Scrolls to the lower right.
		case SB_ENDSCROLL:		//	Ends scroll.
			return;
		case SB_LINEDOWN:		//	Scrolls one line down.
			ScrollWindowEx (0, -m_nTextHigh, NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
//			m_siVert.nPos += 1;
			m_siVert.nPos += m_nTextHigh;
			m_siVert.nTrackPos += m_nTextHigh;
			if (m_siVert.nPos > m_siVert.nMax)
				m_siVert.nPos = m_siVert.nMax;
//			if (m_nFirstVisible)
				++m_nFirstVisible;
			break;
		case SB_LINEUP:			//	Scrolls one line up.
			ScrollWindowEx (0, 1, NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
			if (m_siVert.nPos == 0)
				return;
			m_siVert.nPos -= 1;
			if (m_siVert.nPos < 0)
				m_siVert.nPos = 0;
			++m_nFirstVisible;
			break;
		case SB_PAGEDOWN:		//	Scrolls one page down.
			if (m_siVert.nPos >= m_siVert.nMax)
				return;
			Pos = m_siVert.nPos;
			m_siVert.nPos += m_siVert.nPage / 2;
			if (m_siVert.nPos > m_siVert.nMax)
			{
				Scroll = 0;
				m_siVert.nPos = m_siVert.nMax;
			}
			else
				Scroll = m_siVert.nPage / 2;
			ScrollWindowEx (0, -((int) m_siVert.nPage / 2), NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
//			m_Stop = true;
			m_nFirstVisible += 10;
			break;
		case SB_PAGEUP:			//	Scrolls one page up.
			if (m_siVert.nPos == 0)
				return;
			Pos = m_siVert.nPos;
			m_siVert.nPos -= m_siVert.nPage / 2;
			if (m_siVert.nPos < 0)
			{
				Scroll = 0;
				m_siVert.nPos = 0;
			}
			else
				Scroll = m_siVert.nPage / 2;
			ScrollWindowEx (0, m_siVert.nPage / 2, NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
//			m_Stop = true;
			m_nFirstVisible -= 10;
			if (m_nFirstVisible < 0)
				m_nFirstVisible = 0;
			break;
		case SB_THUMBPOSITION:	//	The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter indicates the position of the scroll box at the end of the drag operation.
		case SB_THUMBTRACK:		//	The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The nPos parameter indicates the position that the scroll box has been dragged to.
			ScrollWindowEx (0, m_siVert.nPos - nPos, NULL, &rClip, NULL, NULL, SW_ERASE | SW_INVALIDATE);
			m_siVert.nPos = nPos;
			break;
		case SB_TOP:				//	Scrolls to the upper left.
			return;
	}
	SetScrollInfo (SB_VERT, &m_siVert, true);
}

⌨️ 快捷键说明

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