阅读:1548回复:1
请教打印流程
startdocw->startpage->startpageprinter.........endpageprinter->endpage->enddoc,一般流程是这样吧,请在startpageprinter和endpageprinter之间,一般会调用什么函数。谢谢
|
|
沙发#
发布于:2012-05-29 19:00
// Zero and then initialize the members of a DOCINFO structure.
memset( &di, 0, sizeof(DOCINFO) ); di.cbSize = sizeof(DOCINFO); di.lpszDocName = (LPCTSTR)TEXT("Bitmap Printing Test"); di.lpszOutput = (LPTSTR) NULL; di.lpszDatatype = (LPTSTR) NULL; di.fwType = 0; // Begin a print job by calling the StartDoc function. nError = StartDoc(pd.hDC, &di); if (nError == SP_ERROR) { errhandler((LPCTSTR)TEXT("StartDoc"), hWnd); goto Error; } // Inform the driver that the application is about to begin // sending data. nError = StartPage(pd.hDC); if (nError <= 0) { errhandler((LPCTSTR)TEXT("StartPage"), hWnd); goto Error; } // Retrieve the number of pixels-per-logical-inch in the // horizontal and vertical directions for the display upon which // the bitmap was created. These are likely the same as for // the present display, so we use those values here. hWinDC = GetDC(hWnd); fLogPelsX1 = (float) GetDeviceCaps(hWinDC, LOGPIXELSX); fLogPelsY1 = (float) GetDeviceCaps(hWinDC, LOGPIXELSY); // Retrieve the number of pixels-per-logical-inch in the // horizontal and vertical directions for the printer upon which // the bitmap will be printed. fLogPelsX2 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSX); fLogPelsY2 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSY); // Determine the scaling factors required to print the bitmap and // retain its original proportions. if (fLogPelsX1 > fLogPelsX2) fScaleX = (fLogPelsX1 / fLogPelsX2); else fScaleX = (fLogPelsX2 / fLogPelsX1); if (fLogPelsY1 > fLogPelsY2) fScaleY = (fLogPelsY1 / fLogPelsY2); else fScaleY = (fLogPelsY2 / fLogPelsY1); // Compute the coordinates of the upper left corner of the // centered bitmap. cWidthPels = GetDeviceCaps(pd.hDC, HORZRES); xLeft = ((cWidthPels / 2) - ((int) (((float) bmih.biWidth) * fScaleX)) / 2); cHeightPels = GetDeviceCaps(pd.hDC, VERTRES); yTop = ((cHeightPels / 2) - ((int) (((float) bmih.biHeight) * fScaleY)) / 2); // Use StretchDIBits to scale the bitmap and maintain // its original proportions (that is, if the bitmap was square // when it appeared in the application's client area, it should // also appear square on the page). if (StretchDIBits(pd.hDC, xLeft, yTop, (int) ((float) bmih.biWidth * fScaleX), (int) ((float) bmih.biHeight * fScaleY), 0, 0, bmih.biWidth, bmih.biHeight, lpBits, lpBitsInfo, iUsage, SRCCOPY) == GDI_ERROR) { errhandler((LPCTSTR)TEXT("StretchDIBits Failed"), hWnd); } // Retrieve the width of the string that specifies the full path // and filename for the file that contains the bitmap. GetTextExtentPoint32W(pd.hDC, ofn.lpstrFile, ofn.nFileExtension + 3, &szMetric); // Compute the starting point for the text-output operation. The // string will be centered horizontally and positioned three lines // down from the top of the page. xLeft = ((cWidthPels / 2) - (szMetric.cx / 2)); yTop = (szMetric.cy * 3); // Print the path and filename for the bitmap, centered at the top // of the page. TextOut(pd.hDC, xLeft, yTop, ofn.lpstrFile, ofn.nFileExtension + 3); // Determine whether the user has pressed the Cancel button in the // AbortPrintJob dialog box; if the button has been pressed, call // the AbortDoc function. Otherwise, inform the spooler that the // page is complete. nError = EndPage(pd.hDC); if (nError <= 0) { errhandler((LPCTSTR)TEXT("EndPage"), hWnd); goto Error; } // Inform the driver that document has ended. nError = EndDoc(pd.hDC); if (nError <= 0) errhandler((LPCTSTR)TEXT("EndDoc"), hWnd); Error: // Enable the application's window. EnableWindow(hWnd, TRUE); // Remove the AbortPrintJob dialog box. DestroyWindow(hdlgCancel); // Delete the printer DC. DeleteDC(pd.hDC); 主要就是GDI的绘制函数,MSDN有打印作业的例子的,上面就是。 |
|