Recent

Author Topic: Simple Program; screen storage ...  (Read 2331 times)

graemejc

  • New Member
  • *
  • Posts: 33
Simple Program; screen storage ...
« on: January 21, 2022, 02:16:00 pm »
I'm just writing a few VERY simple programs, indeed when I create a new project, I select "Simple Program." The screen created uses text only. What I am wanting to know is how to save a portion of the screen write over it and then restore it later on. Simple to do in Turbo Pascal in the 1980s when I last programmed regularly.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Simple Program; screen storage ...
« Reply #1 on: January 21, 2022, 03:22:04 pm »
Yeah, those where the days...

In TP you either used WIN unit or read the video memory yourself to read screen content.
FPC does not provide such a functionality, at least not with e.g. crt unit.
There is no WIN unit.

Maybe you can achieve what you want using FreeVison (the fpc alternatve for TP's TurboVision).

Bart

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: Simple Program; screen storage ...
« Reply #2 on: January 23, 2022, 09:45:08 pm »

Using the console, and windows gdi, but since win 10 getpixel and setpixel are very slow(don't know about win 11)
This captures a part of the console into an array of pixels.
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. program console_gdi;
  4. uses
  5. windows;
  6.  
  7. type pixel=object
  8. x,y:integer;
  9. c:COLORREF;
  10. end;
  11.  
  12. type aop=array of pixel;
  13.  
  14. procedure capture(fx,fy,lx,ly:integer;var p:aop);
  15. var
  16. h:hdc;
  17. x,y:integer;
  18. counter :int32=0;
  19. colour:COLORREF;
  20. begin
  21. h:=getdc(GetConsoleWindow());
  22.  for y := fy to ly do
  23.    begin
  24.       for x:=fx to lx do
  25.       begin
  26.       setlength(p,counter+1);
  27.       p[counter].x:=x;
  28.       p[counter].y:=y;
  29.       p[counter].c:=getpixel(h,x,y);
  30.       counter:=counter+1;
  31.   end;
  32. end;
  33. end;
  34.  
  35. procedure rewrite(dx:integer;dy:integer; p:aop);
  36. var
  37. h:hdc;
  38. i:int32;
  39. begin
  40. h:=getdc(GetConsoleWindow());
  41. for i:=0 to high(p) do
  42. begin
  43. setpixel(h,p[i].x+dx,p[i].y+dy, RGB(GetBValue(p[i].c),GetGValue(p[i].c),GetRValue(p[i].c)));
  44. end;
  45.  
  46. end;
  47.  
  48.  
  49. var
  50. s:ansistring='abcdefghijklmnopqrstuvwxyz' + chr(10);
  51. pix:aop;
  52.  
  53. begin
  54. s:=s+s;
  55. s:=s+s;
  56. writeln(s);
  57. writeln('Please wait a few seconds');
  58. capture(0,0,215,100,pix);
  59. rewrite(250,100,pix);
  60. writeln('Done, press return to end ...');
  61. readln;
  62. end.
  63.  

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Simple Program; screen storage ...
« Reply #3 on: January 23, 2022, 10:23:22 pm »
I'm just writing a few VERY simple programs, indeed when I create a new project, I select "Simple Program." The screen created uses text only. What I am wanting to know is how to save a portion of the screen write over it and then restore it later on. Simple to do in Turbo Pascal in the 1980s when I last programmed regularly.
I first want to make sure I understood your request correctly.  You want to save the _text_ that is someplace on the screen, write some new _text_ where the original text was and then restore the original text, is this correct ?

if that is correct then, if you want a solution that is Windows only then, it's fairly easy to do because Windows gives you access to the screen buffer, you can read it, overwrite any portion you want and later restore the original text (which you should have saved somewhere) or, you can create a secondary screen buffer where you write whatever temporary text you want to display.

I don't know if Lazarus has "cushy" functions to do the above but, it can be done with reasonable ease using the Windows API (if you don't mind programming to the API.)

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Elap

  • Jr. Member
  • **
  • Posts: 55
Re: Simple Program; screen storage ...
« Reply #4 on: January 26, 2022, 08:51:41 am »
I had this problem in 2015 and the help from this site was amazing and greatly appreciated.

Search on this site for "screen scrape" and you'll find the thread.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Simple Program; screen storage ...
« Reply #5 on: January 26, 2022, 09:05:20 am »
I'm just writing a few VERY simple programs, indeed when I create a new project, I select "Simple Program." The screen created uses text only. What I am wanting to know is how to save a portion of the screen write over it and then restore it later on. Simple to do in Turbo Pascal in the 1980s when I last programmed regularly.

The way you expect it is simply not the way it is done nowadays (especially on modern systems). You either have console windows where you display text (e.g. on Windows such a console window will be created automatically by Windows if you don't start your application from a command line while on *nix you have to start one yourself) or you have a window in which you place controls or you draw into it to your heart's content (the later is essentially what 440bx suggested albeit using the desktop window instead of a dedicated window).

 

TinyPortal © 2005-2018