Easy Report Processing in the Visual C ++ Environment

zhaozj2021-02-08  219

Visual C Environment Easy Report Processing Zhejiang Wenling Telecom Bureau Wang Jun

This article is suitable for the reader level: primary, intermediate

Foreword Database is widely used in the enterprise software system, while the report's display and printing becomes the necessary functions of such software. Unfortunately, VC does not integrates the report acceptance tool, but its powerful features plus the functional report processing tools on the market make this work easily. This article describes the Crystal Report (Crystal Report) using Seagate in the VC environment. To implement the display and printing of the report, and provide sample code. I. Preparation (1) Installing the Crystal Report Software Crystal Report 4.6 is a free report tool that can be found on CDs such as VB5 or Windows NT 4.0 BackOffice. Crystal Report4.6 contains report design tools and report print controls. The issuance of the program only needs to install the print control related section. Netizens who can't find this software can be downloaded to the VC Knowledge Base site. Website is http://www.vckbase.com/ocx/report (2) Design Report We generate a report called Sample.rpt, this process can be referenced Crystal Report comes with help documentation, this article does not introduce a detailed introduction. This file has been included in the sample code you can also download it directly, click here to download II. Creating a VC Project Add Report Control In the VC Integration Environment, create a new MFC single document engineering, the rest option. Both are default. Select Project-> Add to Project-> Components and Controls ... Pop-up components, control selection dialog box, enter Registered ActiveX Controls, select Crystal Report Control 4.6, click the Insert button, confirm, and enter the class configuration dialog box, press By default. Turns off the control selection dialog Completes the addition of the control. Third, the display and printing of the report is under the dialog box's static creation process, and the dynamic creation process of the control is demonstrated in the main view. 3.1 Print the report in the dialog box to open the ID of the IDD_ABOUTBOX in the resource editor, in the Controls toolbar, we can find the Crystal Report Control 4.6 control button just added to the project to insert it into the dialog. At the location. Right-click on the controls in the dialog, select Properties, and you can set up a number of properties for the control. We entered the report file name Sample.rptfilename in the Control Options page ReportFileName, set the appropriate location of the control in the Print Window option page, and press and hold the Ctrl key in the dialog template, double-click the left mouse button, The Add Member Variable dialog pops up, we name the member variable m_crystalReport, open the classwizard, add the process function for the WM_INITDIALOG message for the CaboutDLG dialog: BOOL OnItDialog (), and do the following processing in the function

Bool caboutdlg :: OnNitDialog () {cdialog :: OnIndIalog (); / This row sets the parent window of the control, you can also remove the row to see the running effect / m_crystalreport.SetWindowParentHandle ((Long) (THIS "(THIS system_hwnd); / Print Report to the window / m_crystalreport.printreport (); return true;} To this, the first part of the program is written, compile, open the About dialog, look at the effect!

Oh! Not bad! If you don't show a report, there is a possible reason: (1) The control is not placed in a suitable location or size is wrong. (2) The report file itself exists such as a data source to be unavailable. The toolbar in the control window provides scaling, printing and other functions, you can also try the effect of printing on the printer. 3.2 Displaying the report in the program main window Open ClassWizard to increase the handler for id_file_open and id_file_print, the code is as follows void cmyreportview :: onfileopen () {char filter [] = "crystal report files (*. Rpt) | *. Rpt | All Files (*. *) | *. * || "; CRECT RECT; CFiledialog OpenDLG (True, 0, 0, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, (LPCTSTSTSTSTER) FILTER, NULL); if (OpenDLG.Domodal ()! = IDOK) // / Display file dialog return; cstring m_fname = OPENDLG.GETPATHNAME (); /// gets the file name if (m_crystalreport) m_crystalreport.destroyWindow (); getClientRect (RECT); /// creation control /// if (! M_crystalReport. create (AfxRegisterWndClass (0, AfxGetApp () -> LoadStandardCursor (IDC_ARROW)), WS_CHILD | WS_VISIBLE, rect, this, IDC_CRYSTALREPORT1)) {AfxMessageBox ( "controls creation failed!"); return;} m_CrystalReport.SetWindowParentHandle ((long) ( This-> m_hwnd); /// Set the parent window m_crystalreport.SetWindowBorderstyle (0); // 设置 set to no border m_crystalreport.SetWindowleft (0); /// Left space m_crystalreport.SetWindowtop (0); /// top space m_CrystalReport.SetWindowControls (FALSE); /// not show the toolbar m_CrystalReport.SetReportFileName (m_fName); /// set the report file m_CrystalReport.SetWindowWidth (rect.Width ()); /// set the window width m_CrystalReport.Set WindowHeight (Rect.Height ()); /// Settings Window Height M_CrystalReport.setFormulas (0, "Company = /" VC Knowledge Base / "); // Set the value of the COMPANY variable in the report to VC Knowledge Base m_CrystalReport.SetDestination (0); /// set the output destination is the screen m_CrystalReport.PrintReport (); /// Show report} void CMyReportView :: OnFilePrint () {if (! m_CrystalReport && m_CrystalReport.GetReportFileName () = "") { m_crystalReport.SetDestination (1); /// Setting the output object is the printer m_crystalreport.printreport (); /// print}} The program operation is as follows

Click here to download the sample code: We use Crystal Report 4.6 to implement report processing in the VC environment, but Crystal Report 4.6 report control features and controllable performance may not meet your requirements, and the latest version of this software in this software is Crystal. Report 8.0, all aspects are excellent, but the free version of this software does not include report designers, gratifying the report display controls in 8.0 compatible with previous version of the report format, so I recommend using a 4.6 version to design reports. Relying on the report display control in 8.0 to display, print. --- www.vckbase.com ---

转载请注明原文地址:https://www.9cbs.com/read-1746.html

New Post(0)