17.5.2 Retrieving a Copy of the Print Settings

It is often useful when working with print settings to determine a particular printer driver's current settings. This lets your application determine whether the settings are appropriate for its own printing requirements. Follow these steps to retrieve a copy of the driver's print settings:

1.Determine how much space the output DEVMODE structure will require. To do this, call ExtDeviceMode with the fwMode parameter set to zero. ExtDeviceMode returns the size, in bytes, of the output DEVMODE structure (the one the driver would create if you set fwMode to DM_COPY).

2.Allocate a buffer of this size.

3.Call ExtDeviceMode again, including the following information in the parameters:

Parameter Value

lpdmOutput A pointer to the output buffer you just allocated
fwMode DM_COPY

The printer driver then puts a DEVMODE structure containing its current print settings into the buffer you specified.

Because the output buffer contains a complete DEVMODE structure, you can easily pass that data to the CreateDC function.