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
Anonymous
unregistriert
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 |
// ########################################################################### // Datei: conioex.h // ########################################################################### // Autor: Patrick Ullmann // Erstellt: 27.06.2005 // Änderungen: 27.06.2005 (Patrick) Datei erstellt // ########################################################################### // Beschreibung: Portierung der <conio.h> für den VC++ #if (_MSC_VER > 1000) #pragma once #endif // VC++ Include Guard #if !defined(__conioex_h__) #define __conioex_h__ // I N C L U D E S ########################################################### // Allgemeine conio includieren #include <conio.h> // D E F I N I T I O N E N ################################################### // Nur für Non-Borland Compiler benötigen wir folgende Implementierung #if !defined(__BORLANDC__) // Nur Win32-Konsolen werden unterstützt #if !defined(_WIN32) || (defined(_MSC_VER) && !defined(_CONSOLE)) #error Only Win32-Console-Targets supported #endif // Farben definieren wenn nötig #if !defined(__COLORS) #define __COLORS // Die Farben enum COLORS { // Dunkle Farben BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, // Helle Farben LIGHTGRAY, DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE }; #endif // Cursortypen für _setcursortype() const unsigned long _NOCURSOR = 0; const unsigned long _SOLIDCURSOR = 1; const unsigned long _NORMALCURSOR = 2; // Makro für die Erstellung von Textattributen #if !defined(BUILD_TEXTATTR) #define BUILD_TEXTATTR(f, b) static_cast<int>((((b) & 15) << 4) | ((f) & 15)) #endif // Leert den Inhalt des Bildschirms und setzt den Cursor auf 1x1 void __cdecl clrscr (void); // Leert die Aktuelle Zeile, Cursor wird nicht verschoben void __cdecl clreol (void); // Setzt den Cursor an die Position X und Y void __cdecl gotoxy (int x, int y); // Gibt die aktuelle X-Position des Cursors wieder int __cdecl wherex (void); // Gibt die aktuelle Y-Position des Cursors wieder int __cdecl wherey (void); // Fügt eine neue Zeile hinzu. void __cdecl insline (void); // Löscht eine Zeile void __cdecl delline (void); // Setzt eine Textfarbe void __cdecl textcolor (int color); // Setzt eine Hintergrundfarbe für den Text void __cdecl textbackground (int color); // Setzt ein Attribut für den Text void __cdecl textattr (int attr); // Aktiviert helle Farben void __cdecl highvideo (void); // Deaktiviert helle Farben void __cdecl lowvideo (void); // Verändert den Cursortyp void __cdecl _setcursortype (unsigned long cur_t); #endif #endif |
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
// ########################################################################### // Datei: conioex.cpp // ########################################################################### // Autor: Patrick Ullmann // Erstellt: 27.06.2005 // Änderungen: 27.06.2005 (Patrick) Datei erstellt // ########################################################################### // Beschreibung: Portierung der <conio.h> für den VC++ // I N C L U D E S ########################################################### // Nur für Nun-Borland Compiler gillt diese Implementierung #if !defined(__BORLANDC__) #include <windows.h> #include "conioex.h" // F U N K T I O N E N ####################################################### // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Leert den Inhalt des Bildschirms und setzt den Cursor auf 1x1 // /////////////////////////////////////////////////////////////////////////// void __cdecl clrscr (void) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; HANDLE out; unsigned long written; COORD coord; // Informationen holen if ((out = ::GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return; if (!::GetConsoleScreenBufferInfo(out, &info)) return; // Cursor verschieben coord.X = 0; coord.Y = 0; // Konsole manipulieren ::FillConsoleOutputAttribute (out, info.wAttributes, info.dwSize.X*info.dwSize.Y, coord, &written); ::FillConsoleOutputCharacter (out, TEXT(' '), info.dwSize.X*info.dwSize.Y, coord, &written); // Cursorposition setzen ::SetConsoleCursorPosition (out, coord); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Leert die Aktuelle Zeile, Cursor wird nicht verschoben // /////////////////////////////////////////////////////////////////////////// void __cdecl clreol (void) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; HANDLE out; unsigned long written; // Informationen holen if ((out = ::GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return; if (!::GetConsoleScreenBufferInfo(out, &info)) return; // Konsole manipulieren ::FillConsoleOutputAttribute (out, info.wAttributes, (info.dwSize.X - info.dwCursorPosition.X), info.dwCursorPosition, &written); ::FillConsoleOutputCharacter (out, TEXT(' '), (info.dwSize.X - info.dwCursorPosition.X), info.dwCursorPosition, &written); // Cursor setzen ::SetConsoleCursorPosition (out, info.dwCursorPosition); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Setzt den Cursor an die Position X und Y // /////////////////////////////////////////////////////////////////////////// void __cdecl gotoxy(int x, int y) { // Sicherheitsabfrage if(HIWORD(x) || HIWORD(y)) return; // Hilfsstruktur COORD coord; // Cursor verschieben coord.X = LOWORD(x - 1); coord.Y = LOWORD(y - 1); // Cursor setzen ::SetConsoleCursorPosition (::GetStdHandle(STD_OUTPUT_HANDLE), coord); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Gibt die aktuelle X-Position des Cursors wieder // /////////////////////////////////////////////////////////////////////////// int __cdecl wherex(void) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; // Informationen holen if (!::GetConsoleScreenBufferInfo(::GetStdHandle(STD_OUTPUT_HANDLE),&info)) return 0; // Position zurück geben return (info.dwCursorPosition.X + 1); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Gibt die aktuelle Y-Position des Cursors wieder // /////////////////////////////////////////////////////////////////////////// int __cdecl wherey(void) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; // Informationen holen if (!::GetConsoleScreenBufferInfo(::GetStdHandle(STD_OUTPUT_HANDLE),&info)) return 0; // Position zurück geben return (info.dwCursorPosition.Y + 1); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Fügt eine neue Zeile hinzu. // /////////////////////////////////////////////////////////////////////////// void __cdecl insline(void) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; SMALL_RECT rect; CHAR_INFO char_info; HANDLE out; COORD coord; // Informationen holen if ((out = ::GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return; if (!::GetConsoleScreenBufferInfo(out, &info)) return; // Unicode oder nicht? #if defined(UNICODE) char_info.Char.UnicodeChar = L' '; #else char_info.Char.AsciiChar = ' '; #endif // Attribute sichern char_info.Attributes = info.wAttributes; // Rechteck ausrechnen rect.Left = 0; rect.Top = LOWORD(info.dwCursorPosition.Y); rect.Right = LOWORD(info.dwSize.X - 1); rect.Bottom = LOWORD(info.dwSize.Y - 1); // Position setzen coord.X = 0; coord.Y = LOWORD(info.dwCursorPosition.Y + 1); // Konsole manipulieren ::ScrollConsoleScreenBuffer (out, &rect, NULL, coord, &char_info); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Löscht eine Zeile // /////////////////////////////////////////////////////////////////////////// void __cdecl delline(void) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; SMALL_RECT rect; CHAR_INFO char_info; HANDLE out; COORD coord; // Informationen holen if ((out = ::GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return; if (!::GetConsoleScreenBufferInfo(out, &info)) return; // Unicode oder nicht? #if defined(UNICODE) char_info.Char.UnicodeChar = L' '; #else char_info.Char.AsciiChar = ' '; #endif // Attribute sichern char_info.Attributes = info.wAttributes; // Rechteck ausrechnen rect.Left = 0; rect.Top = LOWORD(info.dwCursorPosition.Y + 1); rect.Right = LOWORD(info.dwSize.X - 1); rect.Bottom = LOWORD(info.dwSize.Y - 1); // Position setzen coord.X = 0; coord.Y = LOWORD(info.dwCursorPosition.Y); // Konsole manipulieren ::ScrollConsoleScreenBuffer (out, &rect, NULL, coord, &char_info); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Setzt eine Textfarbe // /////////////////////////////////////////////////////////////////////////// void __cdecl textcolor (int color) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; HANDLE out; // Informationen holen if ((out = ::GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return; if (!::GetConsoleScreenBufferInfo(out, &info)) return; // Konsole manipulieren ::SetConsoleTextAttribute (out, static_cast<unsigned short>((info.wAttributes & ~0x0F) | static_cast<unsigned short>(color & 0x0F))); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Setzt eine Hintergrundfarbe für den Text // /////////////////////////////////////////////////////////////////////////// void __cdecl textbackground (int color) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; HANDLE out; // Informationen holen if ((out = ::GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return; if (!::GetConsoleScreenBufferInfo(out, &info)) return; // Konsole manipulieren ::SetConsoleTextAttribute (out, static_cast<unsigned short>((info.wAttributes & ~0xF0) | static_cast<unsigned short>((color & 0x0F) << 4))); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Setzt ein Attribut für den Text // /////////////////////////////////////////////////////////////////////////// void __cdecl textattr (int attr) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; HANDLE out; // Informationen holen if ((out = ::GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return; if (!::GetConsoleScreenBufferInfo(out, &info)) return; // Konsole manipulieren ::SetConsoleTextAttribute (out, static_cast<unsigned short>((info.wAttributes & ~0xFF) | static_cast<unsigned short>(attr & 0xFF))); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Aktiviert helle Farben // /////////////////////////////////////////////////////////////////////////// void __cdecl highvideo (void) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; HANDLE out; // Informationen holen if ((out = ::GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return; if (!::GetConsoleScreenBufferInfo(out, &info)) return; // Konsole manipulieren ::SetConsoleTextAttribute (out, static_cast<unsigned short>(info.wAttributes | FOREGROUND_INTENSITY)); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Deaktiviert helle Farben // /////////////////////////////////////////////////////////////////////////// void __cdecl lowvideo (void) { // Hilfsvariablen /- strukturen CONSOLE_SCREEN_BUFFER_INFO info; HANDLE out; // Informationen holen if ((out = ::GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) return; if (!::GetConsoleScreenBufferInfo(out, &info)) return; // Konsole manipulieren ::SetConsoleTextAttribute (out, static_cast<unsigned short>(info.wAttributes | ~FOREGROUND_INTENSITY)); } // /////////////////////////////////////////////////////////////////////////// // PUBLIC // // Verändert den Cursortyp // /////////////////////////////////////////////////////////////////////////// void __cdecl _setcursortype (unsigned long type) { // Hilfsstruktur CONSOLE_CURSOR_INFO info; // Größe verändern if ((type == _NOCURSOR) || (type == _NORMALCURSOR)) info.dwSize = 25; else if (type == _SOLIDCURSOR) info.dwSize = 100; else return; // Cursor sichtbar? info.bVisible = (type == _NOCURSOR) ? false : true; // Konsole manipulieren ::SetConsoleCursorInfo (::GetStdHandle(STD_OUTPUT_HANDLE), &info); } #endif |
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 |
// ########################################################################### // Datei: main.cpp // ########################################################################### // Autor: Patrick Ullmann // Erstellt: 27.06.2005 // Änderungen: 27.06.2005 (Patrick) Datei erstellt // ########################################################################### // Beschreibung: Hauptdatei // I N C L U D E S ########################################################### #include <iostream> #include "conioex.h" // F U N K T I O N E N ####################################################### void header (void) { // Bildschirm löschen clrscr (); // Textfarbe und Hintergrund setzen textcolor (WHITE); textbackground (LIGHTBLUE); // Zeile hinzufügen insline(); // Titelzeile std::cout << "Testprogramm fuer <conioex.h>"; // Version soll ganz rechts stehen gotoxy (79, 1); std::cout << "v1"; // Textfarbe und Hintergrund setzen textcolor (WHITE); textbackground (BLACK); } void footer (void) { // Ganz nach unten gotoxy (1, 25); // Textfarbe und Hintergrund setzen textcolor (WHITE); textbackground (LIGHTBLUE); // Zeile hinzu fügen insline(); // Bissel Blabla std::cout << "Yeah es geht!"; // Textfarbe und Hintergrund setzen textcolor (WHITE); textbackground (BLACK); } int main (void) { // Header malen header (); // Die 1. 16 Zellen der ASCII-Tabelle ausgeben for (unsigned long i=0; i<16; ++i) { gotoxy (5, i+4); std::cout << i << ": " << static_cast<char>(i); } // Text ausgeben gotoxy (20, 4); std::cout << "Ein kleiner Teil einer ASCII-Tabelle"; // Footer malen footer (); gotoxy (25, 20); return 0; } |
Anonymous
unregistriert
Anonymous
unregistriert
Werbeanzeige