You can create a normal device context by calling DevOpenDC. This function requires that you specify one of the six normal types. It also requires that you pass certain device-initialization data, including a logical address, the device-driver name, device-driver data, a description of the device type, and information about the queue (if the device is a queued device). The device-initialization data is passed in a DEVOPENSTRUC structure.
The following figure is an example of this structure.
typedef struct _DEVOPENSTRUC { /* dop */ PSZ pszLogAddress /* Logical-device address */ PSZ pszDriverName /* Device-driver name */ PDRIVDATA pdriv /* Pointer to extra driver data */ PSZ pszDataType /* Type of queued data */ PSZ pszComment /* Optional spooler info */ PSZ pszQueueProcName /* Queue-processor name */ PSZ pszQueueProcParams /* Queue-processor arguments */ PSZ pszSpoolerParams /* Spooler arguments */ PSZ pszNetworkParams /* Network arguments */ } DEVOPENSTRUC;
The last four fields in this structure apply only to queued devices.
The following figure shows how to create a nondisplay device context for a printer.
HDC hdcPrinter; /* Handle of printer device context */ HAB hab; /* Anchor-block handle */ DEVOPENSTRUC dop; /* Device information */ dop.pszLogAddress = "lpt1"; /* Logical-device address */ dop.pszDriverName = "EPSON"; /* Device-driver name */ dop.pdriv = (PDRIVDATA) NULL; /* Pointer to driver data */ dop.pszDataType = "PM_Q_STD"; /* Standard queued data */ hdcPrinter = DevOpenDC(hab, OD_DIRECT, /* Direct device type */ "*", /* No data in OS2.INI */ 4, /* Use first 4 fields in dop structure */ (PDEVOPENDATA) &dop, (HDC) NULL);
The following figure is an example of how to create a standard device context for a metafile.
HDC hdcMeta; /* Handles of metafile */ /* and window DCs */ HAB hab; /* Anchor-block handle */ DEVOPENSTRUC dop; /* Device information */ dop.pszLogAddress = NULL; /* Logical-device address */ dop.pszDriverName = "DISPLAY"; /* Device-driver name */ hdcMeta = DevOpenDC(hab, OD_METAFILE, /* Metafile DC */ "*", /* No data in OS2.INI */ 2, /* Use first 2 fields in dop */ (PDEVOPENDATA) &dop, /* Structure for system info */ NULL) /* Compatible with screen */