Easy Printing
Language: C++
Compiler: MS Visual C++ 5.0 SP3
Environment: Windows 9x/NT
What's this?
This is the easiest way to print data on printer without using all the MFC framework; you don't need document/view programming style to use a valid printing method.
With this code it's possible to print everything wherever you are: it's possible to implement this printing method in a non-windows classes too with little modifies.
How does it work?
Download source code (14 kb)
This method uses following steps:
- call the tipical 'Print' dialog;
- attach the printer device context to a device context used in following steps;
- initialize print documents details;
- calculate the scale factors (depending on the printer resolution);
- create one or more fonts;
- start the printing document;
- set paper orientation or size if necessary;
- start first page;
- select font (or fonts);
- let's print using ALL the Device Context drawing instructions (like lines, rectangles, ellipses, drawing text and more...);
- end first page;
- 'deselect' fonts;
- set paper orientation or size if necessary;
- start second page;
- select font (or fonts);
- let's print using ALL the Device Context drawing instructions (like lines, rectangles, ellipses, drawing text and more...);
- end second page;
- 'deselect' fonts;
- end document;
- detach the device context;
- That's all.
Of course you can print more than two page, or just one page too.
Remember: this method is really easy, but it's hard to use with complex page layout. If you have to design compex pages I suggest you to use the Richard Stringer Printing Class Library. It's fantastic: you can also define tables, print images, print rotated text and more.
Now you can send me a comment or
suggestions for next atricles. Thanks.
Feel free to contact me if you found an error (any kind) in this article.
Back to Articles Page