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

📄 firstview.cpp

📁 VC源代码大全(精华版)
💻 CPP
字号:
// FirstView.cpp : implementation of the CFirstView class
//

#include "stdafx.h"
#include "Split.h"

#include "SplitDoc.h"
#include "FirstView.h"
#include	"MainFrm.h"

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

struct UPDATECHAR : CObject
	{
	int		startSel;
	int		endSel;
	UINT	nChar;
	UINT	nRepCnt;
	UINT	nFlags;
};

/////////////////////////////////////////////////////////////////////////////
// CFirstView

IMPLEMENT_DYNCREATE(CFirstView, CEditView)

BEGIN_MESSAGE_MAP(CFirstView, CEditView)
	//{{AFX_MSG_MAP(CFirstView)
	ON_WM_CHAR()
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
	ON_WM_SYSCHAR()
	ON_WM_SYSKEYDOWN()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFirstView construction/destruction

CFirstView::CFirstView()
{
	// TODO: add construction code here

}

CFirstView::~CFirstView()
{
}

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

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
//	cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);	// Enable word-wrapping
	cs.style &= ~(WS_HSCROLL|WS_VSCROLL);		// Remove scroll bars

	return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CFirstView drawing

void CFirstView::OnDraw(CDC* pDC)
{
	CSplitDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CFirstView printing

BOOL CFirstView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default CEditView preparation
	return CEditView::OnPreparePrinting(pInfo);
}

void CFirstView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView begin printing.
	CEditView::OnBeginPrinting(pDC, pInfo);
}

void CFirstView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView end printing
	CEditView::OnEndPrinting(pDC, pInfo);
}

/////////////////////////////////////////////////////////////////////////////
// CFirstView diagnostics

#ifdef _DEBUG
void CFirstView::AssertValid() const
{
	CEditView::AssertValid();
}

void CFirstView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CFirstView message handlers

void CFirstView::OnInitialUpdate() 
{
    CMainFrame *frame = DYNAMIC_DOWNCAST(CMainFrame, AfxGetApp()->GetMainWnd());
	if (frame == NULL)
		return;
    CFirstView *pView = (CFirstView *)frame->GetActiveView();
    if ((pView == this) || (pView == NULL))
        return;
    CString strText;
    strText = pView->LockBuffer ();
    pView->UnlockBuffer ();
    SetWindowText (strText);
	int nLine = pView->GetEditCtrl().GetFirstVisibleLine ();
	GetEditCtrl().LineScroll (nLine);
}

void CFirstView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	if ((pSender == this) || (pHint == NULL))
		return;
	CEdit& edit = GetEditCtrl ();

	int startSel, endSel;
	switch (lHint)
	{
		case 1:
		{
			UPDATECHAR *puc = (UPDATECHAR *) pHint;
			edit.GetSel (startSel, endSel);
			edit.SetRedraw (FALSE);
			edit.SetSel (puc->startSel, puc->endSel);
			CEditView::OnChar(puc->nChar, puc->nRepCnt, puc->nFlags);
			edit.SetSel (startSel, endSel);
			edit.SetRedraw (TRUE);
			break;
		}
		case 2:
		{
			UPDATECHAR *puc = (UPDATECHAR *) pHint;
			switch (puc->nChar)
			{
				case 46:
					edit.SetSel (puc->startSel, puc->endSel);
					CEditView::OnKeyDown(puc->nChar, puc->nRepCnt, puc->nFlags);
					break;
				default:
				{
				    CMainFrame *frame = DYNAMIC_DOWNCAST(CMainFrame, AfxGetApp()->GetMainWnd());
					if ((frame->m_wndSplitter.GetColumnCount() < 2)
					|| (frame->m_wndSplitter.GetRowCount() < 2))
						break;
					edit.SetSel (puc->startSel, puc->endSel);
					CEditView::OnKeyDown(puc->nChar, puc->nRepCnt, puc->nFlags);
					break;
				}
			}

			break;
		}
		case 3:
		{
			UPDATECHAR *puc = (UPDATECHAR *) pHint;
			edit.SetSel (puc->startSel, puc->endSel);
			CEditView::OnSysChar(puc->nChar, puc->nRepCnt, puc->nFlags);
			break;
		}
		case 4:
		{
			UPDATECHAR *puc = (UPDATECHAR *) pHint;
			edit.SetSel (puc->startSel, puc->endSel);
			CEditView::OnSysKeyDown(puc->nChar, puc->nRepCnt, puc->nFlags);
			break;
		}
		default:
			break;
	}
}

void CFirstView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
UPDATECHAR	uc;

	GetEditCtrl ().GetSel (uc.startSel, uc.endSel);
	uc.nChar = nChar;
	uc.nRepCnt = nRepCnt;
	uc.nFlags = nFlags;
	CEditView::OnChar(nChar, nRepCnt, nFlags);
	GetDocument()->UpdateAllViews (this, (LPARAM) 1, &uc);
}

void CFirstView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
UPDATECHAR	uc;

	GetEditCtrl ().GetSel (uc.startSel, uc.endSel);
	uc.nChar = nChar;
	uc.nRepCnt = nRepCnt;
	uc.nFlags = nFlags;
	GetDocument()->UpdateAllViews (this, (LPARAM) 2, &uc);
	CEditView::OnKeyDown(nChar, nRepCnt, nFlags);
//	::SetFocus (this->m_hWnd);
}

void CFirstView::OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
UPDATECHAR	uc;

	GetEditCtrl ().GetSel (uc.startSel, uc.endSel);
	uc.nChar = nChar;
	uc.nRepCnt = nRepCnt;
	uc.nFlags = nFlags;
	CEditView::OnSysChar(nChar, nRepCnt, nFlags);
	GetDocument()->UpdateAllViews (this, (LPARAM) 3, &uc);
	::SetFocus (this->m_hWnd);
}

void CFirstView::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
UPDATECHAR	uc;

	GetEditCtrl ().GetSel (uc.startSel, uc.endSel);
	uc.nChar = nChar;
	uc.nRepCnt = nRepCnt;
	uc.nFlags = nFlags;
	CEditView::OnKeyDown(nChar, nRepCnt, nFlags);
	GetDocument()->UpdateAllViews (this, (LPARAM) 4, &uc);
	::SetFocus (this->m_hWnd);
}

⌨️ 快捷键说明

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