Made by Aistė Augustinaitė Software Engineering 3 group Windows API Printing Made by Aistė Augustinaitė Software Engineering 3 group
Desktop App Printing WndProc function processes messages from the operating system and provide them to the main window procedure. A native Windows program should be multi- threaded. Program's print job processing need to be performed in a different thread than that which processes user interaction. Printing program uses the XPS (XML Paper Specification) documents for printing.
Printing tasks Collect print job information from user Create progress indicator Start the printing thread Render print job data Monitor print job progress Close print job and terminate printing thread
Retrieve a PrinterDevice Context CreateDC function Print common dialog box.
CreateDC function CreateDC which retrieves a device context to the default display device CreateDC in which the "WINSPOOL" driver is selected and the printer name is specified by name
CreateDC function EnumPrinters function which obtains the exact printer name string to pass to CreateDC.
Print common dialog box PrintDlgEx function (newer dialog box) lppd [in, out] - a pointer to a PRINTDLGEX structure that contains information used to initialize the property sheet. When PrintDlgEx returns, this structure contains information about the user's selections. PrintDlg function (older style dialog box) lppd [in, out] - a pointer to a PRINTDLG structure that contains information used to initialize the property sheet. When PrintDlg returns, this structure contains information about the user's selections.
Displaying Print Job Progress WM_INITDIALOG Initializes the controls that the dialog box uses. WM_SETCURSOR Sets the cursor to a pointer when the user is able to cancel a print job, and to the wait cursor when the print job is at a point where it cannot be cancelled. USER_PRINT_START_PRINTING Sets the progress bar parameters for the print job, and creates the printing thread to start processing the print job. This is an application-specific window message.
USER_PRINT_STATUS_UPDATE WM_COMMAND - IDCANCEL Sets the cancel event to tell the print processing thread to cancel the print job. USER_PRINT_STATUS_UPDATE Updates the progress bar and status text to show the current state of the print job. This is an application-specific window message. USER_PRINT_CLOSING Sets the closing status text in the progress dialog box to indicate that the print job is closing. USER_PRINT_COMPLETE Displays the "Print job complete" message to the user, and releases handles and events that were used in this print job.
Start and Stop a Printing Thread Prepare the data and user interface elements for printing. Start the print processing thread. Call CreateThread to start the processing thread.
Check whether print processing failed on start. Use WaitForSingleObject function. It returns when either the timeout occurs or the thread handle is signaled. STOP There should be a Cancel button in the print progress dialog box that calls the quiteEvent event.
Print APIs that a native Windows application can use
Print Spooler API The Print Spooler API provides an interface to the print spooler for applications to manage printers and print jobs.
Print Ticket API The Print Ticket API provides enables applications to manage and convert print tickets. A print ticket is an XPS document component that contains the preferred printer settings. The print ticket must be validated against the printer's characteristics.
GDI Print API The GDI Print API provides applications with a device- independent printing interface. http://www.dreamincode.net/forums/topic/194320- win32-api-printer-tutorial-using-gdi-functions/
XPS Print API Provides an interface to the print spooler. Applications can use this API to send XPS documents to a printer. Client applications should use the Print Document Package API instead.
Print Document Package API Provides an interface that allows an application to access and manage the print document package.
Literature All the information can be found on: https://msdn.microsoft.com/en-us/library/windows/desktop/ff819274(v=vs.85).aspx
Thank you for your attention!