【VC开源代码栏目提醒】:网学会员VC开源代码为您提供SetPageSizeView.cpp参考,解决您在SetPageSizeView.cpp学习中工作中的难题,参考学习。
// SetPageSizeView.cpp : implementation of the CSetPageSizeView class
//
#include "stdafx.h"
#include "SetPageSize.h"
#include "SetPageSizeDoc.h"
#include "SetPageSizeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSetPageSizeView
IMPLEMENT_DYNCREATE(CSetPageSizeView, CView)
BEGIN_MESSAGE_MAP(CSetPageSizeView, CView)
//{{AFX_MSG_MAP(CSetPageSizeView)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CSetPageSizeView construction/destruction
CSetPageSizeView::CSetPageSizeView()
{
// TODO: add construction code here
}
CSetPageSizeView::~CSetPageSizeView()
{
}
BOOL CSetPageSizeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSetPageSizeView drawing
void CSetPageSizeView::OnDraw(CDC* pDC)
{
CSetPageSizeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->TextOut(0,0,"请点击文件菜单下的打印菜单项!");
}
/////////////////////////////////////////////////////////////////////////////
// CSetPageSizeView printing
BOOL CSetPageSizeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSetPageSizeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo *pInfo)
{
CPrintDialog printDlg(FALSE);//构造打印设置对话框对象
CDC dc;
printDlg.GetDefaults();//检取缺省打印设备的设备环境
DEVMODE *dm=(LPDEVMODE)::GlobalLock(printDlg.GetDevMode());
dm->dmOrientation=DMORIENT_PORTRAIT;
dm->dmFields|=DM_PAPERSIZE;
//将打印纸大小设为自定义
dm->dmPaperSize=DMPAPER_USER;
//定义打印纸的长宽
dm->dmPaperLength=1800;
dm->dmPaperWidth=1800;
CString strLength(""),strWidth("");
strLength.Format("%.2f",dm->dmPaperLength/100.);
strWidth.Format("%.2f",dm->dmPaperWidth/100.);
AfxMessageBox("您设置的打印页面长度为:"+strLength+"厘米\n"+
"您设置的打印页面宽度为:"+strWidth+"厘米");
::GlobalUnlock(dm);
pInfo->m_pPD->m_pd.hDC=printDlg.CreatePrinterDC();
}
void CSetPageSizeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSetPageSizeView diagnostics
#ifdef _DEBUG
void CSetPageSizeView::AssertValid() const
{
CView::AssertValid();
}
void CSetPageSizeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSetPageSizeDoc* CSetPageSizeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSetPageSizeDoc)));
return (CSetPageSizeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSetPageSizeView message handlers