// -----------------------------------------------------------------------------
// Datei: ceText.pas ----------------------------------------------------------
// Datum: 19.03.2013 ----------------------------------------------------------
// -----------------------------------------------------------------------------
// Textklasse der ChrisEngine. Stellt Funktionen zum Umgang mit Text in --------
// Konsolenanwendungen bereit. --------
// -----------------------------------------------------------------------------
unit ceText;
interface
// I N C L U D E S -------------------------------------------------------------
uses
SysUtils, Windows;
// C E T E X T - K L A S S E ----------------------------------------------
type
TText =
class
private
iStdTextColor: Integer;
public
procedure printf(sText:
String; TextColor: Integer=0);
// formatierte Ausgabe
procedure ClrScr;
// Konsole leeren
function Ansi2OEM(AnsiString:
string):
string;
// ANSI-String zu OEM-String
procedure TText;
// Konstruktor
end;
implementation
procedure TText.TText;
begin
iStdTextColor := 6;
end;
procedure TText.printf(sText:
String; TextColor: Integer=0);
begin
// Ungültige Textfarbe?
if textColor > 14
then MessageBox(0, '
Ungültiger Farbwert für Text in TText.pas!', '
Warnung!', MB_OK);
if textColor = 0
then TextColor := iStdTextColor;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), TextColor);
Writeln(Ansi2OEM(sText));
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), iStdTextColor);
end;
procedure TText.ClrScr;
var tc :tcoord;
nw : DWORD;
cbi : TConsoleScreenBufferInfo;
HConsoleOutput:thandle;
TextAttr : Word;
begin
TextAttr := cbi.wAttributes;
HConsoleOutput := GetStdHandle(STD_OUTPUT_HANDLE);
getConsoleScreenBufferInfo(HConsoleOutput,cbi);
tc.x := 0;
tc.y := 0;
FillConsoleOutputAttribute(HConsoleOutput,textattr,cbi.dwsize.x*cbi.dwsize.y,tc,nw);
FillConsoleOutputCharacter(HConsoleOutput,#32,cbi.dwsize.x*cbi.dwsize.y,tc,nw);
setConsoleCursorPosition(hconsoleoutput,tc);
end;
function TText.Ansi2OEM(AnsiString:
string):
string;
begin
ANSIString := ANSIString + #0;
CharToOEM(PChar(ANSIString), @ANSIString[1]);
Delete(ANSIString, Length(ANSIString), 1);
Result := ANSIString;
end;
end.