// PrintControlView.cpp : implementation of the CPrintControlView class
//
#include "stdafx.h"
#include "PrintControl.h"
#include "PrintControlDoc.h"
#include "PrintControlView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPrintControlView
IMPLEMENT_DYNCREATE(CPrintControlView, CFormView)
BEGIN_MESSAGE_MAP(CPrintControlView, CFormView)
//{{AFX_MSG_MAP(CPrintControlView)
// 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, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrintControlView construction/destruction
CPrintControlView::CPrintControlView()
: CFormView(CPrintControlView::IDD)
{
//{{AFX_DATA_INIT(CPrintControlView)
m_nControlChoice = 0;
m_nPrintChoice = 0;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CPrintControlView::~CPrintControlView()
{
}
void CPrintControlView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPrintControlView)
DDX_Control(pDX, IDC_PICTURE, m_ctlPicture);
DDX_Radio(pDX, IDC_CONTROL1, m_nControlChoice);
DDX_Control(pDX, IDC_CALENDAR1, m_ctlCalendar);
DDX_Control(pDX, IDC_MSCHART1, m_ctlChart);
DDX_Radio(pDX, IDC_RADIO_PRINT1, m_nPrintChoice);
//}}AFX_DATA_MAP
}
BOOL CPrintControlView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CPrintControlView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CPrintControlView diagnostics
#ifdef _DEBUG
void CPrintControlView::AssertValid() const
{
CFormView::AssertValid();
}
void CPrintControlView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CPrintControlDoc* CPrintControlView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPrintControlDoc)));
return (CPrintControlDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPrintControlView printing
BOOL CPrintControlView::OnPreparePrinting(CPrintInfo* pInfo)
{
// limit pages for testing
pInfo->SetMinPage(1);
pInfo->SetMaxPage(1);
// default preparation
return DoPreparePrinting(pInfo);
}
void CPrintControlView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
}
void CPrintControlView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
}
/////////////////////////////////////////////////////////////////////////////
// Demonstration code
// *********************************************************
// ErrorMessage
//
// Looks up and displays an error message.
//
// Arguments:
//
// hr - (HRESULT, input) the error code
// strError - (CString, input) the error string (may be blank)
//
// Returns:
//
// Nothing
//
void ErrorMessage(HRESULT hr, CString strError)
{
CString strTemp;
// use the string if given
if (!strError.IsEmpty())
{
strTemp.Format(_T("Error - 0x%08X, %s"), hr, strError);
AfxMessageBox(strTemp);
}
else
{
// attempt to get the message from the system
LPVOID lpMsgBuf = NULL;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ))
{
strTemp.Format(_T("Error - 0x%08X, %s"), hr, lpMsgBuf);
AfxMessageBox(strTemp);
LocalFree(lpMsgBuf);
}
// unknown error code
else
{
strTemp.Format(_T("Unknown Error - 0x%08X"), hr);
AfxMessageBox(strTemp);
}
}
}
// *********************************************************
// PrintTitle
//
// Prints a title string on the top of the page so we can
// identify the print mechanism.
//
// Arguments:
//
// pDC - (CDC *) the printer device context
// pInfo - (CPrintInfo *) the print info structure pointer
// strTitle - (CString, input) the title string
//
// Returns:
//
// Nothing
//
void CPrintControlView::PrintTitle(CDC* pDC, CPrintInfo* pInfo, CString strTitle)
{
// create the font for the title (note assumes MM_TEXT mode)
CFont fntPrintFont;
int nHeight = -MulDiv(10, pDC->GetDeviceCaps(LOGPIXELSY), 72); // 10 point font
fntPrintFont.CreateFont(nHeight, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, 0, DEFAULT_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("MS Shell Dlg"));
// switch to our font
CFont *pOldFont = pDC->SelectObject(&fntPrintFont);
// get a reference to the drawing rectangle
CRect &rcPage = pInfo->m_rectDraw;
// draw the title
int nCurrentY = rcPage.top + 100;
CSize sizeHeader = pDC->GetTextExtent(strTitle);
pDC->TextOut(100, nCurrentY, strTitle);
// move down a little
nCurrentY += sizeHeader.cy * 2;
// adjust the remaining printable area
rcPage.top = nCurrentY;
// clean up
pDC->SelectObject(pOldFont);
fntPrintFont.DeleteObject();
}
// *********************************************************
// OnPrint
//
// Standard MFC print framework routine. Called for print or
// print preview.
//
// Arguments:
//
// See the MFC documentation for OnPrint.
//
// Returns:
//
// Nothing
//
void CPrintControlView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// Note: in all cases we assume the printer can handle graphics, etc.
// transfer choices to member variables
UpdateData(TRUE);
// get the selected control
CWnd *pWnd = NULL;
if (m_nControlChoice == 0)
pWnd = &m_ctlChart;
else if (m_nControlChoice == 1)
pWnd = &m_ctlCalendar;
else
pWnd = &m_ctlPicture;
// print using the selected radio option
switch (m_nPrintChoice)
{
case 0: // draw using a screen device context, then transfer to printer dc ourselves
PrintTitle(pDC, pInfo, _T("IViewObject::Draw (Screen DC)"));
PrintControlUsingScreen(pWnd, pDC, pInfo);
break;
case 1: // draw using the printer device context directly
PrintTitle(pDC, pInfo, _T("IViewObject::Draw (Printer DC)"));
PrintControlUsingPrinter(pWnd, pDC, pInfo);
break;
case 2: // draw into a metafile, then transfer to the printer dc ourselves
PrintTitle(pDC, pInfo, _T("IViewObject::Draw (Metafile)"));
PrintControlUsingMetafile(pWnd, pDC, pInfo);
break;
case 3: // getdata into a metafile, then transfer to the printer dc ourselves
PrintTitle(pDC, pInfo, _T("IDataObject::GetData (Metafile)"));
PrintControlGetData(pWnd, pDC, pInfo);
break;
case 4: // use WM_PRINT to the print to the printer device context directly
PrintTitle(pDC, pInfo, _T("WM_PRINT (Printer DC)"));
PrintControlWmPrint(pWnd, pDC, pInfo);
break;
default:
ASSERT(FALSE); // bad option selection
break;
}
}
/////////////////////////////////////////////////////////////////////////////
// These are the functions that do the control printing.
/////////////////////////////////////////////////////////////////////////////
// *********************************************************
// PrintControlUsingScreen
//
// Prints the control by using the IViewObject::Draw routine
// to an offscreen memory device context. This data is then
// simply transferred to the printer device context.
//
// T
没有合适的资源?快使用搜索试试~ 我知道了~
打印与预览 ocx显示的内容
共25个文件
h:8个
cpp:7个
ico:2个
1星 需积分: 9 24 下载量 147 浏览量
2011-05-24
11:14:05
上传
评论 1
收藏 50KB ZIP 举报
温馨提示
经典案例 在应用程序中打印与预览OCX控件中的内容,应用程序为DOC-VIEW模式,OCX为任何普通控件。
资源推荐
资源详情
资源评论
收起资源包目录
PrintControl.zip (25个子文件)
PrintControl
PrintControl.dsw 547B
StdAfx.cpp 214B
resource.h 1KB
PrintControlDoc.cpp 2KB
mschart.cpp 15KB
mschart.h 5KB
PrintControl.clw 3KB
PrintControlView.cpp 23KB
MainFrm.h 2KB
PrintControl.rc 52KB
PrintControl.h 1KB
PrintControl.dsp 5KB
Debug
StdAfx.h 1KB
PrintControlView.h 3KB
MainFrm.cpp 3KB
Release
PrintControl.exe 72KB
calendar1.cpp 9KB
res
PrintControlDoc.ico 1KB
PrintControl.ico 1KB
TestPicture.bmp 21KB
Toolbar.bmp 1KB
PrintControl.rc2 404B
calendar1.h 3KB
PrintControlDoc.h 2KB
PrintControl.cpp 4KB
共 25 条
- 1
资源评论
- 我不是浆糊2019-08-01垃圾资源,害人不浅。谁下谁被坑
no_17
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功