📄 11view.cpp
字号:
// 11View.cpp : implementation of the CMy11View class
//
#include "stdafx.h"
#include "11.h"
#include "11Doc.h"
#include "11View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy11View
IMPLEMENT_DYNCREATE(CMy11View, CView)
BEGIN_MESSAGE_MAP(CMy11View, CView)
//{{AFX_MSG_MAP(CMy11View)
ON_COMMAND(ID_FILEOPEN, OnFileopen)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMy11View construction/destruction
CMy11View::CMy11View()
{
// TODO: add construction code here
bIsOpen=FALSE;
}
CMy11View::~CMy11View()
{
}
BOOL CMy11View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMy11View drawing
void CMy11View::OnDraw(CDC* pDC)
{
CMy11Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString strVal[500],strTemp;
int nCount=0;
// TODO: add draw code for native data here
if(bIsOpen)
{
strTemp=strFile;
BOOL bIsIn=TRUE;
while(bIsIn)
{
bIsIn=FALSE;
strFile=strTemp;
int nLen=strFile.GetLength();
int nSize;
for(int i=0;i<nLen;i++)
{
if(strFile.GetAt(i)=='\r')
{
bIsIn=TRUE;
nSize=i;
break;
}
}
if(bIsIn)
{
strVal[nCount]=strFile.Left(nSize);
strTemp=strFile.Right(nLen-nSize-1);
nCount++;
}
else
strVal[nCount]=strTemp;
}
}
for(int i=0;i<nCount+1;i++)
pDC->TextOut(0,i*20,strVal[i]);
}
/////////////////////////////////////////////////////////////////////////////
// CMy11View printing
BOOL CMy11View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy11View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy11View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy11View diagnostics
#ifdef _DEBUG
void CMy11View::AssertValid() const
{
CView::AssertValid();
}
void CMy11View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy11Doc* CMy11View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy11Doc)));
return (CMy11Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMy11View message handlers
void CMy11View::OnFileopen()
{
// TODO: Add your command handler code here
CStdioFile mFile;
CString path,strTemp;
CFileDialog dlg(true, NULL, NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Text File(*.txt)|*.txt||");
if(dlg.DoModal()==IDOK)
{
bIsOpen=TRUE;
CString filename=dlg.GetPathName();
BOOL isEof=FALSE;
if(mFile.Open(filename,CFile::modeRead|CFile::typeBinary))
{
while(!isEof)
{
isEof=!mFile.ReadString(strTemp);
strFile+=strTemp;
if(isEof) break;
}
}
RedrawWindow();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -