Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include <windows.h> namespace Console { enum CursorType { SOLID_CURSOR = 100, NORMAL_CURSOR = 25, SMALL_CURSOR = 5 }; void SetCursor(const CursorType cursor, const bool visible = true); void GotoXY(const unsigned short x, const unsigned short y); } /// Aussehen des Cursors setzen void Console::SetCursor(CursorType cursor, bool visible) { ::CONSOLE_CURSOR_INFO cur = { static_cast<unsigned long>(cursor), visible }; ::SetConsoleCursorInfo(::GetStdHandle(STD_OUTPUT_HANDLE), &cur); } /// Zur Koordinate x y gehen, ich glaub die fangen aber bei (1, 1) an void Console::GotoXY(unsigned short x, unsigned short y) { ::COORD pos = { x, y }; ::SetConsoleCursorPosition(::GetStdHandle(STD_OUTPUT_HANDLE), pos); }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
#pragma once #include <windows.h> #include <iostream> namespace Console { inline void gotoxy( unsigned short x, unsigned short y ) { HANDLE hCon = GetStdHandle( STD_OUTPUT_HANDLE ); COORD pos; pos.X=x; pos.Y=y; if ( ! SetConsoleCursorPosition( hCon, pos ) ) { // Platz für individuelle Fehlerbehandlung^^ } } // Farben gibts hier inline void attribute( unsigned short attr = 0 ) { HANDLE hCon = GetStdHandle( STD_OUTPUT_HANDLE ); if ( ! SetConsoleTextAttribute( hCon, attr ) ) { // Platz für individuelle Fehlerbehandlung^^ } } // Cursorgröße, -sichtbarkeit inline void cursor( unsigned long size, bool visible = true ) { HANDLE hCon = GetStdHandle( STD_OUTPUT_HANDLE ); CONSOLE_CURSOR_INFO info; if ( size < 1 ) { size = 1; visible = false; } info.bVisible = visible; info.dwSize = size; if ( ! SetConsoleCursorInfo( hCon, &info ) ) { // Platz für individuelle Fehlerbehandlung^^ } } // Hier wird das Konsolenfenster bearbeitet inline void displaysize( unsigned short _X, unsigned short _Y ) { HANDLE hCon = GetStdHandle( STD_OUTPUT_HANDLE ); CONSOLE_SCREEN_BUFFER_INFO info; SMALL_RECT change = {0}; if ( ! GetConsoleScreenBufferInfo( hCon, &info ) ) { // Platz für individuelle Fehlerbehandlung^^ } if ( _X >= info.dwMaximumWindowSize.X ) change.Right = info.dwMaximumWindowSize.X-1; else change.Right = _X; if ( _Y >= info.dwMaximumWindowSize.Y ) change.Bottom = info.dwMaximumWindowSize.Y-1; else change.Bottom = _Y; if ( ! SetConsoleWindowInfo( hCon, true, &change ) ) { // Platz für individuelle Fehlerbehandlung^^ } } // Jetzt ist der Ausgabebuffer dran inline void buffersize( unsigned short _X, unsigned short _Y ) { HANDLE hCon = GetStdHandle( STD_OUTPUT_HANDLE ); COORD newSize; newSize.X = _X; newSize.Y = _Y; if ( ! SetConsoleScreenBufferSize( hCon, newSize ) ) { // Platz für individuelle Fehlerbehandlung^^ } } // Selbsterklärend inline void title( const wchar_t* title ) { if ( ! SetConsoleTitleW( title ) ) { // Platz für individuelle Fehlerbehandlung^^ } } // So oft neue Zeile, bis der Buffer wieder schön sauber ist //FillConsoleOutputCharacter(...) macht leider blöde Effekte bei Hintergrundfarben inline void cls(void) { HANDLE hCon = GetStdHandle( STD_OUTPUT_HANDLE ); CONSOLE_SCREEN_BUFFER_INFO info; if ( ! GetConsoleScreenBufferInfo( hCon, &info ) ) { // Platz für individuelle Fehlerbehandlung^^ } wchar_t* fill = new wchar_t[info.dwSize.Y+1]; for (int i=0; i<=info.dwSize.Y; ++i) fill[i] = L'\n'; fill[info.dwSize.Y] = 0; gotoxy(0, info.dwSize.Y-1); std::wcout << fill; gotoxy(0, 0); delete [] fill; } } |
Werbeanzeige