home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / MSC_WIND.ZIP / WINDOWS.C next >
Encoding:
C/C++ Source or Header  |  1987-12-06  |  6.5 KB  |  229 lines

  1. #include <graph.h>
  2. #include <windows.h>
  3.  
  4.  
  5. void set_text_mode()
  6.   {
  7.   if (_setvideomode(_TEXTC80))
  8.     {
  9.     video_mode_set = _TEXTC80;
  10.     video_base = 0xb800;
  11.     }
  12.   else
  13.     if (_setvideomode(_TEXTBW80))
  14.       {
  15.       video_mode_set = _TEXTBW80;
  16.       video_base = 0xb000;
  17.       }
  18.     else
  19.       if (_setvideomode(_TEXTC40))
  20.         {
  21.         video_mode_set = _TEXTC40;
  22.         video_base = 0xb800;
  23.         }
  24.       else
  25.         if (_setvideomode(_TEXTBW40))
  26.           {
  27.           video_mode_set = _TEXTBW40;
  28.           video_base = 0xb000;
  29.           }
  30.         else
  31.           if (_setvideomode(_TEXTMONO))
  32.             {
  33.             video_mode_set = (_TEXTMONO);
  34.             video_base = 0xb000;
  35.             }
  36.   }
  37.  
  38. int makebxwindow(up_row, up_col, down_row, down_col, fore_color, back_color,
  39.   border_fore, border_back)
  40.   short up_row;
  41.   short up_col;
  42.   short down_row;
  43.   short down_col;
  44.   short fore_color;
  45.   short back_color;
  46.   short border_fore;
  47.   short border_back;
  48.   {
  49.   int window_made = 1;
  50.   int count;
  51.   int max_count;
  52.   short old_wrap;
  53.   char hold_char[2];
  54.  
  55.   if (((down_row - up_row) < 3) || ((down_col - up_col) < 5))
  56.     return(0);
  57.   old_wrap = _wrapon(_GWRAPOFF);
  58.   window_made = makewindow(up_row,up_col,down_row,down_col,
  59.   border_fore,border_back);
  60.   if (!window_made)
  61.     {
  62.     _wrapon(old_wrap);
  63.     return(0);
  64.     }
  65.   hold_char[0] = UP_LEFT_CORNER;
  66.   hold_char[1] = '\00';
  67.   _outtext(hold_char);
  68.   hold_char[0] = HORZ_LINE;
  69.   max_count = (down_col - up_col) - 1;
  70.   for (count = 0; count < max_count; count++)
  71.     _outtext(hold_char);
  72.   hold_char[0] = UP_RIGHT_CORNER;
  73.   _outtext(hold_char);
  74.   hold_char[0] = VERT_LINE;
  75.   max_count = (down_row - up_row) + 1;
  76.   for (count = 2; count < max_count; count++)
  77.     {
  78.     _settextposition(count, down_col);
  79.     _outtext(hold_char);
  80.     }
  81.   _settextposition(down_row,1);
  82.   hold_char[0] = DOWN_LEFT_CORNER;
  83.   _outtext(hold_char);
  84.   hold_char[0] = HORZ_LINE;
  85.   max_count = (down_col - up_col) - 1;
  86.   for (count = 0; count < max_count; count++)
  87.     _outtext(hold_char);
  88.   hold_char[0] = DOWN_RIGHT_CORNER;
  89.   _outtext(hold_char);
  90.   hold_char[0] = VERT_LINE;
  91.   max_count = (down_row - up_row) + 1;
  92.   for (count = 2; count < max_count; count++)
  93.     {
  94.     _settextposition(count, 1);
  95.     _outtext(hold_char);
  96.     }
  97.   hold_char[0] = VERT_LINE;
  98.   up_row += 1;
  99.   up_col += 2;
  100.   down_row -= 1;
  101.   down_col -= 2;
  102.   window_made = makewindow(up_row,up_col,down_row,down_col,
  103.     fore_color,back_color);
  104.   _wrapon(old_wrap);
  105.   if (!window_made)
  106.     return(0);
  107.   else
  108.     return(1);
  109.   }
  110.  
  111.  
  112. int makewindow(up_row, up_col, down_row, down_col, fore_color, back_color)
  113.   short up_row;
  114.   short up_col;
  115.   short down_row;
  116.   short down_col;
  117.   short fore_color;
  118.   short back_color;
  119.   {
  120.   int num_bytes;
  121.   int bytes_per_line;
  122.   int loop;
  123.   int start_pos;
  124.   unsigned int vid_offset = 0;
  125.   struct rccoord cp;
  126.   struct videoconfig vc;
  127.  
  128.   if (window.current_window > (MAX_WINDOW_NUMBER - 1))
  129.     return(0);
  130.   _getvideoconfig(&vc);
  131.   if ((down_row <= up_row) || (down_col <= up_col))
  132.     return(0);
  133.   if ((up_row < 1) || (up_row > vc.numtextrows))
  134.     return(0);
  135.   if ((up_col < 1) || (up_col > vc.numtextcols))
  136.     return(0);
  137.   if ((down_row < 1) || (down_row > vc.numtextrows))
  138.     return(0);
  139.   if ((down_col < 1) || (down_col > vc.numtextcols))
  140.     return(0);
  141.   if ((video_mode_set == _TEXTBW40) || (video_mode_set == _TEXTBW80) ||
  142.     (video_mode_set == _TEXTMONO))
  143.     {
  144.     fore_color = WHITE;
  145.     back_color = BLACK;
  146.     }
  147.   if (window.current_window == 0)
  148.     {
  149.     window.up_row[0] = 1;
  150.     window.up_col[0] = 1;
  151.     window.down_row[0] = vc.numtextrows;
  152.     window.down_col[0] = vc.numtextcols;
  153.     num_bytes = ((vc.numtextrows * vc.numtextcols) * 2);
  154.     window.hold_address[0] = _fmalloc(num_bytes);
  155.     movedata(video_base, 0x0000, FP_SEG(window.hold_address[0]),
  156.       FP_OFF(window.hold_address[0]), num_bytes);
  157.     }
  158.   cp = _gettextposition();
  159.   window.cursor_row[window.current_window] = cp.row;
  160.   window.cursor_col[window.current_window] = cp.col;
  161.   window.fore_color[window.current_window] = _gettextcolor();
  162.   window.back_color[window.current_window] = _getbkcolor();
  163.   window.current_window += 1;
  164.   _settextcolor(fore_color);
  165.   _setbkcolor(back_color);
  166.   num_bytes = (((down_row - up_row) + 1) * ((down_col - up_col) + 1)) * 2;
  167.   window.hold_address[window.current_window] = _fmalloc(num_bytes);
  168.   bytes_per_line = ((down_col - up_col) + 1) * 2;
  169.   for (loop = up_row; loop < (down_row + 1); loop++)
  170.     {
  171.     start_pos = (((loop - 1) * (vc.numtextcols * 2)) + ((up_col - 1) * 2));
  172.     movedata(video_base, start_pos,
  173.       FP_SEG(window.hold_address[window.current_window]),
  174.       (FP_OFF(window.hold_address[window.current_window]) + vid_offset),
  175.       bytes_per_line);
  176.     vid_offset += bytes_per_line;
  177.     }
  178.   _settextwindow(up_row, up_col, down_row, down_col);
  179.   _clearscreen(_GWINDOW);
  180.   window.up_row[window.current_window] = up_row;
  181.   window.up_col[window.current_window] = up_col;
  182.   window.down_row[window.current_window] = down_row;
  183.   window.down_col[window.current_window] = down_col;
  184.   return(1);
  185.   }
  186.  
  187. int unmakebxwindow()
  188.   {
  189.   unmakewindow();
  190.   unmakewindow();
  191.   }
  192.  
  193. int unmakewindow()
  194.   {
  195.   int loop;
  196.   unsigned int vid_offset = 0;
  197.   int start_pos;
  198.   int bytes_per_line;
  199.   struct rccoord cp;
  200.   struct videoconfig vc;
  201.  
  202.   if (window.current_window == 0)
  203.     return(0);
  204.   _getvideoconfig(&vc);
  205.   bytes_per_line = ((window.down_col[window.current_window] -
  206.     window.up_col[window.current_window]) + 1) * 2;
  207.   for (loop = window.up_row[window.current_window];
  208.     loop < (window.down_row[window.current_window] + 1); loop++)
  209.     {
  210.     start_pos = (((loop - 1) * (vc.numtextcols * 2)) +
  211.       ((window.up_col[window.current_window] - 1) * 2));
  212.     movedata(FP_SEG(window.hold_address[window.current_window]),
  213.     (FP_OFF(window.hold_address[window.current_window]) + vid_offset),
  214.     video_base, start_pos, bytes_per_line);
  215.     vid_offset += bytes_per_line;
  216.     }
  217.   window.current_window -= 1;
  218.   _settextcolor(window.fore_color[window.current_window]);
  219.   _setbkcolor(window.back_color[window.current_window]);
  220.   _settextwindow(window.up_row[window.current_window],
  221.     window.up_col[window.current_window],
  222.     window.down_row[window.current_window],
  223.     window.down_col[window.current_window]);
  224.   _settextposition(window.cursor_row[window.current_window],
  225.     window.cursor_col[window.current_window]);
  226.   return(1);
  227.   }
  228.  
  229.