

You can choose from two Print common dialog boxes to display to a user the newer dialog box, which you can display by calling the PrintDlgEx function, and the older style dialog box, which you can display by calling the PrintDlg function. returned printer, set the printerName value to When this desired printer is found in the list of name to use in the CreateDC function call.

Review the information from all the printers PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,

That information is used to allocate a buffer of the required size, and the second call to EnumPrinters returns the data that you want. The first call returns the size of the required buffer. Because the size of the required buffer cannot be known in advance, the EnumPrinters is called two times. The following code example shows how to call EnumPrinters and get the names of the local and locally connected printers. You can obtain the exact printer name string to pass to CreateDC by calling the EnumPrinters function. printerDC = CreateDC( L"WINSPOOL", printerName, NULL, NULL) The following example shows a call to CreateDC in which the "WINSPOOL" driver is selected and the printer name is specified by name.

You can also pass a DEVMODE structure in the call to CreateDC if you want to provide device-specific initialization data for the device driver when you create the device context. To render to a specific printer, you must specify "WINSPOOL" as the device and pass the correct name of the printer to CreateDC. hDC = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL) The code in this example retrieves a device context to the default display device. The simplest call to retrieve a device context is shown in the code example that follows. CreateDC returns a device context into which you can render the content to print. If you know the device to which you want to print, you can call CreateDC and pass that information directly to the function. This topic describes how to obtain a printer device context by using the following methods. The Print common dialog box returns these selections in a data structure. When you display a Print common dialog box a user will be able to select the printer, the pages of the document, and the number of document copies they want to print. You can retrieve a printer device context by calling the CreateDC function directly, or it can be returned by a Print common dialog box. This topic describes how to retrieve a printer device context.
