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

📄 testview.cpp

📁 Visual C++中文字界面
💻 CPP
字号:
// testView.cpp : implementation of the CTestView class
//

#include "stdafx.h"
#include "test.h"

#include "testDoc.h"
#include "testView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTestView

IMPLEMENT_DYNCREATE(CTestView, CView)

BEGIN_MESSAGE_MAP(CTestView, CView)
	//{{AFX_MSG_MAP(CTestView)
	ON_WM_CREATE()
	ON_WM_CHAR()
	ON_WM_LBUTTONDOWN()
	ON_WM_TIMER()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CTestView construction/destruction

CTestView::CTestView()
{
	// TODO: add construction code here
    m_strLine="";
	m_ptOrigin=0;
	m_nWidth=0;
}

CTestView::~CTestView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTestView drawing

void CTestView::OnDraw(CDC* pDC)
{
	CTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CString str("zhang lei");
	pDC->TextOut (50,50,str);
	CSize sz=pDC->GetTextExtent(str);
	str.LoadString (IDS_ZHANGLEI);
	pDC->TextOut (0,200,str);
	pDC->BeginPath ();
	pDC->Rectangle (50,50,50+sz.cx ,50+sz.cy );
	pDC->EndPath ();
	pDC->SelectClipPath (RGN_DIFF);
	for(int i=0;i<=300;i+=10)
	{
		pDC->MoveTo (0,i);
		pDC->LineTo (300,i);
		pDC->MoveTo (i,0);
		pDC->LineTo (i,300);

	}
}

/////////////////////////////////////////////////////////////////////////////
// CTestView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTestView diagnostics

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

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

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

int CTestView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	CClientDC dc(this);
		TEXTMETRIC tm;
	dc.GetTextMetrics (&tm);
	//CreateSolidCaret(tm.tmAveCharWidth /8,tm.tmHeight );
	
	bitmap.LoadBitmap (IDB_BITMAP1);
	CreateCaret(&bitmap);
	ShowCaret();
	SetTimer(1,100,NULL);
	return 0;
}

void CTestView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	CClientDC dc(this);
	CFont font;
	font.CreatePointFont(300,"仿宋",NULL);
	CFont *pOldFont=dc.SelectObject (&font);
	TEXTMETRIC tm;
	dc.GetTextMetrics(&tm);
	if(0x0d==nChar)
	{
		m_strLine.Empty ();
		m_ptOrigin.y+=tm.tmHeight ;

	}
	else if(0x08==nChar)
	{
		COLORREF clr=dc.SetTextColor (dc.GetBkColor() );
		dc.TextOut (m_ptOrigin.x ,m_ptOrigin.y ,m_strLine);
		m_strLine=m_strLine.Left (m_strLine.GetLength() -1);
		dc.SetTextColor(clr);
	}
	else
	{
		m_strLine+=nChar;
	}
	CSize sz=dc.GetTextExtent (m_strLine);
	CPoint pt;
	pt.x =m_ptOrigin.x +sz.cx ;
	pt.y=m_ptOrigin.y;
	SetCaretPos(pt);
	dc.TextOut (m_ptOrigin.x ,m_ptOrigin.y ,m_strLine);

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

void CTestView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	SetCaretPos(point);
	m_strLine.Empty ();
	m_ptOrigin=point;
	CView::OnLButtonDown(nFlags, point);
}

void CTestView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	m_nWidth+=5;
	CClientDC dc(this);
    TEXTMETRIC tm;
	dc.GetTextMetrics (&tm);
	CRect rect;
	rect.left =0;
	rect.top =200;
	rect.right =m_nWidth;
	rect.bottom =rect.top+tm.tmHeight ;
	dc.SetTextColor (RGB(255,0,0));
	CString str;
	str.LoadString (IDS_ZHANGLEI);
	dc.DrawText (str,rect,DT_LEFT);
	CSize sz=dc.GetTextExtent (str);
	if(m_nWidth>sz.cx )
	{
		m_nWidth=0;
		dc.SetTextColor (RGB(0,255,0));
		dc.TextOut (0,200,str);
	}

	CView::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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