|
 |
Prize winner in Competition "MFC/C++ Feb 2005"
|
|
|

Introduction
Printing is a normal part of most applications, but far too convoluted for many developers. The amount of work necessary to add printing of lists and reports to an application often seems daunting, and there are many pitfalls. Here, I come to the aid, with a package containing a plug-in report generator working with template files, a SDI-demo, a plug-and-play report editor for the template files, as well as a demo of the latter. And documentation! The code is intended either for use as-is in your own applications, or as a CReportEditor as well.
ReportCreator also contains a ruler that can be ripped out and used with other CDiagramEditor-derived works. This is an exercise left to the reader, however.
The documentation contains docs on the package structure.
Using ReportCreator
ReportCreator is an editor for the report generator template files. It's first and foremost a vector editor, letting you draw fields on screen with all the features of CDiagramEditor, such as panning, zoom, multiple selects, and much, much more.
It allows you to work in pixels, centimeters or inches as is befitting for a printer-oriented application. The documentation contains detailed information.
Licenses
If you want to add the package(s) or parts of them into your own code - commercial or not, you are completely free to do so. The code comes with the TISATAAFL-license, There Is Such A Thing As A Free Lunch, and you are free to modify, rewrite, resell or do whatever you feel like with the code. You are explicitly allowed to remove my comments in the source and headers, replacing them with your own. You don't have to acknowledge me, neither in code, nor in documentation or the finished application if you should use the code in a commercial application.
History
6/5 2005
Initial version.
28/5 2005
First of all, a few bug corrections:
- Fixed resource leak in
CCornerBox::OnPaint in the report creator (alex_br).
- Fixed silly line-thickness bug in draw object line thickness/brush creation (lordly).
As well as a few others that was removed as a spin-off from other modifications.
There are also quite a few changes:
- Multi-template reports. A report can be composed from several templates, for example, a title page, several sections and a summary (Carsten Bøgh Poulsen).
- Dynamic object access. Objects can be accessed at runtime, so attributes can be inspected and modified. Objects can also be added at runtime (Håkan Nilsson).
- More special markers for fields and cells. [%bold%] and [%italic%] will make the field/cell bold or italic respectively. [%separator%], [%bold-separator%], [%double-separator%] will draw a thin line, a thick line or a double line across a row in a grid instead of data (Carsten Bøgh Poulsen).
- Images can not only be set from files, but also from
HBITMAPs and handles to DIBs (Alex Evans).
- Templates can not only be added from file, but also with data from a
CStringArray, a LPCTSTR, a CFile or even from the application resources (DaberElay, Carsten Bøgh Poulsen).
1/10 2006
This project has been neglected for some time, but now it's time for an update! This time, we have:
- Returning
TRUE from Add when adding data as per documentation
- Added support for font charset. (Vladimir Svrkota, J Bartkowiak).
- Added locale-handling (J Bartkowiak).
- Added [%pagebreak%]-command for grids. This works as the other commands, when putting this text in a cell, the grid will break and continue on the next page. (Charlie Curry, Carsten B Poulsen)
- Added a function call
ReplaceCell to set cell data in a grid. This call replaces the data in a specific cell with new data. (Carsten B Poulsen)
And a big thanks for all the help, feedback and support for this project!
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 484 (Total in Forum: 484) (Refresh) | FirstPrevNext |
|
 |
|
|
Is there a way to assign attributes (almost back/fore color,font weight and text alignment) to a grid's cell programmatically from code?
thanks for this fantastic piece of code, anyway.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for the feedback!
CReportGenerator::GetObject gives access to the individual drawing objects, then you can use RTTI to cast the objects to the specific type, or access the public CDrawObject members.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
Lots of enhancements would be possible, calculated fields, image fields etc. etc. etc. What you have here is a documented framework to build from, or rather to derive from and add to as you see fit. The main purpose of the code is to give a way to create reports, which I know something that is a daunting task initially even for experienced programmers.
I will indeed continue to maintain the code, but find little time to expand on it in the forseeable future, unfortunately.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Firstly, I should say thank you very mush for your great code. Your code is very helpful for me.
My questioin is how to add new menu items to the pop-up menu (right button message) for different entities seperately without modifying your source code?
I'm looking forward to your answering.
Thanks!
Xiaoming Huang
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I have used the Report Generator in my application for several years and appreciate the work you have done on this.
After upgrading my compiler to Visual Studio 2008 SP1 (from Visual Studio 2008), my application now bombs when trying to print or print preview from release mode if the the page includes a grid of any kind (empty/full, with or without lines, etc.). The problem only seems to occur on Vista Machines, not on XP machines. The application does not fail in debug mode.
Please let me know if you have any suggestions.
Scott Moss
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
I was able to determine that the problem (application will crash) is not related to Windows Vista (the error also occurs in Windows XP).
It actually is related to the upgrade of Microsoft .Net Framework 2.0 Service Pack 1 (SP1) to Service Pack 2 (SP2). If you upgrade your compiler to Visual Studio 2008 SP1, this installation will also install Microsoft .Net 3.5 SP1. This .Net upgrade also upgrades .Net Framework 2.0 from SP1 to SP2. When this upgrade of .Net 2.0 occurs, printing no longer works.
Also, I believe that the error only occurs if the application uses the new MFC ribbon interface (I was able to do a print preview using the Report Generator when creating an application that did not use the ribbon interface).
I know that the error is occurring in the CDrawGrid Draw method but am unable to isolate the actual error.
To temporarily solve the problem, I made sure that .Net 3.5 (not SP1) was installed on user machines.
Scott Moss
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks a lot for the info! Not running VS2008 (still using MSVC 6.0, yes, I know I'm old and conservative), this is not something I can easily analyse.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Firstly, I should say thank you very mush for your great code. Your code is very helpful for me.
My questioin is how to add new menu items to the pop-up menu (right button message) for different entities seperately without modifying your source code?
I'm looking forward to your answering.
Thanks!
Xiaoming Huang
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
The report files are saved in 8-bit-per-character format, but when loading from the resource section, they are treated like a LPCSTR. But what we want is the TCHAR form. So, in BOOL CReportGenerator::AddTemplate( UINT resourceID, int type ), modify the contents of if (hGlobal) {...} to
LPCSTR buf = (LPCSTR) ::LockResource( hGlobal ); if( buf ) { CString template_contents(buf); result = AddTemplate( (LPCTSTR)template_contents, type ); }
to make it work.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Thanks for this great component Johan.
I have a general question which, since nobody has asked for the last 3 years, must be a stupid one. How do people generally deal with different paper sizes? I have a report that I'd like people to be able to print on different paper sizes, let's say A4 and letter. Do I need to make different reports for these sizes, check which paper size the user has selected in the print dialog and select the right report at runtime, or is there a way to for example say that a grid should have a width of 100% of the page width, independent of the actual size of the paper?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I find this a valid question indeed. There are 3 measurements you can use when handling printouts, device dependent, physical and relative.
Device dependent is the least useful, but the one that people mostly stumble on, in my experience. You work in pixels or pels, and get surprised when the printouts have different sizes on different media - as different printers print a different amount of pixels depending on the resolution of the printer.
Physical measurements are by far the most useful, and what most people really wants. You don't want a field of 800 pixels horizontally, you want a field one inch wide.
Measurements relative to the size of the out media is not so common, especially not for reports. Typically, you would want this for images - if you are printing a poster, you would most likely want it to cover the printable area regardless of paper size.
A report using relative sizes would most likely need a mix of relative and physical measurements - if you have a grid, you would most likely want it to cover a fixed percentage of the width, but the individual lines should have a fixed height, and a larger paper would admit more lines rather than upscaled ones (even though with A4 versus legal, I can imagine that you would, in fact, just want a scaling). Also, a further complication is the text content of fields. It would be a strange report indeed if not only the width of the fields was scaled to a larger paper, but the font as well!
As you can see, it's a tricky question, where there might be an awful lot of different versions of scaling for a field. One way to handle this would be to break down the desired settings:
Absolute size of the field in physical measurements in one dimension/relative size of the field in percentage in one dimension
Scaling of the conents of the field for any relatively sized fields/no scaling of the same.
This would have to be added as flags for (derived) field objects, and then used during drawing/print out. As it is possible to ask the printer for the current resolution, scaling itself is not a problem.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Ok I see, looks like this would be rather complicated to implement. For now I'll just stick with providing templates with the most common paper sizes in my application I guess. I'm not very well versed in using this library yet, when I get some more experience I'll have a better informed opinion on the best way to go for my application.
Your library is helping me out a lot, I was wondering you'd appreciate a hand as a way of giving back. You mention somewhere in the comments that you don't want to spend too much time on the report designer, would you like me to do some work on that? The VS2008 feature pack has a bunch of great new MFC controls, I could maybe go over the dialogs, make them a bit more modern, is there any other functionality that would be helpful? Having a zoom in / out button would be nice for me, what do you think?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
How to get the ratio of scale of screendc and printerdc.It seems that they are the same and the ratio is 1. Then, the fields are small in preview mode. Where am I wrong?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
You should not need this, normally. As for print previews, use physical measurements instead. You can inspect how the preview is implemented in the test application, for example.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
You can see my other articles for stuff like zoom-support (this is alredy supported in the underlying CDiagramEditor). A hand is always welcome, I would suggest that you fork out into a separate artice (so I don't have to support it ), then I'll link to it from this one. Feel no pressure to do it, however.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for your great work.When I browing on the internet for so much time to find a print demo program. Your code is just what I need. I cannot believe it that it fits me completely.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have a problem about how to use CReportEntityField. When and where I set the value for a field object when I print it.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for your kind feedback!
You might want to take a look at the documentation - SetReportfile to load a report, Add on the different fields to add data for printouts. You might want to inspect the demo application as well.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|