SHARE
TWEET

Untitled

a guest Nov 12th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class c_console
  2. {
  3.     void show_cursor( bool state );
  4.     void set_transparency( int value );
  5.     void remove_taskbar( );
  6.     void center( );
  7.  
  8.     void set_size( int16_t width, int16_t height );
  9.     void set_font( );
  10.  
  11.     void print_logo( );
  12. public:
  13.     void setup( );
  14.  
  15.     void print_color( const char* text, uint16_t color );
  16.     void print_line( const char* text );
  17. };
  18.  
  19. extern c_console console;
  20.  
  21.  
  22. #include "console.h"
  23. #include <windows.h>
  24. #include <cstdio>
  25.  
  26. c_console console;
  27.  
  28. static __forceinline void get_screen_size( float& _width, float& _height )
  29. {
  30.     static float width = float( GetSystemMetrics( SM_CXSCREEN ) );
  31.     static float height = float( GetSystemMetrics( SM_CYSCREEN ) );
  32.  
  33.     _width = width;
  34.     _height = height;
  35. }
  36.  
  37. void c_console::show_cursor( bool state )
  38. {
  39.     HANDLE out = GetStdHandle( STD_OUTPUT_HANDLE );
  40.  
  41.     CONSOLE_CURSOR_INFO cursorInfo;
  42.  
  43.     GetConsoleCursorInfo( out, &cursorInfo );
  44.     cursorInfo.bVisible = state;
  45.     SetConsoleCursorInfo( out, &cursorInfo );
  46. }
  47.  
  48. void c_console::set_transparency( int value )
  49. {
  50.     LONG wAttr;
  51.     wAttr = GetWindowLong( GetConsoleWindow( ), GWL_EXSTYLE );
  52.     wAttr |= WS_EX_LAYERED;
  53.     SetWindowLong( GetConsoleWindow( ), GWL_EXSTYLE, wAttr );
  54.     SetLayeredWindowAttributes( GetConsoleWindow( ), 0, value, 2 );
  55. }
  56.  
  57. void c_console::remove_taskbar( )
  58. {
  59.     DWORD dwStyle = GetWindowLong( GetConsoleWindow( ), GWL_STYLE );
  60.     dwStyle &= ~( WS_CAPTION | WS_SIZEBOX );
  61.     dwStyle |= WS_BORDER;
  62.  
  63.     SetWindowLong( GetConsoleWindow( ), GWL_STYLE, dwStyle );
  64.  
  65.     SetWindowPos( GetConsoleWindow( ), NULL, 0, 0, 300, 150, SWP_NOMOVE | SWP_NOZORDER );
  66.  
  67.     set_size( 43, 12 );
  68. }
  69.  
  70. void c_console::set_size( int16_t width, int16_t height )
  71. {
  72.     COORD coord = { width, height };
  73.  
  74.     SMALL_RECT Rect;
  75.     Rect.Top = 0;
  76.     Rect.Left = 0;
  77.     Rect.Bottom = height - 1;
  78.     Rect.Right = width - 1;
  79.  
  80.     const auto stdHandle = GetStdHandle( STD_OUTPUT_HANDLE );
  81.     SetConsoleScreenBufferSize( stdHandle, coord );
  82.     SetConsoleWindowInfo( stdHandle, TRUE, &Rect );
  83. }
  84.  
  85. void c_console::set_font( )
  86. {
  87.     CONSOLE_FONT_INFOEX cfi;
  88.     cfi.cbSize = sizeof cfi;
  89.     cfi.nFont = 0;
  90.     cfi.dwFontSize.X = 6;
  91.     cfi.dwFontSize.Y = 12;
  92.     cfi.FontFamily = FF_DONTCARE;
  93.     cfi.FontWeight = 400;
  94.     wcscpy( cfi.FaceName, L"Consolas" );
  95.     SetCurrentConsoleFontEx( GetStdHandle( STD_OUTPUT_HANDLE ), FALSE, &cfi );
  96. }
  97.  
  98. void c_console::center( )
  99. {
  100.     float width, height;
  101.     get_screen_size( width, height );
  102.  
  103.     RECT console_rect;
  104.     GetWindowRect( GetConsoleWindow( ), &console_rect );
  105.  
  106.     int console_w = console_rect.right - console_rect.left;
  107.     int console_h = console_rect.bottom - console_rect.top;
  108.  
  109.     int console_x = int( width * 0.5f ) - console_w / 2;
  110.     int console_y = int( height * 0.5f ) - console_h / 2;
  111.  
  112.     SetWindowPos( GetConsoleWindow( ), 0, console_x, console_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
  113. }
  114.  
  115. void  c_console::print_color( const char* text, uint16_t color )
  116. {
  117.     HANDLE console_handle = GetStdHandle( STD_OUTPUT_HANDLE );
  118.     SetConsoleTextAttribute( console_handle, color );
  119.     printf( text );
  120. }
  121.  
  122. void c_console::print_line( const char* text )
  123. {
  124.     print_color( xors( " " ), 0x0C );
  125.     print_color( text, 0x0F );
  126. }
  127.  
  128. void c_console::setup( )
  129. {
  130.     //Allocate a console and make sure I can write to it
  131.     if ( AllocConsole( ) )
  132.     {
  133.         freopen( xors( "CON" ), xors( "w" ), stdout );
  134.     }
  135.  
  136.     SetConsoleTitleA( xors( "" ) );
  137.  
  138.     //disable users being able to select/freeze the application
  139.     DWORD prev_mode;
  140.     GetConsoleMode( GetStdHandle( STD_OUTPUT_HANDLE ), &prev_mode );
  141.     SetConsoleMode( GetStdHandle( STD_OUTPUT_HANDLE ), prev_mode & ~ENABLE_QUICK_EDIT_MODE );
  142.  
  143.     show_cursor( false );
  144.     remove_taskbar( );
  145.     set_transparency( 230 );
  146.     set_font( );
  147.     center( );
  148. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top