分类:
2008-09-17 11:04:21
BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); /////此行设置控件的父窗口,你也可以去掉该行看看运行效果///////// m_CrystalReport.SetWindowParentHandle((long)(this->m_hWnd)); /////打印报表到窗口中///// m_CrystalReport.PrintReport(); return TRUE; } |
void CMyReportView::OnFileOpen() { char Filter[] = "Crystal Report files(*.rpt)|*.rpt|All files(*.*)|*.*||"; CRect rect; CFileDialog OpenDlg(TRUE,0,0,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,(LPCTSTR)Filter,NULL); if(OpenDlg.DoModal()!=IDOK) ///显示文件对话框 return; CString m_fName=OpenDlg.GetPathName(); ///取得文件名 if(m_CrystalReport) m_CrystalReport.DestroyWindow(); GetClientRect(rect); ///////////////////创建控件/////////////// if (!m_CrystalReport.Create(AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),WS_CHILD| _ WS_VISIBLE,rect,this,IDC_CRYSTALREPORT1)) { AfxMessageBox("控件创建失败!"); return ; } m_CrystalReport.SetWindowParentHandle((long)(this->m_hWnd));///设置父窗口 m_CrystalReport.SetWindowBorderStyle(0); ///设置为没有边框 m_CrystalReport.SetWindowLeft(0); ///左空间 m_CrystalReport.SetWindowTop(0); ///顶部空间 m_CrystalReport.SetWindowControls(FALSE); ///不显示工具条 m_CrystalReport.SetReportFileName(m_fName); ///设置报表文件 m_CrystalReport.SetWindowWidth(rect.Width()); ///设置窗口宽度 m_CrystalReport.SetWindowHeight(rect.Height()); ///设置窗口高度 m_CrystalReport.SetFormulas(0, "Company=\"VC知识库\""); ///将报表中的Company变量的值设置为VC知识库 m_CrystalReport.SetDestination(0); ///设置输出对象是屏幕 m_CrystalReport.PrintReport(); ///显示报表 } void CMyReportView::OnFilePrint() { if(m_CrystalReport && m_CrystalReport.GetReportFileName() != "") { m_CrystalReport.SetDestination(1); ///设置输出对象是打印机 m_CrystalReport.PrintReport(); ///打印 } } |