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

📄 keyexa~3.cpp

📁 vc++net很不错的一个工具
💻 CPP
字号:
// KeyExampleView.cpp : CKeyExampleView 类的实现
//

#include "stdafx.h"
#include "KeyExample.h"

#include "KeyExampleDoc.h"
#include "KeyExampleView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CKeyExampleView

IMPLEMENT_DYNCREATE(CKeyExampleView, CView)

BEGIN_MESSAGE_MAP(CKeyExampleView, CView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
	ON_WM_CHAR()
END_MESSAGE_MAP()

// CKeyExampleView 构造/销毁

CKeyExampleView::CKeyExampleView()
{
	// TODO: 在此处添加构造代码
	

}

CKeyExampleView::~CKeyExampleView()
{
}

BOOL CKeyExampleView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
	// 样式

	return CView::PreCreateWindow(cs);
}

// CKeyExampleView 绘制

void CKeyExampleView::OnDraw(CDC* pDC)
{
	CKeyExampleDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
    //定义TEXTMETRIC结构体
	TEXTMETRIC tm;
	//获取字体属性
	pDC->GetTextMetrics(&tm);
	for(int i=0;i<=pDoc->m_nCounter;i++)
	{
		//对于字符串数组中的每个字符串,隔行输出
	pDC->TextOut(0,i*tm.tmHeight,pDoc->m_strText[i]);
	}
	// TODO: 在此处为本机数据添加绘制代码
	
}


// CKeyExampleView 打印

BOOL CKeyExampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CKeyExampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 打印前添加额外的初始化
}

void CKeyExampleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 打印后添加清除过程
}


// CKeyExampleView 诊断

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

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

CKeyExampleDoc* CKeyExampleView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CKeyExampleDoc)));
	return (CKeyExampleDoc*)m_pDocument;
}
#endif //_DEBUG


// CKeyExampleView 消息处理程序

void CKeyExampleView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	//获取指向文档类的指针
	CKeyExampleDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	if(nChar!='\r')
	{
	if(nChar=='\b')
	{   //处理退格键消息,每当用户按一次退格键,在对应的字符串中消去此按键字符
		pDoc->m_strText[pDoc->m_nCounter]=pDoc->m_strText[pDoc->m_nCounter].Left(pDoc->m_strText[pDoc->m_nCounter].GetLength()-1);
		if(pDoc->m_strText[pDoc->m_nCounter].GetLength()==0)
			if(pDoc->m_nCounter!=0)
				//当对应字符为空时,继续消去上一字符串内容,直到所有字符串为空。
			pDoc->m_nCounter--;
			else
				pDoc->m_nCounter=0;
	}
	else
		//对于通常的打应字符,将按键字符保存到对应的字符串中
	    pDoc->m_strText[pDoc->m_nCounter] += (CHAR)nChar;
	}
	else
	{  //处理回车键消息,每当用户按一次回车键,字符串数组数目加一
		pDoc->m_nCounter++;
	}

	CView::OnChar(nChar, nRepCnt, nFlags);
	//视图重绘
	Invalidate();
}

⌨️ 快捷键说明

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