[fpc-pascal]Reading the screen

Jeff Wormsley daworm at cdc.net
Fri Sep 29 15:24:22 CEST 2000


On 09/29/2000 at 11:33 AM Martin Hankovec wrote:

>Can it be done in some way under Win console for WIN32 target?
>Under Linux I can use consolebuf. Can it be used under Win32 ?

This is code snagged from a console mode windowing unit I did last year in Delphi.  It should be failry easy to make work in FPC.  There is a lot of crap you won't need, but it is complete enough that you should be able to pop it into a test program and run it.


Uses Windows;

Var
 DestRect       : TSmallRect;
 Win_MaxX       : Byte;             { Max Window X          }
 Win_MaxY       : Byte;             { Max Window Y          }
 Win_MinX       : Byte;             { Min Window X          }
 Win_MinY       : Byte;             { Min Window Y          }
 Win_Save       : Array[0..24, 0..79] of TCharInfo; { Window Save Buffer   }
 BuffSize       : TCoord;
 BuffCoord      : TCoord;
 hOut           : THandle;

{ Win_Height ---------------------------------------------------------------- }

Function Win_Height: Word;

Begin
 Win_Height := Win_MaxY - Win_MinY + 1                { Return Window Height  }
End;

{ Win_Width ----------------------------------------------------------------- }

Function Win_Width: Word;

Begin
 Win_Width := Win_MaxX - Win_MinX + 1                 { Return Window Width   }
End;

{ Win_Push ------------------------------------------------------------------ }
{ This code grabs a region of the screen and saves it in a buffer }
{ Screen region is defined by the coordinates in Win_MinX, Win_MinY, }
{ Win_MaxX, Win_MaxY. }

Procedure Win_Push;

Var
 Y                : Byte;
Begin
 DestRect.Left   := 1;
 DestRect.Top    := 1;
 DestRect.Right  := Win_Width;
 DestRect.Bottom := Win_Height;
 BuffSize.X      := Win_Width; 
 BuffSize.Y      := Win_Height;
 BuffCoord.X     := 1; 
 BuffCoord.Y     := 1;
 ReadConsoleOutput(hOut, @Win_Save, BuffSize, BuffCoord, DestRect);
End;

{ Win_Pull ------------------------------------------------------------------ }
{ This code puts the buffer back onto the screen }
{ Screen region is defined by the coordinates in Win_MinX, Win_MinY, }
{ Win_MaxX, Win_MaxY. }

Procedure Win_Pull;

Var
 Y                : Byte;

Begin
 DestRect.Left   := 1;
 DestRect.Top    := 1;
 DestRect.Right  := Win_Width;
 DestRect.Bottom := Win_Height;
 BuffSize.X      := Win_Width; 
 BuffSize.Y      := Win_Height;
 BuffCoord.X     := 1; 
 BuffCoord.Y     := 1;
 WriteConsoleOutput(hOut, @Win_Save, BuffSize, BuffCoord, DestRect);
End;






More information about the fpc-pascal mailing list