home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freesoft 1997 June
/
Freesoft_1997-06_cd.bin
/
nerecenz
/
programmers
/
C32
/
CRT32.INT
next >
Wrap
Text File
|
1997-09-29
|
13KB
|
356 lines
Unit crt32;
{
(C) 1996-97 By ZieglerSoft / Claus & Nina Ziegler
All rights reserved
CRT32 version 1.15
History:
Version 0.90 - First version, only released in limited number
Version 1.00 - First public available version
Oktober 1996 - version
Version 1.10 - Added a lot of stuff and fixed some errors
November 1996 - version
Version 1.15 - Oktober 1997 - version
New in this version:
* Changes: Small changes in varius places
* New Function/procedure/variable: NormVideo
* New Function/procedure/variable: LowVideo
* New Function/procedure/variable: HighVideo
* New Function/procedure/variable: WindMin
* New Function/procedure/variable: WindMax
* New Function/procedure/variable: SingleFrame
* New Function/procedure/variable: DoubleFrame
* New Function/procedure/variable: Sound (Not on NT)
* New Function/procedure/variable: NoSound (Not on NT)
* New Function/procedure/variable: IsNT
* New Function/procedure/variable: ConsoleWindowHandle
* New Function/procedure/variable: MinimizeConsole
* New Function/procedure/variable: MaximizeConsole
* New Function/procedure/variable: NormalizeConsole
Not to be copied without written permisson from ZieglerSoft
Console-mode-helping-unit for 32-bit Delphi programming
Makes the Console-applications work a bit like old Borland CRT-app-
lications (Not a complete drop-in for CRT/WinCRT/Win32CRT, but a help
for developing Console-applications in an easy way)
It has some enhancements too, like SmartInput, ScreenInput and
fast screenwrites
Sugestions and comments must be send to crt32@zieglersoft.dk.
For information about ZieglerSoft look at: http://www.zieglersoft.dk
}
interface
Uses
Messages,
Windows;
Const {Color constants}
Black = 0;
Blue = 1;
Green = 2;
Cyan = 3;
Red = 4;
Magenta = 5;
Brown = 6;
LightGray = 7;
DarkGray = 8;
LightBlue = 9;
LightGreen = 10;
LightCyan = 11;
LightRed = 12;
LightMagenta= 13;
Yellow = 14;
White = 15;
Var
ConsoleInput : tHandle = 0; {The handle of input}
ConsoleOutput : tHandle = 0; {The handle of output}
ConsoleError : tHandle = 0; {The handle of Error}
Type
Colors = Black..White; {Used anywhere we need a color input}
Type
ShiftCodes=(skRightAlt,skLeftAlt,skAlt,skRightCtrl,skLeftCtrl,
skCtrl,skShift,skNum,skScroll,skCaps,skEnhanced);
ShiftKeys = Set of ShiftCodes;
Type
Keyset = Set of Char; {Used to tell what keys we would allow in input
This is used by SmartInput / ScreenInput}
Var
AllKeys : KeySet = [#000..#255]; {Allow all keys in input
used by SmartInput / ScreenInput}
Type
InputJobs = Record {Used by ScreenInput in an array where we have
one of theese records for each line we want to
input}
X : Integer; {Where must the input-string start?}
Y : Integer;
X1: Integer; {Where must the 'Prompt' start?}
Y1: Integer;
L : Integer; {Length of string we want to edit}
Front,Back: Colors; {The color of the input on screen}
Front1,Back1:Colors;{Colors of the 'prompt'}
S : AnsiString; {The string we want to edit}
P : AnsiString; {The 'prompt'}
AK: keySet; {Accepted keys in this input. If not set,
then all keys can be used}
End;
Type
MouseEvent=(MouseButton,MouseMove,MouseDblClick);
{What happend with the mouse?}
Type
MouseFunction=
Procedure(LeftBut,RightBut:Boolean;X,Y:Integer;Event:MouseEvent);
{Assign a procedure of this type to MouseProcedure to use mouse
in ReadKey}
Var
MouseProcedure : MouseFunction = Nil; {Used if mouseinput in Readkey}
Var
MouseInput : Boolean = False;{Mouseevents in Readkey?}
ShiftKeysDown : ShiftKeys =[]; {What shift-keys was down, when last
Readkey was done?}
FillVideoChar : Char = ' '; {Used to fill the screen when ClrScr,
DelLine, InsLine and ClrEOL. remeber
to use the OEM-charset}
Function SmartInput(X,Y:Integer; {Where do we start}
Len:Integer; {How long}
TextCol,BackCol:Colors; {Colors}
Var Value:AnsiString; {In- and output}
OkKeys : KeySet; {What keys are allowed}
TabAdvance:Boolean; {True=tab returns up/down}
AutoAdvance:Boolean {True=returns down when len}
):Integer; {0=Enter,-1=esc,-2=mouse
else key}
{This function reads a string from the keyboard, but will return
the key used to exit the procedure, as in a normal ReadKey where
this is the second char returned (the first was #0) i.e. this is
the extended char i.e. for PgUp, PgDn, Up and down.
If TabAdvance is true, then a tab-char will return the same char
as Down, and Shift+Tab will return the same code as Up.
If Autoadvance is true, then if the char just entered was the last
that could fit into the string, then the function returns the same
code as Down}
Function ScreenInput(Var TheJob:Array of InputJobs):boolean;
{A function, that can be used to input a complete screen-full of
information in one go. You make an array of InputJobs, that is
filled with the wanted information, then calls this function to
get the data read from the screen.
If False, then user exited by pressing ESC, else ENTER}
Procedure MinimizeConsole;
{Minimize the console-window (if posible)}
Procedure MaximizeConsole;
{Maximize the console-window (if posible)}
Procedure NormalizeConsole;
{Normalize the console-window (if posible)}
Procedure CursorOff;
{Turns off the cursor}
Procedure CursorOn;
{Turns on the cursor, in the state it was last time it was turned off}
Procedure BlockCursor;
{Set the cursor to Block-state. If off, then it is set to blockstate
next time the cursor is turned on}
Procedure NormalCursor;
{Set the cursor to normal. If off, then it is set to normal
next time the cursor is turned on}
Procedure FatCursor;
{Set the cursor to Fat-state. If off, then it is set to Fat-state
next time the cursor is turned on}
Procedure FlushInput;
{Empties the inputbuffer for pending keys ect.}
Function SetScreenSize(Rows,Cols:Word):Boolean;
{Set a new size for the screen. If it can't be done, then it returns
false, else it returns true. Not all wanted sizes can be set.
You can't allways make the screen smaller.
If you run in fullscreen-mode, then only sizes that your system
normaly can do will be done. The font used plays a role too}
Procedure SetTitle(Ind:AnsiString);
{Set a title at the console-window}
Procedure FastWrite(X,Y:integer;Front,Back:Colors;S:AnsiString);
{Writes directely to the Console-buffer, and thereby saves time.
X and Y is the place where we start writing.
Front and Back is the color we want to use when writing
S is the string we want to write.}
Procedure FastTextOut(X,Y:Integer;S:AnsiString);
{As FastWrite, but you can't set the colors, so what's there before
will be used}
Function GetScreenText(X,Y,Length:Integer):AnsiString;
{Read the string from the screen, starting from X,Y and continuing
for Length chars}
Function GetChr(X,Y:Integer):Char;
{Read a char from the screen in position X,Y}
Procedure FastColorOut(X,Y:Integer;Front,Back:Colors;Length:Integer);
{As Fastwrite, but this will only fill the colors, whitout changing
the text at the place.
Length is the number of character cells you want to fill}
Procedure FillScreenChar
(X,Y:Integer;front,Back:Colors;Length:Integer;C:Char);
{Fill the screen from X,Y and length chars forward with the char C
in the colors Back,Front.
The Char (C) must be in the OEM-charset}
Procedure SetBreakHandler(Enable:boolean);
{Set the system to handle Ctrl+Break in the same way as ^C
If Enable is false then Ctrl+Break will terminate the application.
If Enable is True then if SetCheckCtrlC is set true the appliaction
terminates, but if SetCheckCtrlC is set false nothing happens}
Procedure SetCheckCtrlC(Enable:Boolean);
{Set the check for ^C (and ^Break if SetBreakHandler is set true)}
Function CheckCtrlC:Boolean;
{Do we check for ^C? (and ^Break if SetBreakHandler is set true)}
Function ReadKey:Char;
{Like the normal ReadKey-function
Returns the same codes as the normal Crt-unit, not Windows VK_X codes}
Function KeyPressed:Boolean;
{As the normal KeyPressed function}
Procedure GotoXY(X,Y:Integer);
{Moves the cursor to a position at X,Y}
Function WhereX:Integer;
{Where is the cursor, X-direction}
Function WhereY:Integer;
{Where is the cursor, Y-direction}
Procedure TextColor(Color:Colors);
{Set the textcolor}
Procedure Inverse;
{Reverses TextColor and TextBackGround}
Procedure TextBackground(Color:Colors);
{Set the Backgroundcolor}
Function GetTextBackGround:Colors;
{Returns with the color (one of the constants) that TextBackGround
is using right now}
Function GetTextColor:Colors;
{Returns with color (one of the constants) that TextColor is
using right now}
Procedure SetTextAttr(Color:Word);
{Set the colors, both Background and Textcolor. Use it with TextAttr
to set a value. Save TextAttr, do some colorchanges, and restore the
colors by setting this to the saved value}
Function GetScreenAttr(X,Y:Integer):Word;
{Returns the complete attribute for the screenposition}
Function GetScreenTextColor(X,Y:Integer):Colors;
{Returns the textcolor, used in screenposition X,Y}
Function GetScreenBackGround(X,Y:integer):Colors;
{Returns then TextBackGround for the position X,Y}
Function TextAttr:Word;
{Get both Background and Textcolor in one word}
Procedure NormVideo;
{Selects normal characters}
Procedure LowVideo;
{Selects low-intensity characters}
Procedure HighVideo;
{Selects high-intensity characters}
Procedure ClrEol;
{Clear from cursor to end of line}
Procedure ClrScr;
{Clear the screen, and return cursor to 0,0}
Procedure InsLine;
{Insert an empty line at the cursor-position}
Procedure DelLine;
{Delete the line where the cursor is, and moves the lines below up}
Function CurrentCols:Integer;
{How many cols are the screen right now?}
Function CurrentRows:Integer;
{How many rows are the screen right now}
Function WindMin:Word;
{Screen coordinates of the current (and only) Window}
Function WindMax:Word;
{Screen coordinates of the current (and only) Window}
Function AnsiOEMstr(Ind:AnsiString):AnsiString;
{A very simple version of Ansi-OEM, needed when writing strings}
Function OEMAnsiStr(Ind:AnsiString):AnsiString;
{A very simple version of OEM-Ansi, needed when reading strings}
Procedure Delay(Msec:Word);
{A delay-function that waits for at least Msec milliseconds}
Procedure SingleFrame(Front,Back:Colors;X1,Y1,X2,Y2:Integer);
{Draws a single-frame from X1,Y1 to X2,Y2 in the colors Front,Back}
Procedure DoubleFrame(Front,Back:Colors;X1,Y1,X2,Y2:Integer);
{Draws a double-frame from X1,Y1 to X2,Y2 in the colors Front,Back}
Function IsNt:Boolean;
{Helper function for testing if we are running on a NT-Box}
Function ConsoleWindowHandle:Hwnd;
{Helper function to get windows-handle for consolewindow}
Procedure Sound(Hz:Word);
{On Win95, this will Start the internal speaker, at Hz Hertz}
Procedure NoSound;
{On Win95, stops the internal speaker again}
{The following don't do anything, they are just here for comaptibility}
Var
CheckSnow : Boolean = true; {Dummy, for compatibility}
CheckEOF : Boolean = False;{Dummy, for compatibility}
DirectVideo : Boolean = False;{Dummy, for compatibility}
implementation