{# Một đoạn code của bác TQN}
{$R-}
unit CRT32;
{# freeware}
{# version 1.0.0127}
{# Date 18.01.1997}
{# Author Frank Zimmer}
{# description
Copyright © 1997, Frank Zimmer, [email]100703.1602@compuserve.com[/email]
Fixes Copyright © 2001 Juancarlo Añez, [email]juanco@suigeneris.org[/email]
Version: 1.0.0119
Date: 18.01.1997
an Implementation of Turbo Pascal CRT-Unit for Win32 Console Subsystem
tested with Windows NT 4.0
At Startup you get the Focus to the Console!!!!
( with * are not in the original Crt-Unit):
Procedure and Function:
ClrScr
ClrEol
WhereX
WhereY
GotoXY
InsLine
DelLine
HighVideo
LowVideo
NormVideo
TextBackground
TextColor
Delay // use no processtime
KeyPressed
ReadKey // use no processtime
Sound // with Windows NT your could use the Variables SoundFrequenz, SoundDuration
NoSound
*TextAttribut // Set TextBackground and TextColor at the same time, usefull for Lastmode
*FlushInputBuffer // Flush the Keyboard and all other Events
*ConsoleEnd // output of 'Press any key' and wait for key input when not pipe
*Pipe // True when the output is redirected to a pipe or a file
Variables:
WindMin // the min. WindowRect
WindMax // the max. WindowRect
*ViewMax // the max. ConsoleBuffer start at (1,1);
TextAttr // Actual Attributes only by changing with this Routines
LastMode // Last Attributes only by changing with this Routines
*SoundFrequenz // with Windows NT your could use these Variables
*SoundDuration // how long bells the speaker -1 until ??, default = -1
*HConsoleInput // the Input-handle;
*HConsoleOutput // the Output-handle;
*HConsoleError // the Error-handle;
This Source is freeware, have fun :-)
History
18.01.97 the first implementation
23.01.97 Sound, delay, Codepage inserted and setfocus to the console
24.01.97 Redirected status
}
interface
uses
Windows, Messages;
{$IFDEF WIN32}
const
Intense = FOREGROUND_INTENSITY or BACKGROUND_INTENSITY;
Black = 0;
Blue = FOREGROUND_BLUE or BACKGROUND_BLUE;
Green = FOREGROUND_GREEN or BACKGROUND_GREEN;
Cyan = Blue and Green;
Red = FOREGROUND_RED or BACKGROUND_RED;
Magenta = Blue or Red;
Brown = Green or Red;
LightGray = Blue or Green or Red;
DarkGray = LightGray;
LightBlue = Blue or Intense;
LightGreen = Green or Intense;
LightCyan = Cyan or Intense;
LightRed = Red or Intense;
LightMagenta = Magenta or Intense;
Yellow = Brown or Intense;
White = LightGray or Intense;
BackgroundMask = BACKGROUND_BLUE or BACKGROUND_GREEN or BACKGROUND_RED or BACKGROUND_INTENSITY;
ForegroundMask = FOREGROUND_BLUE or FOREGROUND_GREEN or FOREGROUND_RED or FOREGROUND_INTENSITY;
function WhereX: integer;
function WhereY: integer;
procedure ClrEol;
procedure ClrScr;
procedure InsLine;
procedure DelLine;
procedure GotoXY(const x, y: integer);
procedure HighVideo;
procedure LowVideo;
procedure NormVideo;
procedure TextBackground(const Color: word);
procedure TextColor(const Color: word);
procedure TextAttribut(const Color, Background: word);
procedure Delay(const ms: integer);
function KeyPressed: boolean;
function ReadKey: Char;
procedure Sound;
procedure NoSound;
procedure ConsoleEnd;
procedure FlushInputBuffer;
function Pipe: boolean;
procedure Restore;
procedure SetWindowTo(R: TSmallRect);
procedure More(const Text: string);
var
HConsoleInput: tHandle;
HConsoleOutput: thandle;
HConsoleError: Thandle;
WindMin: tcoord;
WindMax: tcoord;
ViewMax: tcoord;
TextAttr: Word;
LastMode: Word;
SoundFrequenz: Integer;
SoundDuration: Integer;
type
PD3InputRecord = ^TD3InputRecord;
TD3InputRecord = record
EventType: Word;
case Integer of
0: (KeyEvent: TKeyEventRecord);
1: (MouseEvent: TMouseEventRecord);
2: (WindowBufferSizeEvent: TWindowBufferSizeRecord);
3: (MenuEvent: TMenuEventRecord);
4: (FocusEvent: TFocusEventRecord);
end;
{$ENDIF win32}
implementation
{$IFDEF win32}
uses Classes, SysUtils;
var
StartAttr: word;
OldCP: integer;
CrtPipe: Boolean;
German: boolean;
procedure ClrEol;
var
tC: tCoord;
Len, Nw: LongWord;
Cbi: TConsoleScreenBufferInfo;
begin
GetConsoleScreenBufferInfo(HConsoleOutput, cbi);
len := cbi.dwsize.x - cbi.dwcursorposition.x;
tc.x := cbi.dwcursorposition.x;
tc.y := cbi.dwcursorposition.y;
FillConsoleOutputAttribute(HConsoleOutput, textattr, len, tc, nw);
FillConsoleOutputCharacter(HConsoleOutput, #32, len, tc, nw);
end;