小标
2018-08-28
来源 :
阅读 3107
评论 0
摘要:本文主要向大家介绍了VC编程之VC2015调用Grid++report报表控件,通过具体的内容向大家展示,希望对大家学习VC编程有所帮助。
本文主要向大家介绍了VC编程之VC2015调用Grid++report报表控件,通过具体的内容向大家展示,希望对大家学习VC编程有所帮助。
Grid++report这是一个国产报表控件,从2.x就开始接触,基本所有的学习资源,来自于自带的文档和例子。能学多少靠摸索。整体功能还是不错的。他提供了3个控件,一个组件。在VC2015如果不想用控件,只想调用组件实现打印的功能,怎么办呢?步骤如下:(1)在afxstd.h文件中包含头文件如下:#include
extern CComModule _Module;
#include
BOOL CMFCApplication1App::InitInstance()
{//初始化报表COM组件
HRESULT hRes = ::CoInitialize(NULL);
ATLASSERT(SUCCEEDED(hRes));
_Module.Init(0, AfxGetInstanceHandle());
//......
}
int CMFCApplication1App::ExitInstance()
{//重写虚函数
_Module.Term();
::CoUninitialize();
return CWinApp::ExitInstance();
}(3)在对话框的头文件中,加入如下:#include "GetPath.h"
#include "GRImport.h"当然需要先将Grid++report目录下的Utility文件夹复制到工程目录中,并在“项目属性->VC++目录->包含目录”添加Utility文件夹。(4)在对话框类中添加成员变量:IGridppReportPtr m_pGridppReport;BOOL CMFCApplication1Dlg::OnInitDialog()
{
//创建报表主对象
m_pGridppReport.CreateInstance(__uuidof(GridppReport));
ATLASSERT(m_pGridppReport != NULL);
//加载模板文件
//从文件中载入报表模板数据到报表主对象
CString FileName = GetReportTemplatePath(_T("标准过磅单1.grf"));
m_pGridppReport->LoadFromFile((LPCTSTR)FileName);
//第(7)步还有代码
}void CMFCApplication1Dlg::OnDestroy()
{
CDialogEx::OnDestroy();
//释放主报表对象
m_pGridppReport.Release();
}
void CMFCApplication1Dlg::OnBnClickedButton1()
{
//直接打印报表
m_pGridppReport->Print(TRUE);
}
void CMFCApplication1Dlg::OnBnClickedButton2()
{
// 显示预览窗口
m_pGridppReport->Title = _T("标准过磅单1");
m_pGridppReport->PrintPreview(TRUE);
}(5)同时将导出库复制到工程路径下,即gregn.tlb 和 grdes.tlb(6)要动态修改报表参数,可以新建一个类,继承报表事件处理接口。//Scale3DCReportEvent.h头文件
#pragma once
#include "GridppReportEventImpl.h"
class CScale3DCReportEvent :public CGridppReportEventImpl
{
public:
CScale3DCReportEvent();
~CScale3DCReportEvent();
virtual void Initialize(void);
IGridppReportPtr m_pGridppReport;
};//Scale3DCReportEvent.cpp文件
#include "stdafx.h"
#include "Scale3DCReportEvent.h"
#include "GridppReportEventImpl.c"
CScale3DCReportEvent::CScale3DCReportEvent()
{
}
CScale3DCReportEvent::~CScale3DCReportEvent()
{
}
void CScale3DCReportEvent::Initialize(void)
{
m_pGridppReport->ParameterByName(_T("车号"))->AsString =_T("猎豹太空梭0X29");
}(7)在相应的对话框头文件中包含:#include "Scale3DCReportEvent.h"//事件包装类#include "GetPath.h" //上面步骤已包含过#include "GRImport.h"在窗口类中声明成员变量://报表事件代理指针CGridppReportEventImpl *m_pReportEvents;在窗口的OnInitDialog()中添加如下代码://创建事件响应对象
CComObject
CComObject
m_pReportEvents = pEvent;
m_pReportEvents->AddRef();
pEvent->m_pGridppReport = m_pGridppReport;//事件代理指针
HRESULT hr = m_pReportEvents->DispEventAdvise(m_pGridppReport,
&__uuidof(_IGridppReportEvents));
ATLASSERT( SUCCEEDED(hr) );(8)在ON_WM_DESTROY消息中继续添加代码://释放事件代理
if (m_pReportEvents != NULL)
{
HRESULT hr = m_pReportEvents->DispEventUnadvise(m_pGridppReport,
&__uuidof(_IGridppReportEvents));
m_pReportEvents->Release();
m_pReportEvents = NULL;
ATLASSERT(SUCCEEDED(hr));
}
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言VC/MFC频道!
喜欢 | 2
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号