home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12732.ZIP / PRINT.C < prev    next >
C/C++ Source or Header  |  1990-08-17  |  7KB  |  196 lines

  1. /******************************* Module Header ******************************\
  2. * Module Name: Print.c
  3. *
  4. *
  5. * Created by Microsoft Corporation, 1989
  6. *
  7. *
  8. * PM OS2.ini Editor
  9. *
  10. * Printing Functions
  11. *
  12. \***************************************************************************/
  13.  
  14.  
  15. #define INCL_PM
  16. #define INCL_BASE
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20.  
  21. #include <os2.h>
  22.  
  23. #include "noncomm.h"
  24. #include "IniEdit.h"
  25.  
  26.  
  27. /******************************* Constants *********************************/
  28.  
  29. #define LEFT_MARGIN      3
  30. #define TOP_MARGIN       7
  31. #define BOTTOM_MARGIN   15
  32. #define    MAX_PRINT_LEN    1024
  33.  
  34.  
  35. /******************************* Externals *********************************/
  36.  
  37. extern USHORT        cAppNames;
  38. extern PGROUPSTRUCT  pGroups;
  39. extern HAB           habIniEdit;
  40. extern USHORT        usLineHeight;
  41. extern USHORT        usPrintFormat;
  42.  
  43. /******************************* Internals ********************************/
  44. CHAR    szBuf[MAX_STRING_LEN];            // Output character buffer
  45. CHAR    szPrinter[MAX_PRINT_LEN];        // Logical Printer Name
  46. CHAR    szDetails[MAX_PRINT_LEN];        // Logical Printer Details
  47.  
  48.  
  49. /***************************** Function Header *****************************\
  50. *
  51. * PrintThread
  52. *
  53. *
  54. * Prints the ini info in specified format
  55. *
  56. \***************************************************************************/
  57.  
  58. VOID PrintThread()
  59. {
  60.     HAB      habPrint;                          // HAB of Print Thread
  61.     HDC      hdcPrint;                          // DC of Printer
  62.     HPS      hpsPrint;                          // PS of Printer
  63.     SIZEL    sizel;                             // Size of PS to Create
  64.     POINTL   ptlOutput;                         // Output location
  65.     BYTE     abOut[50];                         // DevEscape Output
  66.     ULONG    ulOut;                             // DevEscape Output Count
  67.     USHORT   usHeight;                          // Height of Printer Page
  68.     USHORT   cch;                               // Count of Characters in buffer
  69.     INT      i,j;                               // Loop Counters
  70.     DEVOPENSTRUC  dop;                          // DevOpenDC Info
  71.     CHAR     szMessage[80];
  72.  
  73.     /* initialization of thread */
  74.     if (!(habPrint = WinInitialize(0))) DosExit(EXIT_THREAD, -1);
  75.  
  76.  
  77.     /*** Select Port ***/
  78.     /* get name of default logical printer */
  79.     cch = WinQueryProfileString(habPrint, "PM_SPOOLER", "PRINTER",
  80.                            "",                /* default  */
  81.                            szPrinter,
  82.                            MAX_PRINT_LEN);    /* max chars */
  83.  
  84.     szPrinter[cch-2] = 0;                     /* remove terminating ';' */
  85.  
  86.     /* get specifics of default logical printer */
  87.     cch = WinQueryProfileString(habPrint, "PM_SPOOLER_PRINTER", szPrinter,
  88.                            "",                /* default  */
  89.                            szDetails,
  90.                            MAX_PRINT_LEN);    /* max chars */
  91.  
  92.  
  93.     /* info in form of "port; driver; logical address" */
  94.     /* grab driver name; one past semicolon */
  95.     dop.pszDriverName = strchr( szDetails, ';' )+1;
  96.  
  97.     /* Grab logical address */
  98.     dop.pszLogAddress = strchr( dop.pszDriverName, ';' )+1;
  99.  
  100.     /* Make driver and Logical address Null terminated */
  101.     dop.pszLogAddress = strtok( dop.pszLogAddress, ",;" );
  102.     dop.pszDriverName = strtok( dop.pszDriverName, ",.;" );  /* Driver.Model */
  103.  
  104.     dop.pdriv = NULL;
  105.     dop.pszDataType = NULL;
  106.  
  107.     /* Create Printer DC */
  108.     hdcPrint = DevOpenDC( habPrint, OD_QUEUED, "*", 3L, (PDEVOPENDATA)&dop,
  109.             (HDC)NULL);
  110.  
  111.     if( hdcPrint == (HDC)NULL )
  112.         {
  113.     DosExit(EXIT_THREAD, -1);
  114.         }
  115.  
  116.     strcpy( szBuf, (usPrintFormat == APP_FORM) ? SZAPP : SZALL );
  117.     DevEscape( hdcPrint, DEVESC_STARTDOC, (LONG)strlen( szBuf ), (PBYTE)szBuf,
  118.             &ulOut, (PBYTE)NULL );
  119.  
  120.     /* Determine size of page */
  121.     DevQueryCaps( hdcPrint, CAPS_HEIGHT, 1L, (PLONG)&usHeight );
  122.     ptlOutput.y = usHeight - TOP_MARGIN - usLineHeight;
  123.     ptlOutput.x = LEFT_MARGIN;
  124.  
  125.     /* Create Printer PS */
  126.     sizel.cx = sizel.cy = 0L;
  127.     hpsPrint = GpiCreatePS( habPrint, hdcPrint, &sizel,
  128.             PU_PELS | GPIF_DEFAULT | GPIT_NORMAL | GPIA_ASSOC );
  129.  
  130.     if( hpsPrint == (HPS)NULL )
  131.         {
  132.     DosExit(EXIT_THREAD, -1);
  133.         }
  134.  
  135.  
  136.     /* print items */
  137.     if( usPrintFormat == APP_FORM )
  138.         {
  139.         for( i=0; i<cAppNames; i++ )
  140.             {
  141.             sprintf(szMessage,"CharString: X = %ld,  Y = %ld",
  142.                                 ptlOutput.x, ptlOutput.y);
  143.             GpiCharStringAt( hpsPrint, &ptlOutput, (LONG)strlen( pGroups[i].szAppName ),
  144.                     pGroups[i].szAppName );
  145.             ptlOutput.y -= usLineHeight;
  146.  
  147.             if( ptlOutput.y <= BOTTOM_MARGIN )
  148.                 {
  149.                 DevEscape( hdcPrint, DEVESC_NEWFRAME, 0L, (PBYTE)NULL , &ulOut, abOut );
  150.                 ptlOutput.y = usHeight - TOP_MARGIN - usLineHeight;
  151.                 }
  152.  
  153.             }
  154.         }  /* if */
  155.     else
  156.         {
  157.         /* Print App Names */
  158.         for( i=0; i<cAppNames; i++ )
  159.             {
  160.             GpiCharStringAt( hpsPrint, &ptlOutput, (LONG)strlen( pGroups[i].szAppName ),
  161.                     pGroups[i].szAppName );
  162.             ptlOutput.y -= usLineHeight;
  163.             if( ptlOutput.y <= BOTTOM_MARGIN )
  164.                 {
  165.                 DevEscape( hdcPrint, DEVESC_NEWFRAME, 0L, (PBYTE)NULL , &ulOut, abOut );
  166.                 ptlOutput.y = usHeight - TOP_MARGIN - usLineHeight;
  167.                 }
  168.  
  169.             /* Print Key Value Pairs for current App Name */
  170.             for( j=0; j<pGroups[i].cKeys; j++ )
  171.                 {
  172.                 sprintf( szBuf, "   %s: %s", pGroups[i].pPairs[j].szKey,
  173.                         pGroups[i].pPairs[j].szValue );
  174.  
  175.                 if( GpiCharStringAt( hpsPrint, &ptlOutput, (LONG)strlen( szBuf ), szBuf ) == GPI_ERROR )
  176.             ;
  177.  
  178.                 ptlOutput.y -= usLineHeight;
  179.                 if( ptlOutput.y <= BOTTOM_MARGIN )
  180.                     {
  181.                     DevEscape( hdcPrint, DEVESC_NEWFRAME, 0L, (PBYTE)NULL , &ulOut, abOut );
  182.                     ptlOutput.y = usHeight - TOP_MARGIN - usLineHeight;
  183.                     }
  184.                 }  /* for */
  185.             }  /* for */
  186.  
  187.         }
  188.  
  189.     /* Cleanup */
  190.     DevEscape( hdcPrint, DEVESC_ENDDOC, 0L, (PBYTE)NULL , &ulOut, abOut );
  191.     GpiAssociate( hpsPrint, (HDC)NULL );
  192.     GpiDestroyPS( hpsPrint );
  193.     DevCloseDC( hdcPrint );
  194.     DosExit(EXIT_THREAD, 0);
  195. }  /* PrintThread */
  196.