1.
BOOL CxxxxView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
BOOL ret=CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
//创建文本插入符
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
CreateSolidCaret(tm.tmAveCharWidth/8, tm.tmHeight);
ShowCaret();
//
return ret;
}
2. CxxxxView::CEditViewView()
{
// TODO: add construction code here
m_ptOrigin.x=0;
m_ptOrigin.y=0;
}
3.
void CEditViewView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
afxDump << nChar << "\n";
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
//
if (0x0d == nChar)
{
m_strLine.Empty();
m_ptOrigin.y += tm.tmHeight;
}
else if (0x08 == nChar)
{
m_strLine = m_strLine.Left(m_strLine.GetLength() - 1);
}
else
{
m_strLine += nChar;
m_ptOrigin.x += tm.tmAveCharWidth; }
SetCaretPos(m_ptOrigin);
//
Invalidate();
//
CView::OnChar(nChar, nRepCnt, nFlags);
}
4.
void CEditViewView::OnDraw(CDC* pDC)
{
CEditViewDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
afxDump << m_strLine << "\n";
pDC->TextOut (m_ptOrigin.x, m_ptOrigin.y, m_strLine);
}
BOOL CxxxxView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
BOOL ret=CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
//创建文本插入符
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
CreateSolidCaret(tm.tmAveCharWidth/8, tm.tmHeight);
ShowCaret();
//
return ret;
}
2. CxxxxView::CEditViewView()
{
// TODO: add construction code here
m_ptOrigin.x=0;
m_ptOrigin.y=0;
}
3.
void CEditViewView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
afxDump << nChar << "\n";
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
//
if (0x0d == nChar)
{
m_strLine.Empty();
m_ptOrigin.y += tm.tmHeight;
}
else if (0x08 == nChar)
{
m_strLine = m_strLine.Left(m_strLine.GetLength() - 1);
}
else
{
m_strLine += nChar;
m_ptOrigin.x += tm.tmAveCharWidth; }
SetCaretPos(m_ptOrigin);
//
Invalidate();
//
CView::OnChar(nChar, nRepCnt, nFlags);
}
4.
void CEditViewView::OnDraw(CDC* pDC)
{
CEditViewDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
afxDump << m_strLine << "\n";
pDC->TextOut (m_ptOrigin.x, m_ptOrigin.y, m_strLine);
}
解决方案 »
- 百度说了,有图有真相!
- 请教消息映射
- 急问,window下,实现一最简单socket通信,不要界面?
- 一个可停靠的工具栏关闭后其窗口有没有被销毁,还是被隐藏了?用什么代码可以把它重新显示出来?
- 怎样的对象才算是线程安全的??
- 500分求答一个COM问题!!!!!
- TRACE问题
- 我用VC6.0的向导生成了一个程序包含打印的内容,现在我的问题是打印完成后程序返回什么信息,我想每打印完一次,我就记录一次.我说的是打印
- 我为什么在WINDOWS 2000 里老装不上VC,提示错误:安装程序无法创建一个DCOM用户帐号来注册
- 如何获取ClistCtrl中某行英某列的位置??
- 求大神赐教
- 程序编译和执行都没错误,但总是提醒中止或重试
//#include "stdafx.h"
#include "EditView.h"#include "EditViewDoc.h"
#include "EditViewView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CEditViewViewIMPLEMENT_DYNCREATE(CEditViewView, CView)BEGIN_MESSAGE_MAP(CEditViewView, CView)
//{{AFX_MSG_MAP(CEditViewView)
ON_WM_CHAR()
ON_WM_LBUTTONDOWN()
//}}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()/////////////////////////////////////////////////////////////////////////////
// CEditViewView construction/destructionCEditViewView::CEditViewView()
{
// TODO: add construction code here
m_ptOrigin.x=0;
m_ptOrigin.y=0;
}CEditViewView::~CEditViewView()
{
}BOOL CEditViewView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CEditViewView drawingvoid CEditViewView::OnDraw(CDC* pDC)
{
CEditViewDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CFont *pfntOld=CFont::FromHandle((HFONT)pDC->SelectObject(m_Font));
pDC->TextOut (m_ptOrigin.x, m_ptOrigin.y, m_strLine);
pDC->SelectObject(pfntOld);
}/////////////////////////////////////////////////////////////////////////////
// CEditViewView printingBOOL CEditViewView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CEditViewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CEditViewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CEditViewView diagnostics#ifdef _DEBUG
void CEditViewView::AssertValid() const
{
CView::AssertValid();
}void CEditViewView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CEditViewDoc* CEditViewView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEditViewDoc)));
return (CEditViewDoc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CEditViewView message handlers
void CEditViewView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
//
CSize sz(0,0);
CFont *pfntOld=CFont::FromHandle((HFONT)dc.SelectObject(m_Font));
CPoint pt=GetCaretPos();
// afxDump << pt.x << "\n";
if (0x0d == nChar)
{
GetTextExtentPoint32(dc.m_hDC,m_strLine,m_strLine.GetLength(),&sz);
// Origin.x not changed
m_ptOrigin.y += sz.cy;
// caret back
sz.cx = -sz.cx;
// clear
m_strLine.Empty();
}
else if (0x08 == nChar)
{
CString LastOne = m_strLine.Right(1);
m_strLine = m_strLine.Left(m_strLine.GetLength() - 1);
GetTextExtentPoint32(dc.m_hDC,LastOne,sizeof(TCHAR),&sz);
sz.cx=-sz.cx;
sz.cy=0;
}
else
{// CALCULATE caret
m_strLine += nChar;
GetTextExtentPoint32(dc.m_hDC,CString(nChar),sizeof(TCHAR),&sz);
sz.cy=0;
}
dc.SelectObject(pfntOld->m_hObject);
pt.x +=sz.cx;
pt.y +=sz.cy;
SetCaretPos(pt);
pt=GetCaretPos();
// redraw
Invalidate();
//
CView::OnChar(nChar, nRepCnt, nFlags);
}void CEditViewView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_strLine.Empty();
m_ptOrigin = point;
SetCaretPos(point);
//
CView::OnLButtonDown(nFlags, point);
}void CEditViewView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// font
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // zero out structure
lf.lfHeight = 36; // request a 12-pixel-height font
strcpy(lf.lfFaceName, "Arial"); // request a face name "Arial"
m_Font.CreateFontIndirect(&lf); // create the font
SetFont(&m_Font);
//创建文本插入符
CClientDC dc(this);
CFont *pfntOld=CFont::FromHandle((HFONT)dc.SelectObject(m_Font));
dc.GetTextMetrics(&m_tm);
CreateSolidCaret(m_tm.tmAveCharWidth/8, m_tm.tmHeight);
dc.SelectObject(pfntOld->m_hObject);
//
SetCaretPos(CPoint(0,0));
ShowCaret();
}