Console.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:5k
源码类别:

模拟服务器

开发平台:

C/C++

  1. #include "stdafx.h"
  2. #include "console.h"
  3. /*
  4.  * namespace OnlineGameLib::Win32::Console
  5.  */
  6. namespace OnlineGameLib {
  7. namespace Win32 {
  8. namespace Console {
  9. void clrscr()
  10. {
  11. COORD coordScreen = { 0, 0 }; 
  12. DWORD cCharsWritten;
  13. CONSOLE_SCREEN_BUFFER_INFO csbi;
  14. DWORD dwConSize;
  15. HANDLE hConsole = ::GetStdHandle( STD_OUTPUT_HANDLE ); 
  16. ::GetConsoleScreenBufferInfo( hConsole, &csbi );
  17. dwConSize = csbi.dwSize.X * csbi.dwSize.Y; 
  18. ::FillConsoleOutputCharacter( hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten ); 
  19. ::GetConsoleScreenBufferInfo( hConsole, &csbi ); 
  20. ::FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten ); 
  21. ::SetConsoleCursorPosition( hConsole, coordScreen );
  22. }
  23. void gotoxy( int x, int y )
  24. {
  25. COORD point;
  26. point.X = x;
  27. point.Y = y;
  28. ::SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), point );
  29. }
  30. void getxy( int &x, int &y )
  31. {
  32. CONSOLE_SCREEN_BUFFER_INFO csbi;
  33. ::GetConsoleScreenBufferInfo( ::GetStdHandle( STD_OUTPUT_HANDLE ), &csbi );
  34. x = csbi.dwCursorPosition.X;
  35. y = csbi.dwCursorPosition.Y;
  36. }
  37. void setcolor( int color )
  38. {
  39. switch ( color )
  40. {
  41. case enumWhiteonBlack: // White on Black
  42. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY |
  43. FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
  44. break;
  45. case enumRedonBlack: // Red on Black
  46. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY |
  47. FOREGROUND_RED );
  48. break;
  49. case enumGreenonBlack: // Green on Black
  50. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY |
  51. FOREGROUND_GREEN );
  52. break;
  53. case enumYellowonBlack: // Yellow on Black
  54. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY |
  55. FOREGROUND_RED | FOREGROUND_GREEN );
  56. break;
  57. case enumBlueonBlack: // Blue on Black
  58. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY |
  59. FOREGROUND_BLUE );
  60. break;
  61. case enumMagentaonBlack: // Magenta on Black
  62. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY |
  63. FOREGROUND_RED | FOREGROUND_BLUE );
  64. break;
  65. case enumCyanonBlack: // Cyan on Black
  66. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY |
  67. FOREGROUND_GREEN | FOREGROUND_BLUE );
  68. break;
  69. case enumBlackonGray: // Black on Gray
  70. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), BACKGROUND_INTENSITY |
  71. BACKGROUND_INTENSITY );
  72. break;
  73. case enumBlackonWhite: // Black on White
  74. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), BACKGROUND_INTENSITY |
  75. FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE );
  76. break;
  77. case enumRedonWhite: // Red on White
  78. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), BACKGROUND_INTENSITY |
  79. FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
  80. FOREGROUND_RED );
  81. break;
  82. case enumGreenonWhite: // Green on White
  83. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), BACKGROUND_INTENSITY |
  84. FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
  85. FOREGROUND_GREEN );
  86. break;
  87. case enumYellowonWhite: // Yellow on White
  88. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), BACKGROUND_INTENSITY |
  89. FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
  90. FOREGROUND_RED | FOREGROUND_GREEN );
  91. break;
  92. case enumBlueonWhite: // Blue on White
  93. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), BACKGROUND_INTENSITY |
  94. FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
  95. FOREGROUND_BLUE );
  96. break;
  97. case enumMagentaonWhite: // Magenta on White
  98. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), BACKGROUND_INTENSITY |
  99. FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
  100. FOREGROUND_RED | FOREGROUND_BLUE );
  101. break;
  102. case enumCyanonWhite: // Cyan on White
  103. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), BACKGROUND_INTENSITY |
  104. FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
  105. FOREGROUND_GREEN | FOREGROUND_BLUE );
  106. break;
  107. case enumWhiteonWhite: // White on White
  108. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), BACKGROUND_INTENSITY |
  109. FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
  110. FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
  111. break;
  112. case enumDefault:
  113. default : // White on Black
  114. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY |
  115. FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
  116. break;
  117. }
  118. }
  119. } // End of namespace Console
  120. } // End of namespace Win32
  121. } // End of namespace OnlineGameLib