📄 multiviewreportview.cpp
字号:
// MultiViewReportView.cpp : implementation of the CMultiViewReportView class
//
#include "stdafx.h"
#include "MultiViewReport.h"
#include "MultiViewReportDoc.h"
#include "MultiViewReportView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMultiViewReportView
IMPLEMENT_DYNCREATE(CMultiViewReportView, CView)
BEGIN_MESSAGE_MAP(CMultiViewReportView, CView)
//{{AFX_MSG_MAP(CMultiViewReportView)
ON_WM_SIZE()
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_EXPORT, OnExport)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMultiViewReportView construction/destruction
CMultiViewReportView::CMultiViewReportView():iReport(NULL)
{
// TODO: add construction code here
}
CMultiViewReportView::~CMultiViewReportView()
{
if(iReport != 0)
iReport->Release();
}
BOOL CMultiViewReportView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMultiViewReportView drawing
void CMultiViewReportView::OnDraw(CDC* pDC)
{
CMultiViewReportDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMultiViewReportView printing
BOOL CMultiViewReportView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMultiViewReportView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMultiViewReportView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMultiViewReportView diagnostics
#ifdef _DEBUG
void CMultiViewReportView::AssertValid() const
{
CView::AssertValid();
}
void CMultiViewReportView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMultiViewReportDoc* CMultiViewReportView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMultiViewReportDoc)));
return (CMultiViewReportDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMultiViewReportView message handlers
void CMultiViewReportView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
// 建立viewer, 将报表对象附加到该viewer上.
CRect rect;
GetClientRect(rect);
Viewer.Create(NULL, WS_VISIBLE, rect, this, IDC_VIEWER);
//使 export有效.
Viewer.SetEnableExportButton(TRUE);
CMultiViewReportDoc * doc = (CMultiViewReportDoc *)GetDocument();
IReport * iReport = doc->GetAutoReport();
ASSERT(iReport != NULL);
//连接该报表到viewer.
Viewer.SetReportSource(iReport);
Viewer.ViewReport();
}
void CMultiViewReportView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(Viewer.GetSafeHwnd() != 0)
{
CRect rect;
GetClientRect(rect);
Viewer.MoveWindow(rect.top, rect.left, rect.right - rect.left, rect.bottom - rect.top, TRUE);
}
}
void CMultiViewReportView::OnFilePrint()
{
// TODO: Add your command handler code here
CMultiViewReportDoc * Doc = (CMultiViewReportDoc *)GetDocument();
IReport * iReport = Doc->GetAutoReport();
ASSERT(iReport != 0);
VARIANT prompt, copy, collated, startPage, stopPage;
prompt.vt = VT_BOOL;
prompt.boolVal = VARIANT_TRUE;
copy.vt = VT_I4;
copy.lVal = 1;
collated.vt = VT_BOOL;
collated.boolVal = VARIANT_FALSE;
startPage.vt = VT_I4;
startPage.lVal = 1;
stopPage.vt = VT_I4;
stopPage.lVal = (unsigned long)0xffffffffL;
HRESULT hr = iReport->PrintOut(prompt, copy, collated, startPage, stopPage);
if(hr != NOERROR)
CMultiViewReportApp::ProcHandleError(hr);
}
BEGIN_EVENTSINK_MAP(CMultiViewReportView, CView)
ON_EVENT(CMultiViewReportView, IDC_VIEWER, 425, ExportButtonClicked, VTS_PBOOL)
ON_EVENT(CMultiViewReportView, IDC_VIEWER, 409, PrintButtonClicked, VTS_PBOOL)
END_EVENTSINK_MAP()
void CMultiViewReportView::ExportButtonClicked(BOOL FAR* UseDefault)
{
AfxMessageBox("export按钮单击事件");
}
void CMultiViewReportView::PrintButtonClicked(BOOL FAR* UseDefault)
{
AfxMessageBox("print按钮单击事件");
}
void CMultiViewReportView::OnExport()
{
// TODO: Add your command handler code here
CMultiViewReportDoc * doc = (CMultiViewReportDoc *)GetDocument();
IReport * iReport = doc->GetAutoReport();
ASSERT(iReport != 0);
VARIANT prompt;
prompt.vt = VT_BOOL;
prompt.boolVal = VARIANT_TRUE;
HRESULT hr = iReport->Export(prompt);
if(hr != NOERROR)
CMultiViewReportApp::ProcHandleError(hr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -