article directory
 

Initialize Your Win32 Printer - By: Susan10

It is frequently found that using a Printer in Win32 programming is the toughest suggestion. Living in a time of command line programming and DOS, for controlling the outputs, we simply get redirected towards the line Printer or exercise with the codes of the Printer. Therefore the operating systems of Windows, such as Windows XP, Windows 7 etc, enfold the various interfaces and make use of the device abstraction for controlling a Printer and its peripherals.

Considering this, the advantages will be, we can solve all the printer problems on any printer, utilizing the same kind of codes, and Windows will watch out and translate every command the user uses according to your wireless Printer. But the disadvantage is that it does offer any added layer of intricacy. This can be tough to visualize for the programmers who are just beginners and also to the experienced coders as well.

Therefore before starting the whole process you should remember the following things:

· The controlling procedure of the wireless Printer is carried out in the simplest way.

· To solve the Printer related problems one can use most of the HDC related output mechanisms.

In addition to it, we can choose the wireless Printer that is a default one. Choosing the Printer requires a single command that works against the requirement of displaying the printer dialog box to the user.

Printing in the operating systems of Windows

We can make a print in the operating systems of Windows such as Windows XP. That is before we start to continue with certain other processes we are required to get hold of a device context (HDC). Its correct sequence is illustrated below:

· Choose a wireless printer.
· Obtain a suitable device context.
· Start the document.
· Make a beginning of the page.
· Finish the last part of the page.
· Draw the conclusion line of the document.
· Erase the context of the device.

Choosing the Printer that is Default

Selection of a Printer that is a default one can be selected by its name. The selection process includes two-step procedures. These are:

· Obtaining the name
· Choosing the printer

Both the processes are acquired by obtaining a device context to it:

char szPrinterName[255];
unsigned long lPrinterNameLentgth;
GetDefaultPrinter( szPrinterName, &lPrinterNameLength );
HDC hPrinterDC;
hPrinterDC = CreateDC("WINSPOOL", szPrinterName, NULL, NULL);

In the command that is discussed on the top will ensure the reader to note that WINSPOOL queue has been used for obtaining the actual handle to the default printer.

One final task is remaining to continue as a part of the process of initialization. To continue this, we are required to utilize the structure of DOCINFO:

DOCINFO di;
memset( &di, 0, sizeof(DOCINFO) );
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "PrintIt";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;

The DocName can be anything that the application programmer finds appropriate. It will appear on the printer as part of the job name. Having set some reasonable defaults, we can now call StartDoc, and check for errors:

int nError = StartDoc(hPrinterDC, &di);
if (nError == SP_ERROR)
{
printf("nError - please check printer.");
// Handle the error intelligently
}

Now your computer is ready to initialize your Printing process along with your Windows XP and other operating systems.

About the Author

Susan Brown, Seattle, is thoroughly equipped with latest technological development. Her articles are attuned to technological development and modern solutions to age old computer-related problems. She talks about remote assistance and its benefits. She is working with Online PC 24x7 for more than a decade as an expert technical writer.

Article Directory Source: http://www.articlerich.com/profile/Susan10/71248




Click the XML Icon Above to Receive Articles Via RSS!

Page copy protected against web site content infringement by Copyscape

Do not copy content from the page unless you comply with our terms of service.
Plagiarism will be detected by Copyscape.