Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2000-10

Re: Reading the screen under win32

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Hankovec
daworm wrote
>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.

<<

I have put it into simple program:
.........
uses Windows, Crt;

....Your code of procedures is here ....

{--- MY MAIN PROGRAM  -----------}
begin
 win_minX:=1;			{coordinates of whole screen}
 win_minY:=1;
 win_maxX:=80;
 win_maxY:=25;

clrscr;
gotoxy(10,10);
writeln('Hi, how are You ?'); {write ,10}
win_push; {save it to buffer}
readln; {wait for ENTER}
gotoxy(10,10);
writeln('Good morning once again.'); {write another ,10} readln; {wait for ENTER}
win_pull; {restore screen - it should be message 1} readln; {wait for ENTER}
end.
{ ------ END OF PROGRAM --------}

Please, where is the bug in my program ? It doesn't work. It writes message 1 ("Hi, how are You ?"), waits for ENTER. Then the program writes over it message 2 ("Good morning once again."). It's right. And then, after pressing ENTER, it should restore the message 1. But nothing happens!

Thanks for help

Martin

Jeff Wormsley
to Martin Hankovec

Hello Martin,

Sorry, I had a bit of Programmer's One problem there...

Replace the push and pull as shown below, and add this at the very beginning of your program

 AllocConsole; {this may not be needed ???}
 hOut := GetStdHandle(STD_OUTPUT_HANDLE); {This is DEFINITATELY needed}

Sorry about the mixup.

Jeff.

{ 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   := 0;
 DestRect.Top    := 0;
 DestRect.Right  := Pred(Win_Width);
 DestRect.Bottom := Pred(Win_Height);
 BuffSize.X      := Win_Width;
 BuffSize.Y      := Win_Height;
 BuffCoord.X     := 0;
 BuffCoord.Y     := 0;
 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   := 0;
 DestRect.Top    := 0;
 DestRect.Right  := Pred(Win_Width);
 DestRect.Bottom := Pred(Win_Height);
 BuffSize.X      := Win_Width;
 BuffSize.Y      := Win_Height;
 BuffCoord.X     := 0;
 BuffCoord.Y     := 0;
 WriteConsoleOutput(hOut, @Win_Save, BuffSize, BuffCoord, DestRect);
End;