Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class c_console
- {
- void show_cursor( bool state );
- void set_transparency( int value );
- void remove_taskbar( );
- void center( );
- void set_size( int16_t width, int16_t height );
- void set_font( );
- void print_logo( );
- public:
- void setup( );
- void print_color( const char* text, uint16_t color );
- void print_line( const char* text );
- };
- extern c_console console;
- #include "console.h"
- #include <windows.h>
- #include <cstdio>
- c_console console;
- static __forceinline void get_screen_size( float& _width, float& _height )
- {
- static float width = float( GetSystemMetrics( SM_CXSCREEN ) );
- static float height = float( GetSystemMetrics( SM_CYSCREEN ) );
- _width = width;
- _height = height;
- }
- void c_console::show_cursor( bool state )
- {
- HANDLE out = GetStdHandle( STD_OUTPUT_HANDLE );
- CONSOLE_CURSOR_INFO cursorInfo;
- GetConsoleCursorInfo( out, &cursorInfo );
- cursorInfo.bVisible = state;
- SetConsoleCursorInfo( out, &cursorInfo );
- }
- void c_console::set_transparency( int value )
- {
- LONG wAttr;
- wAttr = GetWindowLong( GetConsoleWindow( ), GWL_EXSTYLE );
- wAttr |= WS_EX_LAYERED;
- SetWindowLong( GetConsoleWindow( ), GWL_EXSTYLE, wAttr );
- SetLayeredWindowAttributes( GetConsoleWindow( ), 0, value, 2 );
- }
- void c_console::remove_taskbar( )
- {
- DWORD dwStyle = GetWindowLong( GetConsoleWindow( ), GWL_STYLE );
- dwStyle &= ~( WS_CAPTION | WS_SIZEBOX );
- dwStyle |= WS_BORDER;
- SetWindowLong( GetConsoleWindow( ), GWL_STYLE, dwStyle );
- SetWindowPos( GetConsoleWindow( ), NULL, 0, 0, 300, 150, SWP_NOMOVE | SWP_NOZORDER );
- set_size( 43, 12 );
- }
- void c_console::set_size( int16_t width, int16_t height )
- {
- COORD coord = { width, height };
- SMALL_RECT Rect;
- Rect.Top = 0;
- Rect.Left = 0;
- Rect.Bottom = height - 1;
- Rect.Right = width - 1;
- const auto stdHandle = GetStdHandle( STD_OUTPUT_HANDLE );
- SetConsoleScreenBufferSize( stdHandle, coord );
- SetConsoleWindowInfo( stdHandle, TRUE, &Rect );
- }
- void c_console::set_font( )
- {
- CONSOLE_FONT_INFOEX cfi;
- cfi.cbSize = sizeof cfi;
- cfi.nFont = 0;
- cfi.dwFontSize.X = 6;
- cfi.dwFontSize.Y = 12;
- cfi.FontFamily = FF_DONTCARE;
- cfi.FontWeight = 400;
- wcscpy( cfi.FaceName, L"Consolas" );
- SetCurrentConsoleFontEx( GetStdHandle( STD_OUTPUT_HANDLE ), FALSE, &cfi );
- }
- void c_console::center( )
- {
- float width, height;
- get_screen_size( width, height );
- RECT console_rect;
- GetWindowRect( GetConsoleWindow( ), &console_rect );
- int console_w = console_rect.right - console_rect.left;
- int console_h = console_rect.bottom - console_rect.top;
- int console_x = int( width * 0.5f ) - console_w / 2;
- int console_y = int( height * 0.5f ) - console_h / 2;
- SetWindowPos( GetConsoleWindow( ), 0, console_x, console_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
- }
- void c_console::print_color( const char* text, uint16_t color )
- {
- HANDLE console_handle = GetStdHandle( STD_OUTPUT_HANDLE );
- SetConsoleTextAttribute( console_handle, color );
- printf( text );
- }
- void c_console::print_line( const char* text )
- {
- print_color( xors( " " ), 0x0C );
- print_color( text, 0x0F );
- }
- void c_console::setup( )
- {
- //Allocate a console and make sure I can write to it
- if ( AllocConsole( ) )
- {
- freopen( xors( "CON" ), xors( "w" ), stdout );
- }
- SetConsoleTitleA( xors( "" ) );
- //disable users being able to select/freeze the application
- DWORD prev_mode;
- GetConsoleMode( GetStdHandle( STD_OUTPUT_HANDLE ), &prev_mode );
- SetConsoleMode( GetStdHandle( STD_OUTPUT_HANDLE ), prev_mode & ~ENABLE_QUICK_EDIT_MODE );
- show_cursor( false );
- remove_taskbar( );
- set_transparency( 230 );
- set_font( );
- center( );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement