Advertisement
PiotrGrochowski

Untitled

Jul 1st, 2020
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.22 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdint.h>
  3.  
  4.     const uint16_t width = 80;
  5.     const uint16_t height = 30;
  6.     SMALL_RECT testscreenrect={0, 0, width-1, height-1};
  7.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  8.     CHAR_INFO screen[width*height];
  9. typedef struct _CONSOLE_SCREEN_BUFFER_INFOEX {
  10.   ULONG      cbSize;
  11.   COORD      dwSize;
  12.   COORD      dwCursorPosition;
  13.   WORD       wAttributes;
  14.   SMALL_RECT srWindow;
  15.   COORD      dwMaximumWindowSize;
  16.   WORD       wPopupAttributes;
  17.   BOOL       bFullscreenSupported;
  18.   COLORREF   ColorTable[16];
  19. } CONSOLE_SCREEN_BUFFER_INFOEX, *PCONSOLE_SCREEN_BUFFER_INFOEX;
  20.  
  21. extern "C" BOOL WINAPI GetConsoleScreenBufferInfoEx(
  22.   HANDLE hConsoleOutput,
  23.   PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx
  24. );
  25.  
  26. extern "C" BOOL WINAPI SetConsoleScreenBufferInfoEx(
  27.   HANDLE hConsoleOutput,
  28.   PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx
  29. );
  30. void initscreen(){
  31.     SetConsoleOutputCP(437);
  32.     CONSOLE_CURSOR_INFO temp2={100, 0};
  33.     SetConsoleCursorInfo(hConsole, &temp2);
  34.     CONSOLE_SCREEN_BUFFER_INFO temp;
  35.     GetConsoleScreenBufferInfo(hConsole, &temp);
  36.     SetConsoleScreenBufferSize(hConsole, {width, temp.dwSize.Y});
  37.     SetConsoleScreenBufferSize(hConsole, {temp.dwSize.X, height});
  38.     SetConsoleScreenBufferSize(hConsole, {width, height});
  39.     SetConsoleWindowInfo(hConsole, 1, &testscreenrect);
  40.     SetConsoleScreenBufferSize(hConsole, {width, height});
  41.     CONSOLE_SCREEN_BUFFER_INFOEX colorinfo;
  42.     colorinfo.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
  43.     HMODULE KERNEL32 = LoadLibrary("KERNEL32.dll");
  44.     if (KERNEL32 != NULL){
  45.         auto GetConsoleScreenBufferInfoExfunction = reinterpret_cast<decltype(GetConsoleScreenBufferInfoEx)*>(GetProcAddress(KERNEL32, "GetConsoleScreenBufferInfoEx"));
  46.         if (GetConsoleScreenBufferInfoExfunction != NULL){
  47.             GetConsoleScreenBufferInfoExfunction(hConsole, &colorinfo);
  48.         }
  49.     }
  50.     colorinfo.dwSize = {width, height};
  51.     colorinfo.srWindow.Left = 0;
  52.     colorinfo.srWindow.Top = 0;
  53.     colorinfo.srWindow.Right = width;
  54.     colorinfo.srWindow.Bottom = height;
  55.     for(int i=0; i<16; i++){
  56.         colorinfo.ColorTable[i] = (i&1)*0xAA0000+(i&2)/2*0x00AA00+(i&4)/4*0x0000AA+(i&8)/8*0x555555;
  57.     }
  58.     if (KERNEL32 != NULL){
  59.         auto SetConsoleScreenBufferInfoExfunction = reinterpret_cast<decltype(SetConsoleScreenBufferInfoEx)*>(GetProcAddress(KERNEL32, "SetConsoleScreenBufferInfoEx"));
  60.         if (SetConsoleScreenBufferInfoExfunction != NULL){
  61.             SetConsoleScreenBufferInfoExfunction(hConsole, &colorinfo);
  62.         }
  63.     }
  64. }
  65.  
  66. int main(){
  67.     initscreen();
  68.     const char* colortable = "\
  69. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  70. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  71. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  72. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  73. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  74. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  75. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  76. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  77. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  78. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  79. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  80. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  81. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  82. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  83. \x00\x00\x00\x00\x10\x10\x10\x10\x20\x20\x20\x20\x30\x30\x30\x30\x40\x40\x40\x40\x50\x50\x50\x50\x60\x60\x60\x60\x70\x70\x70\x70\x80\x80\x80\x80\x90\x90\x90\x90\xa0\xa0\xa0\xa0\xb0\xb0\xb0\xb0\xc0\xc0\xc0\xc0\xd0\xd0\xd0\xd0\xe0\xe0\xe0\xe0\xf0\xf0\xf0\xf0pppppppppppppppp\
  84. \x00\x00\x00\x00\x01\x01\x01\x01\x02\x02\x02\x02\x03\x03\x03\x03\x04\x04\x04\x04\x05\x05\x05\x05\x06\x06\x06\x06\x07\x07\x07\x07\x08\x08\x08\x08\x09\x09\x09\x09\x0a\x0a\x0a\x0a\x0b\x0b\x0b\x0b\x0c\x0c\x0c\x0c\x0d\x0d\x0d\x0d\x0e\x0e\x0e\x0e\x0f\x0f\x0f\x0fpppppppppppppppp\
  85. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  86. \x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\x09\x09\x0a\x0a\x0b\x0b\x0c\x0c\x0d\x0d\x0e\x0e\x0f\x0f\x10\x10\x11\x11\x12\x12\x13\x13\x14\x14\x15\x15\x16\x16\x17\x17\x18\x18\x19\x19\x1a\x1a\x1b\x1b\x1c\x1c\x1d\x1d\x1e\x1e\x1f\x1fpppppppppppppppp\
  87.  !!\"\"##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??pppppppppppppppp\
  88. @@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\\\]]^^__pppppppppppppppp\
  89. ``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~\x7f\x7fpppppppppppppppp\
  90. \x80\x80\x81\x81\x82\x82\x83\x83\x84\x84\x85\x85\x86\x86\x87\x87\x88\x88\x89\x89\x8a\x8a\x8b\x8b\x8c\x8c\x8d\x8d\x8e\x8e\x8f\x8f\x90\x90\x91\x91\x92\x92\x93\x93\x94\x94\x95\x95\x96\x96\x97\x97\x98\x98\x99\x99\x9a\x9a\x9b\x9b\x9c\x9c\x9d\x9d\x9e\x9e\x9f\x9fpppppppppppppppp\
  91. \xa0\xa0\xa1\xa1\xa2\xa2\xa3\xa3\xa4\xa4\xa5\xa5\xa6\xa6\xa7\xa7\xa8\xa8\xa9\xa9\xaa\xaa\xab\xab\xac\xac\xad\xad\xae\xae\xaf\xaf\xb0\xb0\xb1\xb1\xb2\xb2\xb3\xb3\xb4\xb4\xb5\xb5\xb6\xb6\xb7\xb7\xb8\xb8\xb9\xb9\xba\xba\xbb\xbb\xbc\xbc\xbd\xbd\xbe\xbe\xbf\xbfpppppppppppppppp\
  92. \xc0\xc0\xc1\xc1\xc2\xc2\xc3\xc3\xc4\xc4\xc5\xc5\xc6\xc6\xc7\xc7\xc8\xc8\xc9\xc9\xca\xca\xcb\xcb\xcc\xcc\xcd\xcd\xce\xce\xcf\xcf\xd0\xd0\xd1\xd1\xd2\xd2\xd3\xd3\xd4\xd4\xd5\xd5\xd6\xd6\xd7\xd7\xd8\xd8\xd9\xd9\xda\xda\xdb\xdb\xdc\xdc\xdd\xdd\xde\xde\xdf\xdfpppppppppppppppp\
  93. \xe0\xe0\xe1\xe1\xe2\xe2\xe3\xe3\xe4\xe4\xe5\xe5\xe6\xe6\xe7\xe7\xe8\xe8\xe9\xe9\xea\xea\xeb\xeb\xec\xec\xed\xed\xee\xee\xef\xef\xf0\xf0\xf1\xf1\xf2\xf2\xf3\xf3\xf4\xf4\xf5\xf5\xf6\xf6\xf7\xf7\xf8\xf8\xf9\xf9\xfa\xfa\xfb\xfb\xfc\xfc\xfd\xfd\xfe\xfe\xff\xffpppppppppppppppp\
  94. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  95. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  96. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  97. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
  98. pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp";
  99.     const char* texttable = "\
  100. The quick brown fox jumps over the lazy dog.                                    \
  101.                                                                                \
  102. All CP437 characters:                                                           \
  103. \x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?                \
  104. @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f                \
  105. \x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf                \
  106. \xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff                \
  107.                                                                                \
  108. \xda\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc2\xc4\xbf  \xd6\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xd2\xc4\xb7  \xd5\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xd1\xcd\xb8  \xc9\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcb\xcd\xbb          \
  109. \xb3Single table\xb3 \xb3  \xbaMixed1 table\xba \xba  \xb3Mixed2 table\xb3 \xb3  \xba""Double table\xba \xba  \xf4       \
  110. \xc3\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc5\xc4\xb4  \xc7\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xd7\xc4\xb6  \xc6\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xd8\xcd\xb5  \xcc\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xce\xcd\xb9  \xb3       \
  111. \xc0\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc1\xc4\xd9  \xd3\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xd0\xc4\xbd  \xd4\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcf\xcd\xbe  \xc8\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xca\xcd\xbc  \xf5       \
  112.                                                                                \
  113. 16 colors:                                                                      \
  114.                                                                                \
  115. \xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb                \
  116.                                                                                \
  117. xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
  118. xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
  119. xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
  120. xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
  121. xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
  122. xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
  123. xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
  124. xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy                \
  125.                                                                                \
  126.                                                                                \
  127.                                                                                \
  128.                                                                                \
  129.                                                                                \
  130. ";
  131.     for(int i=0; i<width*height; i++){
  132.         screen[i].Attributes = (uint8_t)colortable[i];
  133.         screen[i].Char.AsciiChar = (uint8_t)texttable[i];
  134.     }
  135.     WriteConsoleOutput(hConsole, screen, {width, height}, {0, 0}, &testscreenrect);
  136.     while(true);
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement