// print setup PRINTDLG pd; pd . lStructSize = sizeof (PRINTDLG ); pd . hwndOwner = Form1 -> Handle; pd . hDevMode = NULL; pd . hDevNames = NULL; pd . hDC = 0; pd . Flags = PD_RETURNDC | PD_ALLPAGES | PD_HIDEPRINTTOFILE | PD_NOSELECTION; pd . nFromPage = 1; pd . nToPage = TotImg; pd . nMinPage = 1; pd . nMaxPage = TotImg; pd . nCopies = 1; pd . hInstance = 0; pd . lCustData = 0; pd . lpfnPrintHook = NULL; pd . lpfnSetupHook = NULL; pd . lpPrintTemplateName = NULL; pd . lpSetupTemplateName = NULL; pd . hPrintTemplate = NULL; pd . hSetupTemplate = NULL; if ( PrintDlg ( &pd ) == 0 ) return; HDC hPrinter = pd . hDC; int pageFrom = 1; int pageTo = TotImg; if ( pd . Flags & PD_PAGENUMS ) { pageFrom = pd . nFromPage; pageTo = pd . nToPage; } int nCopies = pd . nCopies; // print cycle for ( int x = 1; x <= nCopies; x++ ) { for ( int page = pageFrom; page <= pageTo; page++ ) { char filePathAndName [ 256 ]; strcpy ( filePathAndName, "***path & name of the TIFF file to print***" ); strcat ( filePathAndName, ".TIF" ); HANDLE handle = CreateFileA ( filePathAndName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if ( handle == INVALID_HANDLE_VALUE ) { MessageBox ( NULL, filePathAndName, "File doesn't open:", MB_SYSTEMMODAL ); return; } int rc = pfnFFTiffServices ( 1, handle, NULL, NULL, NULL ); int width = pfnFFTiffServices ( 2, NULL, NULL, NULL, NULL ); int height = pfnFFTiffServices ( 3, NULL, NULL, NULL, NULL ); // max 48 characters in lpsz DocName char printjobNameInQueue [ 2048 ]; strcpy ( printjobNameInQueue, "*** my print job - pag. " ); char asciizNumber [ 32 ]; itoa ( page, asciizNumber, 10 ); strcat ( printjobNameInQueue, asciizNumber ); rc = pfnFFTiffServices ( 5, handle, NULL, NULL, NULL ); HGLOBAL pFrame = GlobalAlloc ( GMEM_FIXED, width * ( height + 1 ) ); rc = pfnFFDec ( handle, 1, pFrame, width/8, 0, height ); CloseHandle ( handle ); HGLOBAL pFrame2 = GlobalAlloc ( GMEM_FIXED, width * height / 8 ); pfnFFReduce8bpp1bpp ( pFrame, width * height, pFrame2 ); HBITMAP hBitmap = CreateBitmap ( width, height, 1, 1, pFrame2 ); HDC hDC = GetDC ( Application -> Handle ); HDC hMemoryDC = CreateCompatibleDC ( hDC ); ReleaseDC ( Application -> Handle, hDC ); HBITMAP hOldBitmap = ( HBITMAP ) SelectObject ( hMemoryDC, hBitmap ); DOCINFO docinfo; docinfo . cbSize = sizeof ( DOCINFO ); docinfo . lpszDocName = printjobNameInQueue; docinfo . lpszOutput = 0; docinfo . lpszDatatype = "BITMAP"; docinfo . fwType = 0; if ( StartDoc ( hPrinter, &docinfo ) > 0 ) { if ( StartPage ( hPrinter ) > 0 ) { if ( GetDeviceCaps ( hPrinter, RASTERCAPS ) & RC_BITBLT ) { int printWidth = GetDeviceCaps ( hPrinter, HORZRES ); int printHeight = GetDeviceCaps ( hPrinter, VERTRES ); StretchBlt ( hPrinter, 0, 0, printWidth, printHeight, hMemoryDC, 0, 0, width, height, SRCCOPY ); EndPage ( hPrinter ); } EndDoc ( hPrinter ); } } SelectObject ( hMemoryDC, hOldBitmap ); DeleteDC ( hMemoryDC ); DeleteObject ( hBitmap ); if ( pFrame != 0 ) { GlobalFree ( pFrame ); } if ( pFrame2 != 0 ) { GlobalFree ( pFrame2 ); } } } DeleteDC ( hPrinter ); return;