home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PRINTDC.ZIP / PRINTDC.C < prev   
Text File  |  1990-01-22  |  2KB  |  69 lines

  1.  
  2. /*------------------------------------------------------------------
  3.    PRINTDC.C -- Function to open device context for default printer
  4.   ------------------------------------------------------------------*/
  5.  
  6. #define INCL_WIN
  7. #include <os2.h>
  8. #include <mt\string.h>   // note: multithread header file
  9. #pragma pack(1)          // align structure fields on 1-byte boundaries
  10.  
  11. HDC OpenDefaultPrinterDC (HAB hab)
  12.      {
  13.      static CHAR     achPrnData[256] ;
  14.      static DRIVDATA driv = { sizeof (DRIVDATA) } ;
  15.      CHAR            achDefPrnName[34], *pchDelimiter ;
  16.      DEVOPENSTRUC    dop ;
  17.  
  18.                // Obtain default printer name and remove semicolon
  19.  
  20.      WinQueryProfileString (hab, "PM_SPOOLER", "PRINTER", ";",
  21.                             achDefPrnName, sizeof achDefPrnName) ;
  22.  
  23.      if ((pchDelimiter = strchr (achDefPrnName, ';')) != NULL)
  24.           *pchDelimiter = '\0' ;
  25.  
  26.      if (achDefPrnName[0] == '\0')
  27.           return DEV_ERROR ;
  28.  
  29.                // Obtain information on default printer
  30.  
  31.      WinQueryProfileString (hab, "PM_SPOOLER_PRINTER", achDefPrnName,
  32.                             ";;;;", achPrnData, sizeof achPrnData) ;
  33.  
  34.                // Parse printer information string
  35.  
  36.      if ((pchDelimiter = strchr (achPrnData, ';')) == NULL)
  37.           return DEV_ERROR ;
  38.  
  39.      dop.pszDriverName = pchDelimiter + 1 ;
  40.  
  41.      if ((pchDelimiter = strchr (dop.pszDriverName, ';')) == NULL)
  42.           return DEV_ERROR ;
  43.  
  44.      dop.pszLogAddress = pchDelimiter + 1 ;
  45.  
  46.      *(dop.pszLogAddress + strcspn (dop.pszLogAddress, ",;")) = '\0' ;
  47.      *(dop.pszDriverName + strcspn (dop.pszDriverName, ",;")) = '\0' ;
  48.  
  49.                // Fill DRIVDATA structure if necessary
  50.  
  51.      if ((pchDelimiter = strchr (dop.pszDriverName, '.')) != NULL)
  52.           {
  53.           *pchDelimiter = '\0' ;
  54.           strncpy (driv.szDeviceName, pchDelimiter + 1,
  55.                                       sizeof (driv.szDeviceName)) ;
  56.           dop.pdriv = &driv ;
  57.           }
  58.      else
  59.           dop.pdriv = NULL ;
  60.  
  61.                // Set data type to "raw"
  62.  
  63.      dop.pszDataType = "PM_Q_RAW" ;
  64.  
  65.                // Open printer device context
  66.  
  67.      return DevOpenDC (hab, OD_QUEUED, "*", 4L, (PDEVOPENDATA) &dop, NULL) ;
  68.      }
  69.