⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 docviewcrystalprintview.cpp

📁 一个很好用的报表控件
💻 CPP
字号:
// DocViewCrystalPrintView.cpp : implementation of the CDocViewCrystalPrintView class
//

#include "stdafx.h"
#include "DocViewCrystalPrint.h"

#include "DocViewCrystalPrintDoc.h"
#include "DocViewCrystalPrintView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDocViewCrystalPrintView

IMPLEMENT_DYNCREATE(CDocViewCrystalPrintView, CView)

BEGIN_MESSAGE_MAP(CDocViewCrystalPrintView, CView)
	//{{AFX_MSG_MAP(CDocViewCrystalPrintView)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CDocViewCrystalPrintView construction/destruction

CDocViewCrystalPrintView::CDocViewCrystalPrintView()
{
	// TODO: add construction code here

}

CDocViewCrystalPrintView::~CDocViewCrystalPrintView()
{
}

BOOL CDocViewCrystalPrintView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDocViewCrystalPrintView drawing

void CDocViewCrystalPrintView::OnDraw(CDC* pDC)
{
	CDocViewCrystalPrintDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CDocViewCrystalPrintView printing

BOOL CDocViewCrystalPrintView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDocViewCrystalPrintView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CDocViewCrystalPrintView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDocViewCrystalPrintView diagnostics

#ifdef _DEBUG
void CDocViewCrystalPrintView::AssertValid() const
{
	CView::AssertValid();
}

void CDocViewCrystalPrintView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CDocViewCrystalPrintDoc* CDocViewCrystalPrintView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDocViewCrystalPrintDoc)));
	return (CDocViewCrystalPrintDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDocViewCrystalPrintView message handlers

void CDocViewCrystalPrintView::OnFileOpen() 
{
	// TODO: Add your command handler code here
	char szFilter[] = "Crystal Report files(*.rpt)|*.rpt|All files(*.*)|*.*||";
    CRect szrect;
    CFileDialog FileOpenDlg(TRUE,0,0,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,(LPCTSTR)szFilter,NULL);
	if(FileOpenDlg.DoModal() != IDOK) 
		return;
	CString m_CrystalReportName = FileOpenDlg.GetPathName();
	if(m_CrystalReport)
		m_CrystalReport.DestroyWindow();
	GetClientRect(szrect);
	//下面创建控件
	if (!m_CrystalReport.Create(AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),WS_CHILD|WS_VISIBLE,szrect,this,IDC_CRYSTALREPORT1))
	{
		AfxMessageBox("创建控件失败!");
	    return ;
	}
	m_CrystalReport.SetWindowParentHandle((long)(this->m_hWnd));//设置水晶报表控件的父窗口
	m_CrystalReport.SetWindowLeft(0); 
	m_CrystalReport.SetWindowTop(0); 
	m_CrystalReport.SetWindowBorderStyle(0); //无边框风格
	m_CrystalReport.SetWindowControls(FALSE); //无工具条
	m_CrystalReport.SetReportFileName(m_CrystalReportName); //设置报表文件
	m_CrystalReport.SetWindowWidth(szrect.Width()); //设置报表窗口宽度
	m_CrystalReport.SetWindowHeight(szrect.Height()); //设置报表窗口高度
	m_CrystalReport.SetDestination(0); //输出对象为向屏幕输出
	m_CrystalReport.PrintReport(); //将报表显示到窗口	
}

void CDocViewCrystalPrintView::OnFilePrint() 
{
	// TODO: Add your command handler code here
	if(m_CrystalReport && m_CrystalReport.GetReportFileName() != "")
	{
		m_CrystalReport.SetDestination(1); //输出对象为向打印机输出
	    m_CrystalReport.PrintReport(); //打印报表
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -