Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. program MinApp;
  2. uses OWindows, wintypes, winprocs, strings;
  3.  
  4. type Circle = record
  5. top: double;
  6. left: double;
  7. r:integer;
  8. g:integer;
  9. b:integer;
  10. end;
  11.  
  12. type
  13. TMyApplication = object(TApplication)
  14. procedure InitMainWindow; virtual;
  15. end;
  16.  
  17. PGraphWindow = ^TGraphWindow;
  18. TGraphWindow = object(TWindow)
  19. circles: array[1..1000] of Circle;
  20. i: integer;
  21. k: integer;
  22. n: bool;
  23. procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
  24. procedure WMLButtonDown(var Msg: TMessage); virtual wm_First + wm_LButtonDown;
  25. procedure Render(TheDC: HDC);
  26. constructor Init(AParent: PWindowsObject; ATitle:PChar);
  27. end;
  28.  
  29.  
  30. constructor TGraphWindow.Init;
  31. begin
  32. inherited Init(AParent, ATitle);
  33. i := 0;
  34. k := 0;
  35. n := false;
  36. end;
  37.  
  38.  
  39. procedure TMyApplication.InitMainWindow;
  40. begin
  41. MainWindow := New(PGraphWindow, Init(nil,'Graph'));
  42. end;
  43.  
  44.  
  45. procedure TGraphWindow.WMLButtonDown;
  46. var
  47. NewBrush, OldBrush: HBrush;
  48. TheDC: HDC;
  49. MyRect: TRect;
  50. begin
  51. n := true;
  52. TheDC := GetDC(HWindow);
  53. GetClientRect(HWindow, MyRect);
  54.  
  55. if (Msg.LParamLo < MyRect.right / 2 and Msg.LParamHi < MyRect.bottom / 2) then begin
  56. NewBrush:=CreateSolidBrush(RGB(0,0,255));
  57. OldBrush:=SelectObject(TheDC, NewBrush);
  58. k := k + 1;
  59. Ellipse(TheDC, Msg.LParamLo-15, Msg.LParamHi-15, Msg.LParamLo+15, Msg.LParamHi+15);
  60. circles[k].top := Msg.LParamHi/MyRect.bottom;
  61. circles[k].left := Msg.LParamLo/MyRect.right;
  62. circles[k].r := 0;
  63. circles[k].g := 0;
  64. circles[k].b := 255;
  65. end
  66.  
  67. if (Msg.LParamLo < MyRect.right / 2 and Msg.LParamHi > MyRect.bottom / 2) then begin
  68. NewBrush:=CreateSolidBrush(RGB(255,0,0));
  69. OldBrush:=SelectObject(TheDC, NewBrush);
  70. k := k + 1;
  71. Ellipse(TheDC, Msg.LParamLo-15, Msg.LParamHi-15, Msg.LParamLo+15, Msg.LParamHi+15);
  72. circles[k].top := Msg.LParamHi/MyRect.bottom;
  73. circles[k].left := Msg.LParamLo/MyRect.right;
  74. circles[k].r := 255;
  75. circles[k].g := 0;
  76. circles[k].b := 0;
  77. end
  78.  
  79. if (Msg.LParamLo > MyRect.right / 2 and Msg.LParamHi < MyRect.bottom / 2) then begin
  80. NewBrush:=CreateSolidBrush(RGB(0,255,0));
  81. OldBrush:=SelectObject(TheDC, NewBrush);
  82. k := k + 1;
  83. Ellipse(TheDC, Msg.LParamLo-15, Msg.LParamHi-15, Msg.LParamLo+15, Msg.LParamHi+15);
  84. circles[k].top := Msg.LParamHi/MyRect.bottom;
  85. circles[k].left := Msg.LParamLo/MyRect.right;
  86. circles[k].r := 0;
  87. circles[k].g := 255;
  88. circles[k].b := 0;
  89. end
  90.  
  91. if (Msg.LParamLo > MyRect.right / 2 and Msg.LParamHi > MyRect.bottom / 2) then begin
  92. NewBrush:=CreateSolidBrush(RGB(255,255,255));
  93. OldBrush:=SelectObject(TheDC, NewBrush);
  94. k := k + 1;
  95. Ellipse(TheDC, Msg.LParamLo-15, Msg.LParamHi-15, Msg.LParamLo+15, Msg.LParamHi+15);
  96. circles[k].top := Msg.LParamHi/MyRect.bottom;
  97. circles[k].left := Msg.LParamLo/MyRect.right;
  98. circles[k].r := 255;
  99. circles[k].g := 255;
  100. circles[k].b := 255;
  101. end
  102.  
  103. NewBrush:=SelectObject(TheDC, OldBrush);
  104. DeleteObject(NewBrush);
  105. ReleaseDC(HWindow, TheDC);
  106. end;
  107.  
  108. procedure TGraphWindow.Render;
  109. var l: integer;
  110. NewBrush, OldBrush: HBrush;
  111. MyRect:TRect;
  112. begin
  113. TheDC := GetDC(HWindow);
  114. GetClientRect(HWindow, MyRect);
  115.  
  116. for l := 1 to k do begin
  117. NewBrush:=CreateSolidBrush(RGB(circles[l].r, circles[l].g, circles[l].b));
  118. OldBrush:=SelectObject(TheDC, NewBrush);
  119. Ellipse(TheDC, round(MyRect.right*circles[l].left - 15), round(MyRect.bottom*circles[l].top-15),
  120. round(MyRect.right*circles[l].left + 15), round(MyRect.bottom*circles[l].top+15));
  121. end;
  122. end;
  123.  
  124. procedure TGraphWindow.Paint;
  125. var
  126. MyRect:TRect;
  127. begin
  128. GetClientRect(HWindow, MyRect);
  129. MoveTo(PaintDC, MyRect.left, MyRect.top);
  130. LineTo(PaintDC, MyRect.right, MyRect.bottom);
  131.  
  132. if (n = true) then
  133. Render(PaintDC);
  134.  
  135. end;
  136.  
  137. var
  138. MyApp: TMyApplication;
  139. begin
  140. MyApp.Init('TestApp');
  141. MyApp.Run;
  142. MyApp.Done;
  143.  
  144.  
  145. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement