⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.cpp

📁 串行通信编程源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ******************************************************************** //
//                                                                      //
//      WINDOW.CPP                                                      //
//      Copyright (c) 1993, Michael Holmes and Bob Flanders             //
//      C++ Communication Utilities                                     //
//                                                                      //
//      Chapter 7: Receiving a FAX                                      //
//      Last changed in chapter 2                                       //
//                                                                      //
//      This file contains the definition and interface for             //
//      the window class.                                               //
//                                                                      //
// ******************************************************************** //

//
//  MSC specific defines
//

#define BLACK           0                   // standard colors
#define BLUE            1
#define GREEN           2
#define CYAN            3
#define RED             4
#define MAGENTA         5
#define BROWN           6
#define LIGHTGRAY       7
#define DARKGRAY        8
#define LIGHTBLUE       9
#define LIGHTGREEN      10
#define LIGHTCYAN       11
#define LIGHTRED        12
#define LIGHTMAGENTA    13
#define YELLOW          14
#define WHITE           15
                                            // MSC text window defines
#define gotoxy(x,y) _settextposition(y, x)  // cursor position in window
#define clrscr()    _clearscreen(_GWINDOW)  // clear screen
#define textcolor(x)      _settextcolor((short) x)  // set up text and
#define textbackground(x) _setbkcolor(x)            // ..and bkgnd color
#define window(ur,uc,lr,lc) _settextwindow(uc, ur, lc, lr) // window define

//
//  Globals
//

int     _wscroll = 1,                       // global text scroll flag
        cprintf(char *msg, ...);            // message to format/display

enum    boxes                               // line drawing box types
    {
    none = -1,                              // no box
    single_line,                            // single line box
    double_line                             // double line box
    };

struct  box_characters                      // box drawing characters
     {
     char ul_char,                          // upper left corner
          ur_char,                          // upper right corner
          ll_char,                          // lower left corner
          lr_char,                          // lower right corner
          top_char,                         // horizontal line
          side_char;                        // vertical line
     } box_chars[2] =
         {
         { '\xda', '\xbf', '\xc0', '\xd9',  // single line box
           '\xc4', '\xb3'},
         { '\xc9', '\xbb', '\xc8', '\xbc',  // double line box
           '\xcd', '\xba'}
         };

class Window
    {
    public:
        Window(char ul_c, char ul_r,        // define window, upper left
               char lr_c, char lr_r,        //   lower right,
               char cn,   char cr);         //   normal & reverse colors
        void Open(boxes box = none),        // open window
             AtSay(int c, int r, char *s),  // display string at position
             AtSayReverse(int c, int r,     // display string at position
               char *s),                    //   in reverse video
             Display(char),                 // display a character
             Display(char *s),              // display a string
             DisplayReverse(char *s),       // display string in rev video
             Clear(void),                   // clear window
             GotoXY(int c, int r),          // goto xy location
             MakeCurrent(void),             // make window current
             Close(void);                   // close window
       ~Window();                           // destructor

    private:
        char  ul_col, ul_row,               // window upper left
              lr_col, lr_row,               // ..and lower right
              cursor_col, cursor_row,       // cursor column and row
              cn_color, cr_color,           // norm and reverse colors
             *old_data,                     // overlaid data
              open_flag,                    // window open/close flag
              scroll_flag;                  // scrolling enabled flag
        boxes border_flag;                  // border type
    };



//
//  Globals
//

int     max_lines = 25;                     // max lines on screen

Window *last_window;                        // last window pointer



//
//  Routine Definitions
//

int     wherex(void),                       // get current cursor
        wherey(void);                       // ..x and y locations



/* ******************************************************************** *
 *
 *  Window -- define window instance
 *
 * ******************************************************************** */

Window::Window(char ul_c, char ul_r,        // upper left corner
               char lr_c, char lr_r,        // lower right corner
               char cn,   char cr)          // normal and reverse colors
{

ul_col = ul_c;                              // save window coordinates
ul_row = ul_r;                              // ..row and column
lr_col = lr_c;                              // ..for upper left
lr_row = lr_r;                              // ..and lower right

cn_color = cn;                              // save user colors
cr_color = cr;                              // ..for later

cursor_col = cursor_row = 1;                // init cursor column and row
open_flag = 0;                              // clear open flags

old_data = new char[(((lr_c - ul_c) + 1)    // get work buffer
            * ((lr_r - ul_r) + 1)) * 2];    // ..for old screen image

}



/* ******************************************************************** *
 *
 *  Open -- open a window
 *
 * ******************************************************************** */

void    Window::Open(boxes box)             // border flag
{
int     i;                                  // loop control
struct  box_characters *b;                  // box characters


if (open_flag)                              // q. window already opened?
    return;                                 // a. yes .. just return

border_flag = box;                          // set border flag
open_flag = 1;                              // show window opened

gettext(ul_col, ul_row, lr_col, lr_row,     // capture old screen data
            old_data);                      // ..to temp buffer

window(ul_col, ul_row, lr_col, lr_row);     // make window active

textcolor(FG(cn_color));                    // set up foreground
textbackground(BG(cn_color));               // ..and background colors

clrscr();                                   // clear window
scroll_flag = _wscroll;                     // ..and save scroll setting

if (box != none)                            // q. border requested?
    {                                       // a. yes .. draw the box
    b = &box_chars[box];                    // get line drawing group
    _wrapon(_GWRAPOFF);                     // disable text scrolling

    gotoxy(1, 1);                           // goto upper left corner
    cprintf("%c", b->ul_char);              // put out first corner

    for (i = 1; i < (lr_col - ul_col); i++) // build top of box..
        cprintf("%c", b->top_char);         // ..with horizontals

    cprintf("%c", b->ur_char);              // ..and upper right corner

    gotoxy(1, (lr_row - ul_row) + 1);       // goto lower left corner
    cprintf("%c", b->ll_char);              // put out bottom corner

    for (i = 1; i < (lr_col - ul_col); i++) // build bottom of box
        cprintf("%c", b->top_char);         // ..with horizontals

    cprintf("%c", b->lr_char);              // ..and lower right corner

    for (i = 2; i <= (lr_row - ul_row); i++)// put the sides on the box
        {
        gotoxy(1, i);                       // jump to left side of box
        cprintf("%c", b->side_char);        // ..and draw a chunk

        gotoxy((lr_col - ul_col) + 1, i);   // ..then jump to right side
        cprintf("%c", b->side_char);        // ..of the box and draw
        }

    }

if (scroll_flag)                            // q. user want scrolling?
    _wrapon(_GWRAPON);                      // a. yes .. enable scrolling

}



/* ******************************************************************** *
 *
 *  AtSay -- display string at position
 *
 * ******************************************************************** */

void    Window::AtSay(int c, int r,         // column and row to
              char *s)                      // display string
{

GotoXY(c, r);                               // set up at the right place

cprintf("%s", s);                           // display string in window

cursor_col = wherex();                      // save cursor column..
cursor_row = wherey();                      // ..and cursor row

}



/* ******************************************************************** *
 *
 *  AtSayReverse -- display string at position in reverse video

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -