WINDOW.PAS 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. program TestWindow;
  2. {$C-}
  3. {
  4. WINDOW DEMONSTRATION PROGRAM Version 1.00A
  5. This program demonstrates the use of windows on the IBM PC
  6. and true compatibles.
  7. PSEUDO CODE
  8. 1. MakeWindow - draws window boxes on the screen
  9. 2. repeat
  10. UpdateWindow 1 - scrolls the window contents up or
  11. down for each window.
  12. UpdateWindow 2
  13. UpdateWindow 3
  14. until a key is pressed
  15. 3. Reset to full screen window
  16. INSTRUCTIONS
  17. 1. Compile this program using the TURBO.COM compiler.
  18. 2. Type any key to exit the program.
  19. }
  20. const Windows = 3;
  21. Wtab : array [1..Windows,1..5] of Integer { X0,Y0,X1,Y1,LineNo }
  22. = ( ( 5, 2, 35, 11, 1),
  23. (45, 2, 75, 11, 1),
  24. ( 5, 15, 75, 23, 1) );
  25. Up = true;
  26. Down = false;
  27. type MaxString = string [255];
  28. var I : Integer;
  29. Ch : char;
  30. procedure Frame(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY: Integer);
  31. var I : Integer;
  32. begin {Frame}
  33. GotoXY(UpperLeftX, UpperLeftY);
  34. Write(chr(218));
  35. for I := (UpperLeftX + 1) to (LowerRightX - 1) do
  36. begin
  37. Write(chr(196));
  38. end;
  39. Write(chr(191));
  40. for I := (UpperLeftY + 1) to (LowerRightY - 1) do
  41. begin
  42. GotoXY(UpperLeftX , I); Write(chr(179));
  43. GotoXY(LowerRightX, I); Write(chr(179));
  44. end;
  45. GotoXY(UpperLeftX, LowerRightY);
  46. Write(chr(192));
  47. for I := (UpperLeftX + 1) to (LowerRightX - 1) do
  48. begin
  49. Write(chr(196));
  50. end;
  51. Write(chr(217));
  52. end; {Frame}
  53. procedure MakeScreen;
  54. begin
  55. ClrScr;
  56. GotoXY(15,25);
  57. Write('TURBO PASCAL Window Demo - Press any key to stop');
  58. for I := 1 to Windows do
  59. begin
  60. Frame(Wtab[I,1] - 1, Wtab[I,2] - 1, Wtab[I,3] + 1, Wtab[I,4] + 1);
  61. end;
  62. end; {MakeScreen}
  63. function RandomStr(Len: Integer): MaxString;
  64. var S: MaxString;
  65. I: integer;
  66. begin
  67. S[0] := Chr(Len);
  68. for Len := 1 to Len do
  69. begin
  70. repeat
  71. I := Random(255)
  72. until not (Chr(I) in[^@,^G,^H,^J,^M]);
  73. S[Len] := Chr(I);
  74. end;
  75. RandomStr := S;
  76. end; {RandomStr}
  77. procedure SelectWindow(Win: Integer);
  78. begin
  79. Window(Wtab[Win,1], Wtab[Win,2], Wtab[Win,3], Wtab[Win,4])
  80. end; {SelectWindow}
  81. procedure UpdateWindow (Win,StringLen: integer;Scroll: boolean);
  82. begin
  83. LowVideo;
  84. SelectWindow(Win);
  85. GotoXY(1,1);
  86. if Scroll then
  87. begin
  88. DelLine;
  89. GotoXY(1, Wtab[Win,4] - Wtab[Win,2] + 1);
  90. end
  91. else
  92. InsLine;
  93. Write('Line ', Wtab[Win,5]:5,' ',chr(219),' ',RandomStr(StringLen));
  94. Wtab[Win,5] := Succ(Wtab[Win,5]);
  95. NormVideo;
  96. end; {UpdateWindow}
  97. procedure DrawWindows;
  98. begin
  99. repeat
  100. UpdateWindow(1,15,Up);
  101. UpdateWindow(2,15,Up);
  102. UpdateWindow(3,55,Down);
  103. until KeyPressed;
  104. Window(1,1,80,25);
  105. GotoXY(1,24);
  106. end; {DrawWindows}
  107. begin { Program body }
  108. MakeScreen;
  109. DrawWindows;
  110. end.
  111.