Wednesday, April 7, 2010

How to print using Win32 Printer functions in VB 6.0?

Dot Matrix Printing Part 1


Reporting and Printing are essential part any commercial application. Visual Basic offers many methods to create professional reports and print those reports. Seagate Crystal Reports (now business objects) is the most popular report authoring tool for Visual basic. It can fetch data from any kind of Database SQL, MS-Access, OLEDB and ODBC. VB 6.0 offers in-built reporting tool data reports.

But one draw back using these tools is observed while printing. When you print a report using dot-matrix line printer it takes a long time to print text reports. This is because the it uses Windows GDI printing technology. Windows prints everything as graphics not as text. In contrast DOS applications use text mode for printing. Thus the printing will be faster in DOS applications. For point-of-sale and counter billing purpose this speed is desired. Print Quality is not important in POS and billing softwares.

To achieve the fast printing in windows applications you must use the raw printing method. This is achieved by using Win32 API functions. There are standard Win32 printer functions to accomplish raw printing in Windows Environment.

OpenPrinter()
StartDocPrinter()
StartPagePrinter()
WritePrinter()

are the Win32 functions used to open a printer and get a handler and write data to the printer. In the next part of this tutorial we will see the declaration of these functions in VB code, passing of parameters to these functions, writing raw data and closing printer object. The examples should help you create your own printing solution for your VB 6.0 projects that use Dot matrix printing for POS or billing. You can also use text printing to print large Accounting statements etc.

 Dot matrix printing part 2