【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,CText_5View.cpp,希望对大家有所帮助!
// CText_5View.cpp : implementation of the CCText_5View class
//
#include "stdafx.h"
#include "CText_5.h"
#include "CText_5Doc.h"
#include "CText_5View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCText_5View
IMPLEMENT_DYNCREATE(CCText_5View, CView)
BEGIN_MESSAGE_MAP(CCText_5View, CView)
//{{AFX_MSG_MAP(CCText_5View)
ON_WM_CHAR()
ON_WM_LBUTTONDOWN()
ON_WM_CREATE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CCText_5View construction/destruction
CCText_5View::CCText_5View()
{
// TODO: add construction code here
m_str="";
m_point=0;
}
CCText_5View::~CCText_5View()
{
}
BOOL CCText_5View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCText_5View drawing
void CCText_5View::OnDraw(CDC* pDC)
{
CCText_5Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCText_5View printing
BOOL CCText_5View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCText_5View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCText_5View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCText_5View diagnostics
#ifdef _DEBUG
void CCText_5View::AssertValid() const
{
CView::AssertValid();
}
void CCText_5View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCText_5Doc* CCText_5View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCText_5Doc)));
return (CCText_5Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCText_5View message handlers
void CCText_5View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
if(0x0d==nChar) //输入“Enter”
{
m_str.Empty();
m_point.y+=tm.tmHeight;
}
else if(0x08==nChar) //输入“BackSpace”
{
COLORREF clr=dc.SetTextColor(dc.GetBkColor());
dc.TextOut(m_point.x,m_point.y,m_str);
m_str=m_str.Left(m_str.GetLength()-1);
dc.SetTextColor(clr);
}
else
{
m_str+=nChar;
}
CSize sz=dc.GetTextExtent(m_str);
CPoint pt;
pt.x=m_point.x+sz.cx;
pt.y=m_point.y;
SetCaretPos(pt);
dc.TextOut(m_point.x,m_point.y,m_str);
CView::OnChar(nChar, nRepCnt, nFlags);
}
void CCText_5View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCaretPos(point);
m_str.Empty();
m_point=point;
CView::OnLButtonDown(nFlags, point);
}
int CCText_5View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);
ShowCaret();
// TODO: Add your specialized creation code here
return 0;
}
上一篇:
CText_5Doc.cpp
下一篇:
4种小菜缓解孕妈咪不适