[fpc-pascal]Windows console

Jeff Wormsley daworm at cdc.net
Wed Mar 7 19:48:10 CET 2001


On 03/07/2001 at 1:19 PM Noah silva wrote:

>he he he
>I think you are going to be rather disappointed with the Windows Console
>API.  It seems as if they purposely made it crappy.  Just look atround for
>the better delphi 4 console libraries.  You will see frustrations of
>authors, as well as what options are/aren't available.

It's not -that- bad, but it can be tedious.  I ported some 16-bit BP code to a Delphi console app that used a homebrew windowing library that was based on direct screen writes.  There is a windows console equivalent to direct screen writes that allows you access to the screen buffer.  The important routines are:

  ReadConsoleOutputAttribute
  WriteConsoleOutputAttribute
  ReadConsoleOutputCharacter
  WriteConsoleOutputCharacter
  ReadConsoleOutput
  WriteConsoleOutput
  GetConsoleCursorInfo
  SetConsoleCursorInfo

AFAIK, all of these functions have been implemented in FPC.  I did find a quirk in the Delphi implementation.  The TCharInfo structure wouldn't work correctly for some of the calls, and I had to declare the following type to make it work:

 TFixCharInfo   = Record
                   AsciiChar  : Char;
                   Dummy      : Byte;
                   Attributes : Word;
                  End;

I don't know if that's the case for FPC or not.

Combined with one of the free WinCRT's out there it worked fairly well.  I also had to write a translator for the keyboard scancodes, but that was fairly simple.  

Unfortunately, that code is owned by my employer, so I can't release it.

HTH,
 Jeff.






More information about the fpc-pascal mailing list