Xom9ik

Lab_7/16 var (IIl semester)

Nov 11th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. //Lab_7.cpp
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <windows.h>
  5. using namespace std;
  6.  
  7. class Rect
  8. {
  9. public:
  10.     virtual void print()
  11.     {
  12.         cout << "\nI'm a rectangle\n\n\n\n";
  13.         POINT op;
  14.         HWND hWnd = GetConsoleWindow(); //Получаем дескриптор окна консоли
  15.         HDC hDC = GetDC(hWnd); //Получаем контекст устройства по полученному дескриптору
  16.         Rectangle(hDC, 150, 40, 310, 80);
  17.         ReleaseDC(hWnd, hDC);
  18.     }
  19. };
  20. class Button : public Rect
  21. {
  22. public:
  23.     void print()
  24.     {
  25.         cout << "\nI'm a button\n\n\n\n";
  26.         POINT op;
  27.         HWND hWnd = GetConsoleWindow();
  28.         HDC hDC = GetDC(hWnd);
  29.         SelectObject(hDC, GetStockObject(WHITE_PEN));
  30.         MoveToEx(hDC, 150, 100, &op); LineTo(hDC, 310, 100);
  31.         MoveToEx(hDC, 310, 100, &op); LineTo(hDC, 310, 140);
  32.         MoveToEx(hDC, 310, 140, &op); LineTo(hDC, 150, 140);
  33.         MoveToEx(hDC, 150, 140, &op); LineTo(hDC, 150, 100);
  34.         //
  35.         MoveToEx(hDC, 145, 95, &op); LineTo(hDC, 150, 100);
  36.         MoveToEx(hDC, 315, 95, &op); LineTo(hDC, 310, 100);
  37.         MoveToEx(hDC, 315, 145, &op); LineTo(hDC, 310, 140);
  38.         MoveToEx(hDC, 145, 145, &op); LineTo(hDC, 150, 140);
  39.         //
  40.         MoveToEx(hDC, 145, 95, &op); LineTo(hDC, 315, 95);
  41.         MoveToEx(hDC, 315, 95, &op); LineTo(hDC, 315, 145);
  42.         MoveToEx(hDC, 315, 145, &op); LineTo(hDC, 145, 145);
  43.         MoveToEx(hDC, 145, 145, &op); LineTo(hDC, 145, 95);
  44.         ReleaseDC(hWnd, hDC);
  45.     }
  46. };
  47. class FloatButton : public Rect
  48. {
  49. public:
  50.     void print()
  51.     {
  52.         cout << "\nI'm a floatButton\n\n\n\n\n";
  53.         POINT op;
  54.         HWND hWnd = GetConsoleWindow();
  55.         HDC hDC = GetDC(hWnd);
  56.         Ellipse(hDC, 150, 200, 250, 300);
  57.         Ellipse(hDC, 175, 225, 225, 275);
  58.         Ellipse(hDC, 185, 235, 215, 265);
  59.     }
  60. };
  61.  
  62. int main()
  63. {
  64.     Rect rect, *rect_p = &rect;
  65.     Button button, *button_p = &button;
  66.     Rect *R1 = &button;
  67.     FloatButton Fbutton, *Fbutton_p = &Fbutton;
  68.     Rect *R2 = &Fbutton;
  69.     rect_p->print(); // rect
  70.     button_p->print(); // button
  71.     R1->print(); // button
  72.     R2->print(); //floatButton
  73.     cout << endl;
  74.     system("pause");
  75. }
Advertisement
Add Comment
Please, Sign In to add comment