tconsole.h
上传用户:haiweijt
上传日期:2018-02-23
资源大小:8195k
文件大小:6k
源码类别:

Telnet服务器

开发平台:

Visual C++

  1. #ifndef __TNPARSER_H
  2. #define __TNPARSER_H
  3. #include "tnconfig.h"
  4. /* A diagram of the following values:
  5.  *
  6.  *           (0,0)
  7.  *              +----------------------------------------+
  8.  *              |                                        |
  9.  *              |                                        |
  10.  *              |                                        |
  11.  *              |                                        |
  12.  *              |                                        |
  13.  *              |                                        |
  14.  *              |                                        |
  15.  *              |                                        |
  16.  *              |                                        |
  17.  *              |                                        |
  18.  *              |                                        |
  19.  *              |                                        |
  20.  *              |                                        |
  21.  *              |          CON_TOP                       |
  22.  *              +---------------------------+.....?......|     ---
  23.  *              |              .            |            |      |
  24.  *              |              .            | <-- OR --> |      |
  25.  *              |              .            |            |      |
  26.  *  CON_LEFT    |              .            | CON_RIGHT  |      
  27.  *    (=0)      |              .            | (=CON_     |  CON_LINES
  28.  *              |..............*            |   WIDTH)   |      
  29.  *              |            (CON_CUR_X,    |            |      |
  30.  *              |             CON_CUR_Y)    |            |      |
  31.  *              |                           |            |      |
  32.  *              |                           |            |      |
  33.  *              |                           |            |      |
  34.  *              +---------------------------+------------+     ---
  35.  *                   CON_BOTTOM (=CON_TOP + CON_HEIGHT)
  36.  *
  37.  *              |--------- CON_COLS --------|
  38.  *
  39.  * Keep in mind that CON_TOP, CON_BOTTOM, CON_LEFT, and CON_RIGHT are relative
  40.  * to zero, but CON_CUR_X, CON_CUR_Y, CON_WIDTH, and CON_HEIGHT are relative to
  41.  * CON_TOP and CON_LEFT
  42.  */
  43. #define CON_TOP ConsoleInfo.srWindow.Top
  44. #define CON_BOTTOM ConsoleInfo.srWindow.Bottom
  45. #define CON_LEFT 0
  46. #define CON_RIGHT (ConsoleInfo.dwSize.X - 1)
  47. #define CON_HEIGHT (CON_BOTTOM - CON_TOP)
  48. #define CON_WIDTH (CON_RIGHT - CON_LEFT)
  49. #define CON_LINES (CON_HEIGHT + 1)
  50. #define CON_COLS (CON_WIDTH + 1)
  51. #define CON_CUR_X (ConsoleInfo.dwCursorPosition.X - CON_LEFT)
  52. #define CON_CUR_Y (ConsoleInfo.dwCursorPosition.Y - CON_TOP)
  53. class TConsole {
  54. public:
  55. TConsole(HANDLE hConsole);
  56. ~TConsole();
  57. void sync();
  58. // Cursor movement routines
  59.     int GetRawCursorX() {return CON_CUR_X;}
  60.     int GetRawCursorY() {return CON_CUR_Y;}
  61.     int GetCursorX() {return CON_CUR_X;}
  62.     int GetCursorY() {
  63. if(iScrollStart != -1)
  64. return CON_CUR_Y - iScrollStart;
  65. return GetRawCursorY();
  66. }
  67. void SetRawCursorPosition(int x, int y);
  68. void SetCursorPosition(int x, int y);
  69. void SetCursorSize(int pct);
  70. void MoveCursorPosition(int x, int y);
  71. // Screen mode/size routines
  72.     int GetWidth() {return CON_COLS;}
  73.     int GetHeight() {return CON_LINES;}
  74. void SetExtendedMode(int iFunction, BOOL bEnable);
  75. void SetWindowSize(int width, int height); // Set the size of the window,
  76. // but not the buffer
  77.    
  78. // Color/attribute routines
  79. void SetAttrib(unsigned char wAttr) {wAttributes = wAttr;}
  80.     unsigned char GetAttrib() {return wAttributes;}
  81.     void Normal(); // Reset all attributes
  82.     void HighVideo(); // Aka "bold"
  83.     void LowVideo();
  84.     void SetForeground(unsigned char wAttrib); // Set the foreground directly
  85.     void SetBackground(unsigned char wAttrib);
  86.     void BlinkOn(); // Blink on/off
  87.     void BlinkOff();
  88. void UnderlineOn(); // Underline on/off
  89. void UnderlineOff();
  90. void UlBlinkOn(); // Blink+Underline on/off
  91. void UlBlinkOff();
  92.     void ReverseOn(); // Reverse on/off
  93.     void ReverseOff();
  94. void Lightbg(); // High-intensity background
  95. void Darkbg(); // Low-intensity background
  96. void setDefaultFg(unsigned char u) {defaultfg = u;}
  97. void setDefaultBg(unsigned char u) {defaultbg = u;}
  98. // Text output routines
  99. unsigned long WriteText(const char *pszString, unsigned long cbString);
  100. unsigned long WriteString(const char* pszString, unsigned long cbString);
  101. unsigned long WriteStringFast(const char *pszString, unsigned long cbString);
  102. unsigned long WriteCtrlString(const char* pszString, unsigned long cbString);
  103. unsigned long WriteCtrlChar(char c);
  104. unsigned long NetWriteString(const char* pszString, unsigned long cbString);
  105. // Clear screen/screen area functions
  106. void ClearScreen(char c = ' ');
  107. void ClearWindow(int start, int end, char c = ' ');
  108. void ClearEOScreen(char c = ' ');
  109. void ClearBOScreen(char c = ' ');
  110. void ClearLine(char c = ' ');
  111. void ClearEOLine(char c = ' ');
  112. void ClearBOLine(char c = ' ');
  113. // Scrolling and text output control functions
  114. void SetScroll(int start, int end);
  115.     void ScrollDown(int iStartRow , int iEndRow, int bUp);
  116. void ScrollAll(int bUp) {ScrollDown(iScrollStart, iScrollEnd, bUp);}
  117. void index();
  118. void reverse_index();
  119. void setLineWrap(bool bEnabled){
  120. if(!ini.get_lock_linewrap()) 
  121. ini.set_value("Wrap_Line", bEnabled ? "true" : "false");
  122. }
  123. bool getLineWrap() {return ini.get_wrapline();}
  124.     // Insert/delete characters/lines
  125. void InsertLine(int numlines); // Added by Titus von Boxberg 30/3/97
  126.     void InsertCharacter(int numchar); // "
  127.     void DeleteCharacter(int numchar); // "
  128. void InsertMode(int i) {insert_mode = i;}
  129. // Miscellaneous functions
  130. void Beep();
  131. protected:
  132. HANDLE hConsole;
  133. CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
  134. unsigned char wAttributes;
  135. unsigned char fg, bg;
  136. unsigned char defaultfg, defaultbg;
  137. unsigned char origfg, origbg;
  138. bool blink;
  139. bool underline;
  140. bool reverse;
  141. int iScrollStart;
  142. int iScrollEnd;
  143. int insert_mode;
  144. };
  145. // Non-member functions for saving state -- used by the scrollback buffer viewer
  146. void saveScreen(CHAR_INFO* chiBuffer);
  147. void restoreScreen(CHAR_INFO* chiBuffer);
  148. CHAR_INFO* newBuffer();
  149. void deleteBuffer(CHAR_INFO* chiBuffer);
  150. #endif