Jak zmienić kolor tekstu oraz tła na konsoli

nss
var
  TextAttr: Byte;
  LastMode: Word;
{----- Procedura zmieniająca kolor tekstu --------------------------}
procedure TextColor(Color: Byte);
begin
  LastMode := TextAttr;
  TextAttr := (TextAttr and $F0) or (Color and $0F);
  SetConsoleTextAttribute(StdOut, TextAttr);
end;

{----- Procedura zmieniająca kolor tła -------------------------------}
procedure TextBackground(Color: Byte);
begin
  LastMode := TextAttr;
  TextAttr := (TextAttr and $0F) or ((Color shl 4) and $F0);
  SetConsoleTextAttribute(StdOut, TextAttr);
end;

Aby uzyskać uchwyt do konsoli należy zadeklarować globalnie

 StdOut:THandle;

i gdzieś przed wywołaniem funkcji wywołać

 StdOut := GetStdHandle(STD_OUTPUT_HANDLE);

Ewentualnie umieścić wewnątrz funkcji (pamiętając o dodaniu unitu windows w uses).

FAQ

1 komentarz

Nie chce sie kompilowac :/ Podaj wszystkie zmienne oraz to co masz w uses ;)