📄 sample10_3view.cpp
字号:
// SAMPLE10_3View.cpp : CSAMPLE10_3View 类的实现
//
#include "stdafx.h"
#include "SAMPLE10_3.h"
#include "SAMPLE10_3Doc.h"
#include "SAMPLE10_3View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CSAMPLE10_3View
IMPLEMENT_DYNCREATE(CSAMPLE10_3View, CScrollView)
BEGIN_MESSAGE_MAP(CSAMPLE10_3View, CScrollView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
// ON_WM_INITMENUPOPUP()
END_MESSAGE_MAP()
// CSAMPLE10_3View 构造/销毁
CSAMPLE10_3View::CSAMPLE10_3View()
{
// TODO: 在此处添加构造代码
}
CSAMPLE10_3View::~CSAMPLE10_3View()
{
}
BOOL CSAMPLE10_3View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
// 样式
return CScrollView::PreCreateWindow(cs);
}
// CSAMPLE10_3View 绘制
void CSAMPLE10_3View::OnDraw(CDC* pDC)
{
CSAMPLE10_3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
LOGFONT logFont;
memset(&logFont, 0, sizeof(LOGFONT));
//1英寸
logFont.lfHeight = 100;
//字体
CFont font;
CFont* pOldFont = NULL;
if (font.CreateFontIndirect(&logFont))
pOldFont = pDC->SelectObject(&font);
CString strPageTitle = GetDocument()->GetTitle();
pDC->SetTextAlign(TA_LEFT);
for(int i=0;i<10;i++)
{
CString out;
out.Format("第%d行",i+1);
pDC->TextOut(i*80, i*100, out);
}
if (pOldFont != NULL)
pDC->SelectObject(pOldFont);
}
// CSAMPLE10_3View 打印
BOOL CSAMPLE10_3View::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CSAMPLE10_3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印前添加额外的初始化
}
void CSAMPLE10_3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印后添加清除过程
}
// CSAMPLE10_3View 诊断
#ifdef _DEBUG
void CSAMPLE10_3View::AssertValid() const
{
CScrollView::AssertValid();
}
void CSAMPLE10_3View::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CSAMPLE10_3Doc* CSAMPLE10_3View::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSAMPLE10_3Doc)));
return (CSAMPLE10_3Doc*)m_pDocument;
}
#endif //_DEBUG
// CSAMPLE10_3View 消息处理程序
void CSAMPLE10_3View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
//设置逻辑单位=1/100英寸,方向为X:右;Y:下
pDC->SetMapMode(MM_ANISOTROPIC);
CSize sizeWindow(1,1);
pDC->SetWindowExt(sizeWindow);
//一英寸有多少象素?
int xLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSX);
int yLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSY);
long xExt = (long)sizeWindow.cx * xLogPixPerInch;
xExt /= 100 ;
long yExt = (long)sizeWindow.cy * yLogPixPerInch;
yExt /= 100;
//物理尺寸
pDC->SetViewportExt((int)xExt, (int)yExt);
CScrollView::OnPrepareDC(pDC, pInfo);
}
//void CSAMPLE10_3View::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
//{
// CScrollView::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
//
// // TODO: 在此添加消息处理程序代码
//}
void CSAMPLE10_3View::OnInitialUpdate()
{
//放置断言失败!
SetScrollSizes(MM_TEXT, CSize(0, 0));
//设置滚动范围
CSize sizeTotal;
//计算此视图的合计大小,窗口大小为10英寸
sizeTotal.cx = 1000;sizeTotal.cy = 1000;
//一页大小
CSize sizePage=CSize(sizeTotal.cx,sizeTotal.cy/2);
//一行大小
CSize sizeLine=CSize(sizeTotal.cx,sizeTotal.cy/10);
CClientDC dc(NULL);
OnPrepareDC(&dc);
//转化为设备坐标
dc.LPtoDP(&sizeTotal);
dc.LPtoDP(&sizePage);
dc.LPtoDP(&sizeLine);
SetScrollSizes(MM_TEXT, sizeTotal,sizePage,sizeLine);
//SetScrollSizes(MM_LOMETRIC, CSize(10*10*20,10*10*30*3),CSize(10*10*20,10*10*30),CSize(10*10,10*10));
// TODO: 在此添加专用代码和/或调用基类
CScrollView::OnInitialUpdate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -