📄 viewerview.cpp
字号:
// ViewerView.cpp : implementation of the CViewerView class
//
#include "stdafx.h"
#include "Viewer.h"
#include "ViewerDoc.h"
#include "ViewerView.h"
#include "DLGState.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CViewerView
IMPLEMENT_DYNCREATE(CViewerView, CScrollView)
BEGIN_MESSAGE_MAP(CViewerView, CScrollView)
//{{AFX_MSG_MAP(CViewerView)
ON_COMMAND(ID_BUTTON_STAT, OnButtonStat)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CViewerView construction/destruction
CViewerView::CViewerView()
{
// TODO: add construction code here
}
CViewerView::~CViewerView()
{
}
BOOL CViewerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CViewerView drawing
void CViewerView::OnDraw(CDC* pDC)
{
CViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
DispContent(pDC);//显示读入的文档
}
void CViewerView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CViewerView printing
BOOL CViewerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CViewerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CViewerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CViewerView diagnostics
#ifdef _DEBUG
void CViewerView::AssertValid() const
{
CScrollView::AssertValid();
}
void CViewerView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CViewerDoc* CViewerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CViewerDoc)));
return (CViewerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CViewerView message handlers
void CViewerView::DispContent(CDC* pDC)
{
CViewerDoc* pDoc = GetDocument();
int nLines = pDoc->m_strContent.GetSize();
if(nLines<1)
return;
CSize sizeLine = pDC->GetTextExtent("A");//获取字符串的宽度和高度
int nTabChars = 4*sizeLine.cx; //设置一个Tab符等于4个字符
int y=0; //行位置
CString str;
int nWidthMax = 0;
for(int i=0;i<nLines;i++)
{
str = pDoc->m_strContent.GetAt(i);
CSize size = pDC->TabbedTextOut(0,y,str,1,&nTabChars,0);
y = y+sizeLine.cy;
if(nWidthMax < size.cx)
nWidthMax = size.cx;
}
SetScrollSizes(MM_TEXT,CSize(nWidthMax,y));
}
void CViewerView::OnButtonStat()
{
// TODO: Add your command handler code here
CViewerDoc* pDoc = GetDocument();
int nLines = pDoc->m_strContent.GetSize();
if(nLines<1)
return;
CString strline;
char ch;
bool chBOOL = true;//true表示字符是单词首字符,
long num_char = 0, num_C = 0, num_E = 0;
for(int i=0;i<nLines;i++)
{
strline = pDoc->m_strContent.GetAt(i);
for(int j =0; j< strline.GetLength(); j++)
{
num_char = num_char + 1;
ch = strline.GetAt(j);
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) //该字符为字母
{
if(chBOOL)
{
num_E = num_E+1;
}
chBOOL = false;
}
else
{
chBOOL = true;
}
if(ch<0)//为汉字
{
num_C = num_C+1;
j++;
}
}
}
CDLGState dlg;
dlg.m_char = num_char;
dlg.m_numch = num_C;
dlg.m_numen = num_E;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -