home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / MNO100.ZIP / MNOEXAMP.C < prev    next >
C/C++ Source or Header  |  1991-05-19  |  16KB  |  567 lines

  1. /*------------------------------------------------------------*/
  2. /* MNOEXAMP.C      ( OS/2 )                                   */
  3. /*                                                            */
  4. /*                                                            */
  5. /* Demonstrate the MNOCALLS library functions.                */
  6. /*                                                            */
  7. /*                                                            */
  8. /*------------------------------------------------------------*/
  9.  
  10. #include    <stdio.h>             /* Library I/O routines.    */
  11. #include    <stdlib.h>            /* Library common routines. */
  12. #include    <string.h>            /* Library string routines. */
  13.  
  14. #define     INCL_BASE
  15. #include    <os2.h>
  16.  
  17. #include    "SYMTYPES.H"          /* Type definitions.        */
  18.  
  19. #include    "MNOCALLS.H"          /* DLL function definitions.*/
  20.  
  21.  
  22. main ()
  23.    {
  24.       {
  25.       USHORT      usRow ;
  26.       USHORT      usColumn ;
  27.       USHORT      fStatus ;
  28.  
  29.       fStatus  = MnoGetCurPos ( &usRow, &usColumn, 0 ) ;
  30.  
  31.       if ( ! fStatus )
  32.          {
  33.          if ( fStatus == ERROR_OPEN_FAILED )
  34.             fprintf (
  35.                stderr,
  36.                "\nMNOEXAMP has failed because the MNODRVR.SYS device\n"
  37.                   "driver did not open properly.  Status: %u.\n",
  38.                fStatus ) ;
  39.          else
  40.             fprintf (
  41.                stderr,
  42.                "\nMNOEXAMP has failed on the first attempt to use\n"
  43.                "MNOCALLS.DLL.  Status: %u.\n",
  44.                fStatus ) ;
  45.  
  46.          exit ( 1 ) ;
  47.          }
  48.       }
  49.  
  50.  
  51.       {
  52.       USHORT      usRow ;
  53.       USHORT      usColumn ;
  54.       USHORT      fStatus ;
  55.  
  56.       usRow    = 1 ;
  57.       usColumn = 10 ;
  58.  
  59.       fStatus  = MnoSetCurPos ( usRow, usColumn, 0 ) ;
  60.  
  61.                // This sets the cursor position to (1, 10),
  62.                // where the origin (0, 0) is defined as the
  63.                // upper left corner of the screen.
  64.  
  65.       if ( ! fStatus )
  66.          {
  67.                // Error handling.
  68.          }
  69.       }
  70.  
  71.  
  72.       {
  73.       VIOCURSORINFO  vioCursorInfo ;
  74.  
  75.       USHORT      fStatus ;
  76.  
  77.       fStatus  = MnoGetCurType ( &vioCursorInfo, 0 ) ;
  78.  
  79.                // This gets the monochrome cursor type
  80.                // information.
  81.  
  82.       if ( ! fStatus )
  83.          {
  84.                // Error handling.
  85.          }
  86.       }
  87.  
  88.  
  89.       {
  90.       VIOCURSORINFO  vioCursorInfo ;
  91.  
  92.       USHORT      fStatus ;
  93.  
  94.       vioCursorInfo.yStart = 0 ;
  95.       vioCursorInfo.cEnd   = 13 ;
  96.       vioCursorInfo.cx     = 1 ;
  97.       vioCursorInfo.attr   = 0 ;
  98.  
  99.       fStatus              = MnoSetCurType ( &vioCursorInfo, 0 ) ;
  100.  
  101.                // This sets the monochrome cursor as a full
  102.                // 14 scan lines in height and it is made 
  103.                // visible.
  104.  
  105.       if ( ! fStatus )
  106.          {
  107.                // Error handling.
  108.          }
  109.       }
  110.  
  111.  
  112.       {
  113.       VIOPHYSBUF  vioPhysBuf ;
  114.  
  115.       USHORT      fStatus ;
  116.       USHORT      fDetachStatus ;
  117.       USHORT      fAnsi ;
  118.       BYTE        fLockStatus ;
  119.       PCH         pchMonoBuffer ;
  120.  
  121.                /*---------------------------------------------*/
  122.                /* Here is how to test for a detached process. */
  123.                /*---------------------------------------------*/
  124.  
  125.       fDetachStatus  = MnoGetAnsi ( &fAnsi, 0 ) ;
  126.  
  127.       if ( fDetachStatus == ERROR_VIO_DETACHED )
  128.          {
  129.                /*---------------------------------------------*/
  130.                /* Use other Mno functions to manipulate the   */
  131.                /* MDA video buffer since we cannot detect     */
  132.                /* screen group switching.                     */
  133.                /*---------------------------------------------*/
  134.          }
  135.       else
  136.          {
  137.                /*---------------------------------------------*/
  138.                /* If this is the foreground process,          */
  139.                /* then prevent screen group switching until   */
  140.                /* this function completes.                    */
  141.                /*---------------------------------------------*/
  142.  
  143.          fStatus  = VioScrLock ( LOCKIO_NOWAIT, &fLockStatus, 0 ) ;
  144.  
  145.          fStatus  = MnoGetPhysBuf ( &vioPhysBuf, 0 ) ;
  146.  
  147.          pchMonoBuffer    = MAKEP ( vioPhysBuf.asel [ 0 ], 0 ) ;
  148.  
  149.                /*---------------------------------------------*/
  150.                /* At this point, pchMonoBuffer is a read/write*/
  151.                /* pointer into the MDA video buffer, which is */
  152.                /* an array of 2000 character-attribute cells. */
  153.                /*---------------------------------------------*/
  154.  
  155.                // Bright 'A' in the
  156.          *pchMonoBuffer++ = 'A' ;
  157.                // first buffer position.
  158.          *pchMonoBuffer   = 0x0F ;
  159.  
  160.          if ( fLockStatus == LOCK_SUCCESS )
  161.             fStatus       = VioScrUnLock ( 0 ) ;
  162.          }
  163.  
  164.       if ( ! fStatus )
  165.          {
  166.                // Error handling.
  167.          }
  168.       }
  169.  
  170.  
  171.       {
  172.       USHORT      fStatus ;
  173.       USHORT      fAnsi ;
  174.  
  175.       fStatus  = MnoGetAnsi ( &fAnsi, 0 ) ;
  176.  
  177.                // fAnsi is either ANSI_ON or ANSI_OFF.
  178.  
  179.       if ( fStatus )
  180.          {
  181.                // Handle Detached Status or Error.
  182.          }
  183.       }
  184.  
  185.  
  186.       {
  187.       USHORT      fStatus ;
  188.       USHORT      fAnsi ;
  189.  
  190.       fAnsi    = ANSI_ON ;
  191.  
  192.       fStatus  = MnoSetAnsi ( fAnsi, 0 ) ;
  193.  
  194.       fStatus  = MnoWrtTTY ( "\n\n\n\t\bSample Text\r\n", 18, 0 ) ;
  195.  
  196.       if ( ! fStatus )
  197.          {
  198.                // Error handling.
  199.          }
  200.       }
  201.  
  202.  
  203.       {
  204.       USHORT      fStatus  = 0 ;
  205.       USHORT      cText    = 0 ;
  206.       UCHAR       achText [ 500 ]   = "" ;
  207.  
  208.  
  209.                // Read 30 characters starting at
  210.                // the 11th line and 2nd column.
  211.  
  212.       cText                = 30 ;
  213.       fStatus              = MnoReadCharStr ( achText, &cText, 10, 1, 0 ) ;
  214.  
  215.       if ( ! fStatus )
  216.          {
  217.                // Error handling.
  218.          }
  219.       }
  220.  
  221.  
  222.       {
  223.       USHORT      fStatus  = 0 ;
  224.       USHORT      cText    = 0 ;
  225.       UCHAR       achText [ 500 ]   = "" ;
  226.  
  227.  
  228.                // Read 15 characters-attribute pairs
  229.                // starting at the 1st line and 5th
  230.                // column.
  231.  
  232.       cText                = 30 ;
  233.       fStatus              = MnoReadCellStr ( achText, &cText, 0, 4, 0 ) ;
  234.  
  235.       if ( ! fStatus )
  236.          {
  237.                // Error handling.
  238.          }
  239.       }
  240.  
  241.  
  242.       {
  243.       USHORT      fStatus        = 0 ;
  244.       BYTE        abCell [ 2 ]   = { 0 } ;
  245.  
  246.                /* Erase monochrome display.                   */
  247.  
  248.       abCell [ 0 ]   = ' ' ;
  249.       abCell [ 1 ]   = 0x07 ;
  250.  
  251.       fStatus        = MnoScrollDn ( 0,        // usTopRow.
  252.                                      0,        // usLeftCol.
  253.                                      0xFFFF,   // usBotRow.
  254.                                      0xFFFF,   // usRightCol.
  255.                                      0xFFFF,   // cbLines.
  256.                                      abCell,
  257.                                      0 ) ;
  258.  
  259.       if ( ! fStatus )
  260.          {
  261.                // Error handling.
  262.          }
  263.       }
  264.  
  265.  
  266.       {
  267.       USHORT      fStatus        = 0 ;
  268.       BYTE        abCell [ 2 ]   = { 0 } ;
  269.  
  270.  
  271.       abCell [ 0 ]   = '.' ;
  272.       abCell [ 1 ]   = 0x0F ;
  273.  
  274.                /*---------------------------------------------*/
  275.                /* Scroll the box at  (row,col):               */
  276.                /*                                             */
  277.                /*            (0,74)----------+                */
  278.                /*              |             |                */
  279.                /*              |             |  */
  280.                /*              |             |                */
  281.                /*              +----------(24,79)             */
  282.                /*                                             */
  283.                /* Up 1 row.                                   */
  284.                /*---------------------------------------------*/
  285.  
  286.       fStatus  = MnoScrollUp ( 0, 74, 24, 79, 1, abCell, 0 ) ;
  287.  
  288.       if ( ! fStatus )
  289.          {
  290.                // Error handling.
  291.          }
  292.       }
  293.  
  294.  
  295.       {
  296.       USHORT      fStatus        = 0 ;
  297.       BYTE        abCell [ 2 ]   = { 0 } ;
  298.  
  299.  
  300.                // Fill character.
  301.       abCell [ 0 ]   = '#' ;
  302.       abCell [ 1 ]   = 0x0F ;
  303.  
  304.                /*---------------------------------------------*/
  305.                /* Scroll the box at  (row,col):               */
  306.                /*                                             */
  307.                /*            (0,0)-----------+                */
  308.                /*              |             |                */
  309.                /*              |             |                */
  310.                /*              |             |                */
  311.                /*              +----------(5,79)              */
  312.                /*                                             */
  313.                /* Left 10 columns.                            */
  314.                /*---------------------------------------------*/
  315.  
  316.       fStatus        = MnoScrollLf ( 0, 0, 5, 79, 10, abCell, 0 ) ;
  317.  
  318.       if ( ! fStatus )
  319.          {
  320.                // Error handling.
  321.          }
  322.       }
  323.  
  324.  
  325.       {
  326.       USHORT      fStatus        = 0 ;
  327.       BYTE        abCell [ 2 ]   = { 0 } ;
  328.  
  329.  
  330.                // Fill character.
  331.       abCell [ 0 ]   = '.' ;
  332.       abCell [ 1 ]   = 0x07 ;
  333.  
  334.                /*---------------------------------------------*/
  335.                /* Scroll the box at  (row,col):               */
  336.                /*                                             */
  337.                /*            (0,0)-----------+                */
  338.                /*              |             |                */
  339.                /*              |             |                */
  340.                /*              |             |                */
  341.                /*              +----------(24,79)             */
  342.                /*                                             */
  343.                /* Right 80 columns.                           */
  344.                /*---------------------------------------------*/
  345.  
  346.       fStatus        = MnoScrollRt ( 0,          // usTopRow.
  347.                                      0,          // usLeftCol.
  348.                                      0xFFFF,     // usBotRow.
  349.                                      0xFFFF,     // usRightCol.
  350.                                      0xFFFF,     // cbLines.
  351.                                      abCell,
  352.                                      0 ) ;
  353.  
  354.       if ( ! fStatus )
  355.          {
  356.                // Error handling.
  357.          }
  358.       }
  359.  
  360.  
  361.       {
  362.       USHORT      fStatus        = 0 ;
  363.       UCHAR       szText [ 20 ]  = "hello world" ;
  364.  
  365.                // Display string at 2nd row, 1st column.
  366.  
  367.       fStatus                    = MnoWrtCharStr ( szText,
  368.             strlen ( szText ),
  369.             1,
  370.             0,
  371.             0 ) ;
  372.  
  373.       if ( ! fStatus )
  374.          {
  375.                // Error handling.
  376.          }
  377.       }
  378.  
  379.  
  380.       {
  381.       USHORT      fStatus        = 0 ;
  382.       UCHAR       szText [ 200 ] = "" ;
  383.  
  384.                // Display string at 11th row, 2nd column.
  385.  
  386.       strcpy ( szText,
  387.          "T\07e\07s\07t\07 \07o\07f\07 \07"
  388.             "W\07r\07t\07C\07e\07l\07l\07S\07"
  389.             "t\07r\07" ) ;
  390.  
  391.  
  392.       fStatus  = MnoWrtCellStr ( szText,
  393.                                  strlen ( szText ),
  394.                                  10,
  395.                                  1,
  396.                                  0 ) ;
  397.  
  398.       if ( ! fStatus )
  399.          {
  400.                // Error handling.
  401.          }
  402.       }
  403.  
  404.  
  405.       {
  406.       USHORT      fStatus        = 0 ;
  407.       UCHAR       szText [ 50 ]  = "" ;
  408.       BYTE        bAttr          = 0x00 ;
  409.  
  410.       bAttr                      = 0x70 ;
  411.  
  412.       strcpy ( szText, "hello world" ) ;
  413.  
  414.  
  415.                // Display 'hello world' on the 6th row
  416.                // and 11th column.
  417.  
  418.  
  419.       fStatus  = MnoWrtCharStr ( szText,
  420.                                  strlen ( szText ),
  421.                                  5,
  422.                                  10,
  423.                                  0 ) ;
  424.  
  425.                // Set the attributes for 'hello world'.
  426.  
  427.  
  428.       fStatus  = MnoWrtNAttr ( &bAttr,
  429.                                strlen ( szText ),
  430.                                5,
  431.                                10,
  432.                                0 ) ;
  433.  
  434.       if ( ! fStatus )
  435.          {
  436.                // Error handling.
  437.          }
  438.       }
  439.  
  440.  
  441.       {
  442.       USHORT      fStatus  = 0 ;
  443.       USHORT      usRow    = 0 ;
  444.       USHORT      usColumn = 0 ;
  445.       BYTE        chChar   = ' ' ;
  446.       PBYTE       pchChar  = &chChar ;
  447.       USHORT      cChars   = 0 ;
  448.  
  449.  
  450.                // Set the last line of the display to all 'E'.
  451.  
  452.       chChar               = 'E' ;
  453.       usRow                = 24 ;
  454.       usColumn             = 0 ;
  455.       cChars               = 80 ;
  456.  
  457.       fStatus  = MnoWrtNChar ( pchChar,
  458.                                cChars,
  459.                                usRow,
  460.                                usColumn,
  461.                                0 ) ;
  462.  
  463.       if ( ! fStatus )
  464.          {
  465.                // Error handling.
  466.          }
  467.       }
  468.  
  469.  
  470.       {
  471.       USHORT      fStatus        = 0 ;
  472.       USHORT      cCells         = 0 ;
  473.       USHORT      usRow          = 0 ;
  474.       USHORT      usColumn       = 0 ;
  475.       BYTE        abCell [ 2 ]   = { 0 } ;
  476.  
  477.                // Display ten 'A' starting at the 3rd row,
  478.                // 79th column, and wrapping onto the 4th row,
  479.                // through the eight column.  The attribute
  480.                // has been set to the normal intensity.
  481.  
  482.       abCell [ 0 ]   = 'A' ;
  483.       abCell [ 1 ]   = 0x07 ;
  484.       cCells         = 10 ;
  485.       usRow          = 2 ;
  486.       usColumn       = 78 ;
  487.  
  488.       fStatus  = MnoWrtNCell ( abCell,
  489.                                cCells,
  490.                                usRow,
  491.                                usColumn,
  492.                                0 ) ;
  493.  
  494.       if ( ! fStatus )
  495.          {
  496.                // Error handling.
  497.          }
  498.       }
  499.  
  500.  
  501.       {
  502.       USHORT      fStatus        = 0 ;
  503.       USHORT      usRow          = 0 ;
  504.       USHORT      usColumn       = 0 ;
  505.       BYTE        bAttr          = 0x07 ;
  506.       UCHAR       szText [ 80 ]  = "" ;
  507.  
  508.       strcpy ( szText, "Some sample text in reverse video" ) ;
  509.       bAttr    = 0x70 ;
  510.  
  511.       fStatus  = MnoWrtCharStrAtt ( szText,
  512.                                     strlen ( szText ),
  513.                                     0,
  514.                                     5,
  515.                                     &bAttr,
  516.                                     0 ) ;
  517.  
  518.       if ( ! fStatus )
  519.          {
  520.                // Error handling.
  521.          }
  522.       }
  523.  
  524.  
  525.       {
  526.       USHORT      fStatus  = 0 ;
  527.       UCHAR       szText [ 200 ] ;
  528.       VIOCURSORINFO  vioCursorInfo ;
  529.  
  530.                // Display "HELLO WORLD" followed by
  531.                // Carriage return - line feed.
  532.  
  533.       strcpy ( szText, "HELLO WORLD\r\n" ) ;
  534.       fStatus  = MnoWrtTTY ( szText, strlen ( szText ), 0 ) ;
  535.  
  536.                // Erase the screen, move the cursor to the upper
  537.                // left position.  Reset all attributes and use
  538.                // normal intensity white text on a dark
  539.                // background. Then display "HELLO WORLD".  The
  540.              // cursor will be placed to the right of the tex>.
  541.  
  542.       strcpy ( szText, "\033[2J\033[0mHELLO WORLD" ) ;
  543.       fStatus  = MnoWrtTTY ( szText, strlen ( szText ), 0 ) ;
  544.  
  545.  
  546.                // Display cursor attributes.
  547.  
  548.       fStatus  = MnoGetCurType ( &vioCursorInfo, 0 ) ;
  549.  
  550.       sprintf ( szText,
  551.          "\r\nCursor Start=%d End=%d Width=%d attr=%x\r\n",
  552.          vioCursorInfo.yStart,
  553.          vioCursorInfo.cEnd,
  554.          vioCursorInfo.cx,
  555.          vioCursorInfo.attr ) ;
  556.  
  557.       fStatus  = MnoWrtTTY ( szText, strlen ( szText ), 0 ) ;
  558.  
  559.       if ( ! fStatus )
  560.          {
  561.                // Error handling.
  562.          }
  563.       }
  564.  
  565.    exit ( 0 ) ;
  566.    }
  567.