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

📄 ch5demo3view.cpp

📁 零基础学Visual.C....教案PPT.随书光盘-452M.zip
💻 CPP
字号:
// Ch5Demo3View.cpp : implementation of the CCh5Demo3View class
//

#include "stdafx.h"
#include "Ch5Demo3.h"

#include "Ch5Demo3Doc.h"
#include "Ch5Demo3View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo3View

IMPLEMENT_DYNCREATE(CCh5Demo3View, CView)

BEGIN_MESSAGE_MAP(CCh5Demo3View, CView)
	//{{AFX_MSG_MAP(CCh5Demo3View)
	ON_WM_CHAR()
	ON_WM_KEYDOWN()
	ON_WM_SETFOCUS()
	ON_WM_KILLFOCUS()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo3View construction/destruction

CCh5Demo3View::CCh5Demo3View()
{
	// TODO: add construction code here
	//初始位置设置在(0,0)
	ptCharacter.x=0;
	ptCharacter.y=0;
}

CCh5Demo3View::~CCh5Demo3View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo3View drawing

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

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo3View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo3View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo3View message handlers

void CCh5Demo3View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	if(nChar==13)//按下了回车键
	{
		//换行
		ptCharacter.x=0;
		ptCharacter.y=ptCharacter.y+25;
		SetCaretPos (ptCharacter);								//将插入符移到键入点
		ShowCaret ();											//显示插入符
	}
	else
	{
		CClientDC dc(this);
		HideCaret ();											//隐藏插入符
		dc.TextOut(ptCharacter.x,ptCharacter.y,(LPCTSTR)&nChar);//显示字符
		CSize textsize;
		textsize=dc.GetTextExtent((LPCTSTR)&nChar);				//获取当前字符大小
		//前进到下一个字符位置
		ptCharacter.x=ptCharacter.x+textsize.cx;
		SetCaretPos (ptCharacter);								//将插入符移到键入点
		ShowCaret ();											//显示插入符

	}
	CView::OnChar(nChar, nRepCnt, nFlags);
}

void CCh5Demo3View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CCh5Demo3View::OnSetFocus(CWnd* pOldWnd) 
{
	CView::OnSetFocus(pOldWnd);
	
	// TODO: Add your message handler code here
		CreateSolidCaret(4, 20);										//创建插入符
		SetCaretPos (ptCharacter);										//将插入符移到鼠标点
		ShowCaret ();											//显示插入符	
}

void CCh5Demo3View::OnKillFocus(CWnd* pNewWnd) 
{
	CView::OnKillFocus(pNewWnd);
	
	// TODO: Add your message handler code her
	HideCaret ();											//隐藏插入符
//	DestoryCaret ();
	
}

⌨️ 快捷键说明

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