home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / os2tk21j / c / samples / bidi / setprint.c__ / setprint.c
Encoding:
C/C++ Source or Header  |  1993-03-12  |  8.0 KB  |  262 lines

  1. /*static char *SCCSID = "@(#)setprint.c    6.2 92/02/24";*/
  2. /*************************************************************************
  3.  * File Name     : SETPRINT.C
  4.  *
  5.  * Description   : This sample program demonstrates how to use the
  6.  *                 Bidirectional (Bidi) API NlsSetBidiPrint.
  7.  *                 This Bidi API is use to send the Bidi attriubtes
  8.  *                 of the string we want to print, to the Bidi
  9.  *                 printer support. Accordingly, the string will be
  10.  *                 printed following this attributes. This is independant
  11.  *                 from the current printer Bidi attriubes.
  12.  *
  13.  * Considerations: Before using this program, make sure that the Bidi
  14.  *                 printer support is active (RUN= statement in the
  15.  *                 CONFIG.SYS exists) and it is loading the correct CFG
  16.  *                 that match the type of printer connected.
  17.  *                 Also make sure that proper font is been dowloaded to
  18.  *                 the printer.
  19.  *
  20.  * API's         : NlsSetBidiPrint
  21.  *                 VioWrtCharStr
  22.  *                 VioScrollUp
  23.  *                 VioSetCurType
  24.  *
  25.  * Required files: To build and run this sample code the following files
  26.  *                 are needed:
  27.  *                 - SETPRINT.C
  28.  *                 - SETPRINT.DEF
  29.  *                 - SETPRINT.MAK
  30.  *                 - SETPRINT.LNK
  31.  *
  32.  *  Copyright (C) 1991 IBM Corporation
  33.  *
  34.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  35.  *      sample code created by IBM Corporation. This sample code is not
  36.  *      part of any standard or IBM product and is provided to you solely
  37.  *      for  the purpose of assisting you in the development of your
  38.  *      applications.  The code is provided "AS IS", without
  39.  *      warranty of any kind.  IBM shall not be liable for any damages
  40.  *      arising out of your use of the sample code, even if they have been
  41.  *      advised of the possibility of such damages.                                                    *
  42.  ************************************************************************/
  43. #define INCL_BASE
  44. /* To include the neccessary header files for Bidi */
  45. #define INCL_DOSERRORS
  46. #define INCL_BDCALLS
  47. #define INCL_DOSFILEMGR
  48. #define PRINTER  "PRN"
  49.  
  50. #include <string.h>
  51. #include <os2.h>
  52. #include <conio.h>
  53. #include <stdio.h>
  54.  
  55. VOID Initialize(VOID);
  56. VOID SendAttThenJob(VOID);
  57. VOID SetCur(INT);
  58.  
  59. /* Define the parameter to Hide and Restore the cursor */
  60. #define HIDE   -1
  61. #define RESTORE 0
  62.  
  63. /* Define the buffer for the string to be printed */
  64. CHAR cString[30];
  65.  
  66. /*************************************************************************
  67.  * Name          : Main
  68.  *
  69.  * Description   : This is the main part of the program, it first clears
  70.  *                 the screen and then hides the cursor. The string to be
  71.  *                 printed will be displayed on the screen, and after
  72.  *                 Hitting Enter, it will go to the printer associated
  73.  *                 with its own attributes.
  74.  *
  75.  * API's         : VioScrollUp
  76.  *
  77.  * Parameters    : This program does not take any command line parameters
  78.  *
  79.  * Returns       : None
  80.  *
  81.  ************************************************************************/
  82.  
  83. INT main(SHORT sArgc,CHAR **ppArgv)
  84. {
  85.    APIRET RC;
  86.  
  87.    /* clear the screen  */
  88.    VioScrollUp(0, 0, 24, 79, -1," \x07", 0);
  89.  
  90.    /* hide the cursor */
  91.    SetCur(HIDE);
  92.  
  93.    /* Write the static text to the screen and the string that
  94.     * is needed to be shaped */
  95.    Initialize();
  96.  
  97.    VioWrtCharStr("Press Enter to continue or Ctrl-c to Exit", 43, 15, 23, 0l);
  98.    getchar();
  99.  
  100.    /* Call the API to shape the string and wirte it to the screen */
  101.    SendAttThenJob();
  102.  
  103.    VioWrtCharStr("Press Enter to end the program", 32, 23, 23, 0l);
  104.    getchar();
  105.  
  106.    /* clear the screen before exit */
  107.    VioScrollUp(0, 0, 24, 79, -1," \x07", 0);
  108.  
  109.    /* restore the cursor position */
  110.    SetCur(RESTORE);
  111.  
  112.    return (0);
  113. }
  114. /*************************************************************************
  115.  * Name          : INITIALIZE
  116.  *
  117.  * Description   : This function displays some static text  on the screen
  118.                    and also the String to print before it is printed.
  119.  *
  120.  * API's         : VioWrtCharStr
  121.  *
  122.  * Parameters    : This program does not take any command line parameters
  123.  *
  124.  * Returns       : None
  125.  *
  126.  ************************************************************************/
  127. VOID Initialize(VOID)
  128. {
  129.    INT iI, iRow, iCol;
  130.  
  131.    APIRET  RC;
  132.  
  133.    /* define structures to be array of strings to contain the static
  134.     * text to be wirtten on the screen  */
  135.    struct {
  136.           CHAR cScreen[45];
  137.           }mssg1[2];
  138.  
  139.    /* Initialize the structures with the characters to be displayed */
  140.    strcpy(mssg1[0].cScreen, " First, make sure that the Bidi Printer");
  141.    strcpy(mssg1[1].cScreen, "Support is running with the correct CFG..");
  142.  
  143.    /* In this for loop, we increment the iRow after the display of each
  144.     * string in the structure to jump to another line, keeping the value
  145.     * of the iCol value fixed to have the strings indented */
  146.    for(iI = 0, iRow = 3, iCol = 23; iI < 2; iI++, iRow++)
  147.      VioWrtCharStr(mssg1[iI].cScreen, strlen(mssg1[iI].cScreen),
  148.                    iRow, iCol, 0l);
  149.  
  150.  
  151.    strcpy(cString,"This is a text sample");
  152.    VioWrtCharStr(cString, strlen(cString), 8, 23, 0l);
  153.  
  154. }
  155. /*************************************************************************
  156.  * Name          : SendAttThenJob
  157.  *
  158.  * Description   : This function will show how to use the Bidi API
  159.  *                 NslSetBidiPrint.
  160.  *                 The function will also display the status of the
  161.  *                 string to print.
  162.  *
  163.  * API's         : NlsSetBidiPrint
  164.  *                 VioWrtCharStr
  165.  *
  166.  * Parameters    : This program does not take any command line parameters
  167.  *
  168.  * Returns       : None
  169.  *
  170.  ************************************************************************/
  171. VOID SendAttThenJob(VOID)
  172. {
  173.  
  174.    APIRET   RC=0;
  175.    HFILE    hfileFileHandle;
  176.    ULONG    ulBidiAttr;
  177.    ULONG    ulLength=8L;
  178.    ULONG    ulAction = 0;
  179.    ULONG    ulBytesWritten;
  180.  
  181.  
  182.    ulBidiAttr =  BD_LEVEL
  183.                | BD_SUPPORT
  184.                | BDORIENT_RTL
  185.                | BDNUM_PASSTHRU
  186.                | BDCSD_PASSTHRU;
  187.  
  188.    RC = DosOpen(PRINTER,
  189.                 &hfileFileHandle,
  190.                 &ulAction,
  191.                 0L,
  192.                 FILE_SYSTEM,
  193.                 OPEN_ACTION_OPEN_IF_EXISTS,
  194.                 OPEN_ACCESS_WRITEONLY |  OPEN_SHARE_DENYREAD,
  195.                 (PEAOP2)NULL);
  196.    if (RC)
  197.    {
  198.      printf ("Cannot open the Printet to write RC=%ld\n",RC);
  199.      exit (1);
  200.    }
  201.  
  202.    RC = NlsSetBidiPrint( ulBidiAttr, ulLength, (HFILE)hfileFileHandle);
  203.  
  204.    if (RC)
  205.    {
  206.      printf ("Error in sending string's attributes to the printer RC=%ld\n",RC);
  207.      exit (1);
  208.    }
  209.    else
  210.    {
  211.      RC = DosWrite(hfileFileHandle,
  212.                    cString,
  213.                    strlen(cString),
  214.                    &ulBytesWritten);
  215.  
  216.      if (RC)
  217.      {
  218.        printf ("Error in writting the string to the printer RC=%ld\n",RC);
  219.        exit(1);
  220.      }
  221.      else
  222.      {
  223.        VioWrtCharStr("The string is been sent to the printer", 40, 18, 23, 0l);
  224.      }
  225.    }
  226.  
  227.    RC = DosClose(hfileFileHandle);
  228.    if (RC)
  229.    {
  230.      printf ("Error in closing the printer device RC=%ld\n",RC);
  231.      exit (1);
  232.    }
  233. }
  234. /*************************************************************************
  235.  * Name          : SET_CUR
  236.  *
  237.  * Description   : This function hides or restores the cursor position.
  238.  *
  239.  * API's         : VioSetCurType
  240.  *
  241.  * Parameters    : (INT flag)
  242.  *                 flag indicates whether we want ot hide or restore
  243.  *                 the cursor.
  244.  *
  245.  * Returns       : None
  246.  *
  247.  ************************************************************************/
  248.  
  249. VOID SetCur(INT iFlag)
  250. {
  251.    HVIO HVIOhandle = 0;
  252.    VIOCURSORINFO cursor;
  253.  
  254.    cursor.yStart  = 3;
  255.    cursor.cEnd    = 5;
  256.    cursor.cx      = 0;
  257.    cursor.attr    = iFlag;
  258.  
  259.    VioSetCurType(&cursor, HVIOhandle);
  260. }
  261.  
  262.