home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 2.ddi / TOOLS.2 / EXAMPLES / TCWIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.1 KB  |  110 lines

  1. /**
  2. *    TCWIN.C     Example of Turbo C TOOLS window support of the
  3. *            Turbo C text window.
  4. *
  5. *  Version    6.00 (C)Copyright Blaise Computing Inc. 1989
  6. *
  7. **/
  8.  
  9. #include <bwindow.h>
  10. #include <bkeys.h>
  11. #include <conio.h>
  12.  
  13. int main()
  14. {
  15.     BWINDOW *pwin;
  16.     BORDER  bord;
  17.     WHERE   location;
  18.     int     mode,columns,act_page;
  19.     int     cursor_was_off,row,col,high,low;
  20.     int     scan;
  21.  
  22.     /* Create the window structure in memory.                */
  23.  
  24.     pwin = wncreate(6,        /* Height of data area            */
  25.             40,     /* Width  of data area            */
  26.             SC_CYAN);    /* Attributes of data area        */
  27.     if (pwin == NIL)
  28.     return b_wnerr;     /* Quit if failure.            */
  29.                 /* (b_wnerr records the most        */
  30.                 /* recent window error.)        */
  31.  
  32.     /* Choose style of border.                        */
  33.  
  34.     bord.type = BBRD_SSSS | BBRD_TCT; /* Box drawn with single        */
  35.                 /*   lines, having a top centered   */
  36.                 /*   title.                */
  37.     bord.attr     = SC_MAGENTA;    /* Border will be magenta on black. */
  38.     bord.ttattr  = REVERSE;    /* Title will be black on white.    */
  39.     bord.pttitle = " A Window ";/* Text of the title.               */
  40.  
  41.     /* Choose where to display the window:  the active page on        */
  42.     /* the current display device.                    */
  43.  
  44.     location.dev    = scmode(&mode, &columns, &act_page);
  45.     location.page    = act_page;
  46.     location.corner.row = 10;
  47.     location.corner.col =  5;
  48.  
  49.     /* Retrieve former cursor position and size.            */
  50.  
  51.     cursor_was_off = sccurst(&row, &col, &high, &low);
  52.  
  53.     /* Actually display the window.                    */
  54.  
  55.     if (NIL == wndsplay(pwin, &location, &bord))
  56.     return b_wnerr;     /* Quit if failure.            */
  57.  
  58.     /* Display two messages on the window.                */
  59.  
  60.     wncurmov(0, 0);
  61.     if (b_wnerr)
  62.     return b_wnerr;     /* Quit if failure.            */
  63.  
  64.  
  65.     wnprintf("This is the first line.\n");
  66.     if (b_wnerr)
  67.     return b_wnerr;     /* Quit if failure.            */
  68.  
  69.     wnprintf("This is the second line.\n");
  70.     if (b_wnerr)
  71.     return b_wnerr;     /* Quit if failure.            */
  72.  
  73.     /* Now use the Turbo C text window functions to reposition the  */
  74.     /* cursor and insert a new blank line.  Note that Turbo C TOOLS */
  75.     /* window coordinates use (0, 0) as the upper left corner,        */
  76.     /* whereas Turbo C uses (1, 1).                    */
  77.  
  78.     gotoxy(1, 2);
  79.     insline();
  80.     cprintf("This line is courtesy of cprintf().");
  81.  
  82.     /* Now synchronize the window's memory image with the screen.   */
  83.  
  84.     wnrevupd();
  85.     if (b_wnerr)
  86.     return b_wnerr;     /* Quit if failure.            */
  87.  
  88.     wncurmov(4, 0);
  89.     wnprintf("Press Enter or Esc to quit:");
  90.     if (b_wnerr)
  91.     return b_wnerr;     /* Quit if failure.            */
  92.  
  93.     /* Poll the keyboard till the user presses Enter or ESC.        */
  94.  
  95.     scan = 0;
  96.     while ((scan != KB_S_N_ENTER) && (scan != KB_S_N_ESC))
  97.     kbgetkey(&scan);
  98.  
  99.     /* Remove the window & restore the screen and cursor.        */
  100.  
  101.     wnremove(pwin);
  102.     if (b_wnerr)
  103.     return b_wnerr;     /* Quit if failure.            */
  104.  
  105.     sccurset(row, col);
  106.     scpgcur(cursor_was_off, high, low, CUR_NO_ADJUST);
  107.  
  108.     return wndstroy(pwin);    /* Clean up data structures.        */
  109. }
  110.