PrintDIB

#include "BIPRINT.H"

 

int CALLBACK PrintDIB( HWND          hWnd,
HDC              hPrnDC,
HANDLE      hDib,
LPTSTR        lpImgName,
LPPOINT      lpptDPI,
LPGPRINT   lpPrint,
LPRECT        lprScale)

Description

Prints a device dependent bitmap called hDIB. The Image will be scaled according to the DPI (dot per inch) resolution found in the lpptDPI data structure relative to the device resolution. For example, if the device is 300 DPI and the image is 100 DPI, the image will stretch to be scaled to the higher resolution device.

Parameters

HWND

hWnd

Window handle

HDC

hPrnDC

Printer DC. if NULL use default printer

HANDLE

hDib

DIB handle

LPTSTR

lpImgName

Pointer to image file name

LPPOINT

lpptDPI

Image DPI, if NULL use screen DPI

LPGPRINT

lpPrint

Pointer to the Print information structure.

If NULL, print DialogBox will be displayed.

LPRECT

lprScale

Scaling factor for image

Additional Information

This example shows how to use the dll when loading statically including the header file. Otherwise if the dll is loaded dynamically, for further information read the “About the difference of static and dynamic library loading” section of the manual.

Return values

IMG_PRINTEROK               // OK or print dialog box is cancelled

IMG_PRINTERRASTER      // device not capable to handle raster

IMG_PRINTERESC4            // Escape failed SETABORTPROC

IMG_PRINTERESC5            // Escape failed STARTDOC

IMG_PRINTERESC6            // Escape failed NEXTBAND

If the Error Code < 0 see GetLastError windows API function to get extended error information.

Programming notes

More than one active printer can be installed at the same time; the first will be highlighted in the Printer Setup dialog box.

Horizontal scaling when the source DPI is less than the destination DPI, is given by the formula:

                                                X / S = Y

...where S = scaling computed from DPI of source and destination; X = xPrnPage, the physical page size returned by DeviceCap; and Y = fxPrnPage, the maximum width of the page before it overlaps to the next page after stretching the bitmap by using the DPI scaling factor.

Vertical scaling when the source DPI is less than the destination DPI is accomplished via the same method as horizontal scaling.

Dot Per Inch: the GetDeviceCap() will return the maximum possible DPI setting regardless of current lower settings. For example, an HPLC driver will return a value of 300 DPI even though the current driver setting is 100 DPI.

Scanner: scanners produce images of full page size. For example, the 8-1/2”x11” image is not the same as an 8-1/2”x11” printer page because, in the case of the HP LaserJet, the printer requires a quarter-inch margin. Therefore, the image has to shrink to fit the print area of 8”x10-1/2”

Banding is explicitly used.

Requirements

Header :     Declared in BIPrint.h; include BIPrint.h.

Library :    Use BIPrint.lib.

DLLs :       BIPrint.dll.

Code example

#include "BIPRINT.H"

case IDM_PRINT:

{

GPRINT Print;

// The print structure must be set. If you select to display dialog box,

// the number of pages the user selected will be returned in Print.nNumCopies.

Print.bDisplay                 = TRUE;                                // Display print dialog box

Print.bCenterVertImg                   = TRUE;                                // Center image vertically

Print.bCenterHorizImg = FALSE;                              // Center image horizontally

Print.bScalePage                            = TRUE;                                // Scale image to fit page

Print.nNumCopies                         = 1;                                         // Number of copies

Print.bConvertCtoB                      = FALSE;                              // Convert color image to monochrome

Print.bStretchPage                         = FLASE;                              // Stretch to page

Print.bAllPage                                 = TRUE;                                // Print all pages

Print.bUseDPI                                 = TRUE;                                // Use image DPI for scaling

Print.bNotDispCancel   = FALSE;                              // Not display print cancel dialog box

 

PrintDIB (hWnd, hPrnDC, hDib, lpImgName, lpptDPI, &Print, lprScale);

}

break;