home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ETRAP8.ZIP / WINDPTR.INC < prev   
Encoding:
Text File  |  1988-01-18  |  2.4 KB  |  85 lines

  1.  
  2.  
  3.  
  4. Function SaveWindow(XLow: XTCoord; YLow: YTCoord;
  5.                     XHigh: XTCoord; YHigh:YTCoord): WindowPtr;
  6. { Allocate a WindowRec of the precise size needed to save the window, then
  7.   fill it with the text that is in the window XLow..XHigh, YLow..YHigh.
  8.   Return a pointer to this WindowRec. }
  9.  
  10.  
  11. Var
  12.     SW: WindowPtr;
  13.     I: Integer;
  14.     XS: XTCoord;
  15.     YS: YTCoord;
  16.  
  17.   Begin
  18.     XS:=XHigh-XLow+1;
  19.     YS:=YHigh-YLow+1;
  20.     GetMem(SW,2*XS*YS + 4);
  21.     { Allocate 2 bytes for each screen position, + 4 for size and position }
  22.     With SW^ Do
  23.      Begin
  24.       XSize:=XS;
  25.       YSize:=YS;
  26.       XPosn:=XLow;
  27.       YPosn:=YLow;
  28.       For I:=0 To YSize-1 Do
  29.         MoveFromScreen(Mem[ScrSeg:((YPosn+I-1)*80+XPosn-1) Shl 1],
  30.                        Contents[I*XSize],XSize Shl 1);
  31.       { For each line of the window,
  32.           Move XSize*2 bytes (1 for char, 1 for attribute) into the Contents
  33.                array.  Leave no holes in the array. }
  34.      End;
  35.     SaveWindow:=SW;
  36.   End;
  37.  
  38.  
  39. Procedure RestoreWindow(WP: WindowPtr; XPos: XTCoord0; YPos: YTCoord0);
  40. { Given a pointer to a WindowRec, restore the contents of the window.  If
  41.   XPos or YPos is 0, use the XPosn or YPosn that the window was originally
  42.   saved with.  If either is nonzero, use it.  Thus a window can be restored
  43.   exactly with  RestoreWindow(wp,0,0);  or its upper left corner can be
  44.   placed at (2,3) with  RestoreWindow(wp,2,3); }
  45.  
  46.  
  47. Var
  48.     I: Integer;
  49.  
  50.   Begin
  51.     With WP^ Do
  52.      Begin
  53.       If XPos=0 Then XPos:=XPosn;
  54.       If YPos=0 Then YPos:=YPosn;
  55.       For I:=0 To YSize-1 Do
  56.         MoveToScreen(Contents[I*XSize],
  57.                      Mem[ScrSeg:2*((YPos+I-1)*80+XPos-1)],XSize*2);
  58.       { For each line of the window,
  59.           Move XSize*2 bytes (1 for char, 1 for attribute) from the Contents
  60.                array onto the screen. }
  61.      End;
  62.   End;
  63.  
  64.  
  65. Procedure DisposeWindow(Var WP: WindowPtr);
  66. { Dispose of a WindowPtr.  The built in procedure Dispose cannot be used,
  67.   because it will deallocate SizeOf(WindowRec) bytes, even though less may
  68.   have been allocated. }
  69.  
  70.   
  71. Begin
  72.     With WP^ Do FreeMem(WP,2*XSize*YSize+4);
  73.     WP:=Nil;
  74.   End;
  75.  
  76.  
  77. Procedure DRestoreWindow(Var WP: WindowPtr; XPos: XTCoord0; YPos: YTCoord0);
  78. { Restore the contents of a window, then dispose of the saved image }
  79.  
  80.   
  81. Begin
  82.     RestoreWindow(WP, XPos, YPos);
  83.     DisposeWindow(WP);
  84.   End;
  85.