Gistrec

ООП ЛАБ1

Sep 18th, 2017
513
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. // FILE: https://www.dropbox.com/s/7ansqfx76mgnper/ConsoleApplication1.zip
  2. // ConsoleApplication1.cpp: определяет точку входа для консольного приложения.
  3.  
  4. #include "stdafx.h"
  5.  
  6.  
  7. #include <windows.h>
  8. #include <windowsx.h>
  9. #include <conio.h>
  10. #include <iostream>
  11.  
  12. void drowRectangle(FILE* input, HDC* hdc, RECT* rt, bool painted) {
  13.     int x1, y1, x2, y2;
  14.     fscanf_s(input, "%d %d %d %d", &x1, &y1, &x2, &y2);
  15.     if (x1 > x2 || y1 > y2) {
  16.         printf("Error coordinates.");
  17.         return;
  18.     }
  19.     if (x1 < 0 || y1 < 0 || x2 > rt->right || y2 > rt->bottom) {
  20.         printf("Error: Out of window.");
  21.         return;
  22.     }
  23.     if ((x2 - x1) != (y2 - y1)) {
  24.         printf("Error: This is not KVADRAT.");
  25.         return;
  26.     }
  27.     // Создаем красное перо и говорим, что будем рисовать этим пером
  28.     HPEN pen = SelectPen(*hdc, CreatePen(PS_SOLID, 1, RGB(255, 0, 0)));
  29.     // Создаем черную кисть и говорим что будем рисовать ей фон???
  30.     HBRUSH brush;
  31.     if (painted) brush = SelectBrush(*hdc, CreateSolidBrush(RGB(255, 0, 0)));
  32.     else brush = SelectBrush(*hdc, CreateSolidBrush(RGB(0, 0, 0)));
  33.     Rectangle(*hdc, x1, y1, x2, y2);
  34.     // удаляем красное перо
  35.     DeletePen(pen);
  36.     // удаляем зеленую кисть
  37.     DeleteBrush(brush);
  38.  
  39. }
  40.  
  41.  
  42. void main() {
  43.     setlocale(LC_ALL, "Russian");
  44.     // получаем идентификатор окна
  45.     HWND hwnd = GetConsoleWindow();
  46.     // получаем контекст отображения
  47.     HDC hdc = GetDC(hwnd);
  48.     RECT rt;
  49.     // получаем размер окна
  50.     GetClientRect(hwnd, &rt);
  51.  
  52.     char buf[100];
  53.     printf("Choose programm (1, 2, 3):");
  54.     int answer = _getch();
  55.     FILE* input;
  56.     switch (answer) {
  57.         case '1':
  58.             input = fopen("1.txt", "r");
  59.             drowRectangle(input, &hdc, &rt, false);
  60.             break;
  61.         case '2':
  62.             input = fopen("2.txt", "r");
  63.             drowRectangle(input, &hdc, &rt, true);
  64.             break;
  65.         case '3':
  66.             input = fopen("3.txt", "r");
  67.             drowRectangle(input, &hdc, &rt, true);
  68.             drowRectangle(input, &hdc, &rt, false);
  69.             break;
  70.         default:
  71.             printf("Not found!");
  72.             break;
  73.     }
  74.     _getch();
  75.     // освобождаем контекст отображения
  76.     ReleaseDC(hwnd, hdc);
  77.     return;
  78. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment