|
||
A printer device must be selected before printing can begin.
You must have added at least one directory to the list of printer
driver search paths and a printer model list must have been created before you
can select a model. For more information on the search path, see
CPrintSetup
.
Retrieve the list of all supported printer models using
CPrintSetup::ModelNameListL().
A printer model is identified by
its UID and also has an associated model name.
Select the target printer device using
CPrintSetup::CreatePrinterDeviceL().
The model list is deleted in the destructor for
CPrintSetup
, but if it is no longer needed, it may be deleted
beforehand using FreeModelList().
// Provide search path for printer drivers
_LIT(KSearchPath,"\\resource\\printers\\*");
iPrintSetup->AddPrinterDriverDirL(KSearchPath);
// Get list of models - causes list to be allocated
CPrinterModelList* modelList = iPrintSetup->ModelNameListL(iFs);
// Create a printer device. Select first in list (random choice)
iPrintSetup->CreatePrinterDeviceL(modelList->NumToUid(0));
// Free models list
iPrintSetup->FreeModelList();
In a real application program, the list of all supported printer
models would be displayed in a suitable dialog box from which the user could
make their choice. In the example above, the first model in the list is chosen
arbitrarily, and its UID is passed to
CPrintSetup::CreatePrinterDeviceL().
Note that CPrintSetup
does not create a default
printer device on construction so CreatePrinterDeviceL()
must have
been called before printing can take place. If no printer device with the UID
specified exists, a default printer device will be created.