?? retextview.cpp
字號:
// RetextView.cpp : implementation of the CRetextView class
//
#include "stdafx.h"
#include "Retext.h"
#include "RetextDoc.h"
#include "RetextView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRetextView
IMPLEMENT_DYNCREATE(CRetextView, CView)
BEGIN_MESSAGE_MAP(CRetextView, CView)
//{{AFX_MSG_MAP(CRetextView)
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()
/////////////////////////////////////////////////////////////////////////////
// CRetextView construction/destruction
CRetextView::CRetextView()
{
// TODO: add construction code here
m_strLine="";
m_ptOrigin=0;
m_nWidth=0;
}
CRetextView::~CRetextView()
{
}
BOOL CRetextView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CRetextView drawing
void CRetextView::OnDraw(CDC* pDC)
{
CRetextDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString str;
str="北京維新科學技術中心";
pDC->TextOut(50,50,str);
CSize sz=pDC->GetTextExtent(str);
str.LoadString(IDS_WEIXIN);
pDC->TextOut(0,200,str);
pDC->BeginPath();
pDC->Rectangle(CRect(50,50,50+sz.cx,50+sz.cy));
pDC->EndPath();
pDC->SelectClipPath(RGN_DIFF);
for(int i=0;i<300;i+=10)
{
pDC->MoveTo(i,0);
pDC->LineTo(i,300);
pDC->MoveTo(0,i);
pDC->LineTo(300,i);
}
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CRetextView printing
BOOL CRetextView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CRetextView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CRetextView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CRetextView diagnostics
#ifdef _DEBUG
void CRetextView::AssertValid() const
{
CView::AssertValid();
}
void CRetextView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CRetextDoc* CRetextView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRetextDoc)));
return (CRetextDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRetextView message handlers
int CRetextView::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 CRetextView::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);
dc.SelectObject(pOldFont);
CView::OnChar(nChar, nRepCnt, nFlags);
}
void CRetextView::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 CRetextView::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;
CString str;
str.LoadString(IDS_WEIXIN);
dc.SetTextColor(RGB(255,0,0));
dc.DrawText(str,rect,DT_LEFT);
rect.top=150;
rect.bottom=rect.top+tm.tmHeight;
dc.DrawText(str,rect,DT_RIGHT);
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 + -