📄 ch9demo2view.cpp
字号:
// Ch9Demo2View.cpp : implementation of the CCh9Demo2View class
//
#include "stdafx.h"
#include "Ch9Demo2.h"
#include "Ch9Demo2Doc.h"
#include "Ch9Demo2View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo2View
IMPLEMENT_DYNCREATE(CCh9Demo2View, CView)
BEGIN_MESSAGE_MAP(CCh9Demo2View, CView)
//{{AFX_MSG_MAP(CCh9Demo2View)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo2View construction/destruction
CCh9Demo2View::CCh9Demo2View()
{
// TODO: add construction code here
}
CCh9Demo2View::~CCh9Demo2View()
{
}
BOOL CCh9Demo2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo2View drawing
void CCh9Demo2View::OnDraw(CDC* pDC)
{
CCh9Demo2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CString str="下面的文本显示为采用DrawText函数进行格式化输出:";
pDC->TextOut(10,10,str);//单行输出文本
CRect rect;
GetClientRect(&rect);//获取客户区窗口矩形
CRect textrect(40,50,(rect.Width()-30),rect.Height());//文本输出矩形区域
pDC->SetTextColor(RGB(200,10,10));//文本颜色
pDC->SetBkMode(TRANSPARENT);//文本采用透明背景色
CString str2="输出文本一般使用CDC::TextOut函数,它可以输出单行的文本。另外,在CDC类中还有一个在指定的矩形范围内,显示格式化文本的函数CDC::DrawText。在输出文字时,可以使用CDC提供的一些函数进行文本颜色、背景颜色的设置等等。";//文本
pDC->DrawText(str2,&textrect,DT_LEFT|DT_WORDBREAK);//格式化文本输出,左对齐,不截断单词
}
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo2View printing
BOOL CCh9Demo2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCh9Demo2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCh9Demo2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo2View diagnostics
#ifdef _DEBUG
void CCh9Demo2View::AssertValid() const
{
CView::AssertValid();
}
void CCh9Demo2View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCh9Demo2Doc* CCh9Demo2View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCh9Demo2Doc)));
return (CCh9Demo2Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo2View message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -