int print_document(imgdes *srcimg, char far *text)
{
#define EJECTPAGE TRUE
#define FONT_FOR_DOCUMENT_SIZE 18
static LOGFONT lf = { // Use font described by LOGFONT struct
0, 0, 0, 0, FW_NORMAL, 0, 0, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "ARIAL"
};
HFONT hFont, hOldFont;
HWND hwnd;
HDC hdcprn;
RECT prntrect;
int prtmode=0;
int rcode = NO_ERROR, length;
hwnd = GetActiveWindow();
hdcprn = GetPrinterDC(); // Defined in VicDemo
// Printing 3-inch wide image
// prntrect: 0, 0, 2.999, [calculated length] inches
// Use units of mils (1000 dpi) for prntrect for printing image
length = srcimg->bmh->biHeight * 3000 / srcimg->bmh->biWidth; // Maintain aspect ratio
SetRect(&prntrect, 0, 0, 2999, length);
printimagestartdoc(hdcprn, "Document containing image and text");
rcode = printimagenoeject(hwnd, hdcprn, 0, srcimg, &prntrect, 0, (DLGPROC)NULL);
// Use printer pixels as units for prntrect for printing text
prntrect.left = GetDeviceCaps(hdcprn, LOGPIXELSX) * 3500 / 1000; //3.5 inches
prntrect.top = 0;
prntrect.right = GetDeviceCaps(hdcprn, HORZRES);
prntrect.bottom = GetDeviceCaps(hdcprn, VERTRES);
// Set the font point size
lf.lfHeight= - MulDiv(FONT_FOR_DOCUMENT_SIZE, GetDeviceCaps(hdcprn, LOGPIXELSY), 72);
hFont = CreateFontIndirect(&lf); // Create the font
hOldFont = SelectObject(hdcprn, hFont); // Select font into DC
// Print the text
DrawText(hdcprn, text, -1, &prntrect, DT_LEFT | DT_WORDBREAK | DT_EXPANDTABS | DT_NOPREFIX);
printimageenddoc(hdcprn, EJECTPAGE);
DeleteObject(SelectObject(hdcprn, hOldFont));
DeleteDC(hdcprn);
return(rcode);
}
Victor Image Processing Library homepage |
Victor Sample Code