Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FILE: https://www.dropbox.com/s/7ansqfx76mgnper/ConsoleApplication1.zip
- // ConsoleApplication1.cpp: определяет точку входа для консольного приложения.
- #include "stdafx.h"
- #include <windows.h>
- #include <windowsx.h>
- #include <conio.h>
- #include <iostream>
- void drowRectangle(FILE* input, HDC* hdc, RECT* rt, bool painted) {
- int x1, y1, x2, y2;
- fscanf_s(input, "%d %d %d %d", &x1, &y1, &x2, &y2);
- if (x1 > x2 || y1 > y2) {
- printf("Error coordinates.");
- return;
- }
- if (x1 < 0 || y1 < 0 || x2 > rt->right || y2 > rt->bottom) {
- printf("Error: Out of window.");
- return;
- }
- if ((x2 - x1) != (y2 - y1)) {
- printf("Error: This is not KVADRAT.");
- return;
- }
- // Создаем красное перо и говорим, что будем рисовать этим пером
- HPEN pen = SelectPen(*hdc, CreatePen(PS_SOLID, 1, RGB(255, 0, 0)));
- // Создаем черную кисть и говорим что будем рисовать ей фон???
- HBRUSH brush;
- if (painted) brush = SelectBrush(*hdc, CreateSolidBrush(RGB(255, 0, 0)));
- else brush = SelectBrush(*hdc, CreateSolidBrush(RGB(0, 0, 0)));
- Rectangle(*hdc, x1, y1, x2, y2);
- // удаляем красное перо
- DeletePen(pen);
- // удаляем зеленую кисть
- DeleteBrush(brush);
- }
- void main() {
- setlocale(LC_ALL, "Russian");
- // получаем идентификатор окна
- HWND hwnd = GetConsoleWindow();
- // получаем контекст отображения
- HDC hdc = GetDC(hwnd);
- RECT rt;
- // получаем размер окна
- GetClientRect(hwnd, &rt);
- char buf[100];
- printf("Choose programm (1, 2, 3):");
- int answer = _getch();
- FILE* input;
- switch (answer) {
- case '1':
- input = fopen("1.txt", "r");
- drowRectangle(input, &hdc, &rt, false);
- break;
- case '2':
- input = fopen("2.txt", "r");
- drowRectangle(input, &hdc, &rt, true);
- break;
- case '3':
- input = fopen("3.txt", "r");
- drowRectangle(input, &hdc, &rt, true);
- drowRectangle(input, &hdc, &rt, false);
- break;
- default:
- printf("Not found!");
- break;
- }
- _getch();
- // освобождаем контекст отображения
- ReleaseDC(hwnd, hdc);
- return;
- }
Advertisement