Advertisement
Guest User

Untitled

a guest
May 21st, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.93 KB | None | 0 0
  1. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\back\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  2.  
  3. #pragma once
  4. #include "framework.h"
  5. #include <math.h>
  6. struct Circle
  7. {
  8.     int x0, y0, r;
  9.     Circle() {};
  10.     Circle(int x, int y, int rr)
  11.     {
  12.         x0 = x;
  13.         y0 = y;
  14.         r = rr;
  15.     }
  16.     void PaintC(HDC hdc, int g1, int g2);
  17. };
  18.  
  19. struct Line
  20. {
  21.     int x1, x2, y1, y2;
  22.     Line() {};
  23.     Line(int x, int xx, int y, int yy)
  24.     {
  25.         x1 = x;
  26.         x2 = xx;
  27.         y1 = y;
  28.         y2 = yy;
  29.     }
  30.     void PaintL(HDC hdc, int g1, int g2);
  31. };
  32.  
  33. class Plate {
  34. private:
  35.     double Len(int x, int xx, int y, int yy);
  36. public:
  37.     Circle c[100];
  38.     Line l[100];
  39.     int nl, nc;
  40.     Plate();
  41.     int AddCircle(int x, int y, int r);
  42.     int AddLine(int x, int xx, int y, int yy);
  43.     int DelCircle(int x, int y, int r);
  44.     int DelLine(int x, int xx, int y, int yy);
  45.     int Usl();
  46.     int Cond1();
  47.     double Cond2();
  48.     void PaintP(HDC hdc, int g1, int g2);
  49. };
  50.  
  51. void Circle::PaintC(HDC hdc, int g1, int g2)
  52. {
  53.     Arc(hdc, x0 - r + g1, -y0 + r + g2, x0 + r + g1, -y0 - r + g2, x0 - r + g1, -y0 + r + g2, x0 - r + g1, -y0 + r + g2);
  54.     HPEN Punktir = CreatePen(PS_DOT, 1, RGB(169, 169, 169));
  55.     SelectObject(hdc, Punktir);
  56.     MoveToEx(hdc, g1, -y0 + g2, NULL);
  57.     LineTo(hdc, x0 + g1, -y0 + g2);
  58.     MoveToEx(hdc, x0 + g1, -y0 + g2, NULL);
  59.     LineTo(hdc, x0 + g1, g2);
  60.     char buf[10];
  61.     _ltoa_s(x0, buf, 10);
  62.     int i = -1;
  63.     while (buf[i + 1] != '\0')
  64.         i++;
  65.     TextOutA(hdc, g1 + x0, g2 + 2, buf, i + 1);
  66.  
  67.     _ltoa_s(y0, buf, 10);
  68.     i = -1;
  69.     while (buf[i + 1] != '\0')
  70.         i++;
  71.     TextOutA(hdc, g1 + 2, g2 - y0, buf, i + 1);
  72.     HPEN Norm = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  73.     SelectObject(hdc, Norm);
  74. }
  75.  
  76. void Line::PaintL(HDC hdc, int g1, int g2)
  77. {
  78.    
  79.     HPEN Punktir = CreatePen(PS_DOT, 1, RGB(169, 169, 169));
  80.     SelectObject(hdc, Punktir);
  81.     MoveToEx(hdc, g1, -y1 + g2, NULL);
  82.     LineTo(hdc, x1 + g1, -y1 + g2);
  83.     MoveToEx(hdc, x1 + g1, -y1 + g2, NULL);
  84.     LineTo(hdc, x1 + g1, g2);
  85.     MoveToEx(hdc, g1, -y2 + g2, NULL);
  86.     LineTo(hdc, x2 + g1, -y2 + g2);
  87.     MoveToEx(hdc, x2 + g1, -y2 + g2, NULL);
  88.     LineTo(hdc, x2 + g1, g2);
  89.     HPEN Norm = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  90.     SelectObject(hdc, Norm);
  91.     MoveToEx(hdc, x1 + g1, -y1 + g2, NULL);
  92.     LineTo(hdc, x2 + g1, -y2 + g2);
  93.     char buf[10];
  94.     _ltoa_s(x1, buf, 10);
  95.     int i = -1;
  96.     while (buf[i + 1] != '\0')
  97.         i++;
  98.     TextOutA(hdc, g1 + x1, g2 + 2, buf, i + 1);
  99.  
  100.     _ltoa_s(x2, buf, 10);
  101.     i = -1;
  102.     while (buf[i + 1] != '\0')
  103.         i++;
  104.     TextOutA(hdc, g1 + x2, g2 + 2, buf, i + 1);
  105.  
  106.     _ltoa_s(y1, buf, 10);
  107.     i = -1;
  108.     while (buf[i + 1] != '\0')
  109.         i++;
  110.     TextOutA(hdc, g1 + 2, g2 - y1, buf, i + 1);
  111.  
  112.     _ltoa_s(y2, buf, 10);
  113.     i = -1;
  114.     while (buf[i + 1] != '\0')
  115.         i++;
  116.     TextOutA(hdc, g1 + 2, g2 - y2, buf, i + 1);
  117. }
  118.  
  119. void Plate::PaintP(HDC hdc, int g1, int g2)
  120. {
  121.     HFONT Font = CreateFont(15, 5, 0, 0, 1, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, L"Arial Bold");
  122.     HFONT Font1 = CreateFont(15, 5, 0, 0, 600, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, L"Arial Bold");
  123.     SelectObject(hdc, Font1);
  124.     char buf[10];
  125.     int j = -1;
  126.     TextOutA(hdc, g1 * 2 + 4, 2, "Окружности", 11);
  127.     TextOutA(hdc, g1 * 2 + 184, 2, "Отрезки", 8);
  128.  
  129.     TextOutA(hdc, g1 * 2 + 4, 32, "x0", 2);
  130.     TextOutA(hdc, g1 * 2 + 64, 32, "y0", 2);
  131.     TextOutA(hdc, g1 * 2 + 124, 32, "r", 2);
  132.  
  133.     TextOutA(hdc, g1 * 2 + 184, 32, "x1", 2);
  134.     TextOutA(hdc, g1 * 2 + 244, 32, "y1", 2);
  135.     TextOutA(hdc, g1 * 2 + 304, 32, "x2", 2);
  136.     TextOutA(hdc, g1 * 2 + 364, 32, "y2", 2);
  137.     SelectObject(hdc, Font);
  138.     for (int i = 0; i < nc; i++)
  139.     {
  140.         c[i].PaintC(hdc, g1, g2);
  141.  
  142.         _ltoa_s(c[i].x0, buf, 10);
  143.         j = -1;
  144.         while (buf[j + 1] != '\0')
  145.             j++;
  146.         TextOutA(hdc, g1 * 2 + 4, i * 20 + 62, buf, j + 1);
  147.  
  148.         _ltoa_s(c[i].y0, buf, 10);
  149.         j = -1;
  150.         while (buf[j + 1] != '\0')
  151.             j++;
  152.         TextOutA(hdc, g1 * 2 + 64, i * 20 + 62, buf, j + 1);
  153.  
  154.         _ltoa_s(c[i].r, buf, 10);
  155.         j = -1;
  156.         while (buf[j + 1] != '\0')
  157.             j++;
  158.         TextOutA(hdc, g1 * 2 + 124, i * 20 + 62, buf, j + 1);
  159.     }
  160.     for (int i = 0; i < nl; i++)
  161.     {
  162.         l[i].PaintL(hdc, g1, g2);
  163.  
  164.         _ltoa_s(l[i].x1, buf, 10);
  165.         j = -1;
  166.         while (buf[j + 1] != '\0')
  167.             j++;
  168.         TextOutA(hdc, g1 * 2 + 184, i * 20 + 62, buf, j + 1);
  169.  
  170.         _ltoa_s(l[i].y1, buf, 10);
  171.         j = -1;
  172.         while (buf[j + 1] != '\0')
  173.             j++;
  174.         TextOutA(hdc, g1 * 2 + 244, i * 20 + 62, buf, j + 1);
  175.  
  176.         _ltoa_s(l[i].x2, buf, 10);
  177.         j = -1;
  178.         while (buf[j + 1] != '\0')
  179.             j++;
  180.         TextOutA(hdc, g1 * 2 + 304, i * 20 + 62, buf, j + 1);
  181.  
  182.         _ltoa_s(l[i].y2, buf, 10);
  183.         j = -1;
  184.         while (buf[j + 1] != '\0')
  185.             j++;
  186.         TextOutA(hdc, g1 * 2 + 364, i * 20 + 62, buf, j + 1);
  187.     }
  188.     SelectObject(hdc, Font);
  189. }
  190.  
  191. Plate::Plate()
  192. {
  193.     nl = 0;
  194.     nc = 0;
  195. }
  196.  
  197. int Plate::AddCircle(int x, int y, int rr)
  198. {
  199.     int fl = 0;
  200.     if (nc < 100)
  201.     {
  202.         int i = 0;
  203.         while (i < nc && !fl)
  204.         {
  205.             if (c[i].x0 == x && c[i].y0 == y && c[i].r == rr)
  206.                 fl = 1;
  207.             i++;
  208.         }
  209.         if (!fl)
  210.         {
  211.             fl = 1;
  212.             nc++;
  213.             c[nc - 1].x0 = x;
  214.             c[nc - 1].y0 = y;
  215.             c[nc - 1].r = rr;
  216.         }
  217.     }
  218.     return fl;
  219. }
  220.  
  221. int Plate::AddLine(int x, int xx, int y, int yy)
  222. {
  223.     int fl = 0;
  224.     if (nl < 100)
  225.     {
  226.         int i = 0;
  227.         while (i < nl && !fl)
  228.         {
  229.             if (l[i].x1 == x && l[i].y1 == y && l[i].x2 == xx && l[i].y2 == yy)
  230.                 fl = 1;
  231.             i++;
  232.         }
  233.         if (!fl)
  234.         {
  235.             fl = 1;
  236.             nl++;
  237.             l[nl - 1].x1 = x;
  238.             l[nl - 1].x2 = xx;
  239.             l[nl - 1].y1 = y;
  240.             l[nl - 1].y2 = yy;
  241.         }
  242.     }
  243.     return fl;
  244. }
  245.  
  246. int Plate::DelCircle(int x, int y, int rr)
  247. {
  248.     int fl = 0;
  249.     if (nc > 0)
  250.     {
  251.         int i = 0;
  252.         while (i < nc && !fl)
  253.         {
  254.             if (c[i].x0 == x && c[i].y0 == y && c[i].r == rr)
  255.                 fl = 1;
  256.             i++;
  257.         }
  258.         if (fl) {
  259.             for (int j = i; j < nc; j++)
  260.                 c[j - 1] = c[j];
  261.             nc--;
  262.         }
  263.     }
  264.     return fl;
  265. }
  266.  
  267. int Plate::DelLine(int x, int xx, int y, int yy)
  268. {
  269.     int fl = 0;
  270.     int i = 0;
  271.     if (nl > 0)
  272.     {
  273.         while (i < nl && !fl)
  274.         {
  275.             if (l[i].x1 == x && l[i].y1 == y && l[i].x2 == xx && l[i].y2 == yy)
  276.                 fl = 1;
  277.             i++;
  278.         }
  279.         if (fl) {
  280.             for (int j = i; j < nl; j++)
  281.                 l[j - 1] = l[j];
  282.             nl--;
  283.         }
  284.     }
  285.     return fl;
  286. }
  287.  
  288. double Plate::Len(int x, int xx, int y, int yy) {
  289.     return sqrt(pow(x - xx, 2) + pow(y - yy, 2));
  290. }
  291.  
  292. int Plate::Usl() {
  293.     int fl = 1;
  294.     for (int i = 0; i < nc && fl; i++) {
  295.         if (c[i].x0 + c[i].r > 0 || c[i].y0 + c[i].r > 0) {
  296.             fl = 0;
  297.         }
  298.     }
  299.     return fl;
  300. }
  301.  
  302. int Plate::Cond1() {
  303.     double len = Len(c[0].x0, 0, c[0].y0, 0);
  304.     int k = 0;
  305.     for (int i = 1; i < nc; i++) {
  306.         if (Len(c[i].x0, 0, c[i].y0, 0) < len) {
  307.             len = Len(c[i].x0, 0, c[i].y0, 0);
  308.             k = i;
  309.         }
  310.     }
  311.     return k;
  312. }
  313.  
  314. double Plate::Cond2() {
  315.     double len = 0;
  316.     for (int i = 0; i < nl; i++) {
  317.         len += Len(l[i].x1, l[i].x2, l[i].y1, l[i].y2);
  318.     }
  319.     return len;
  320. }
  321.  
  322.  
  323.  
  324. /////////////////////////////////////////Основная/////////////////////////////////////////////////
  325.  
  326.  
  327. // WindowsProject1.cpp : Defines the entry point for the application.
  328. //
  329.  
  330. #include "framework.h"
  331. #include "WindowsProject1.h"
  332. #include "back.h"
  333. #include <iostream>
  334. #include <Commdlg.h>
  335.  
  336. #define MAX_LOADSTRING 100
  337.  
  338. Plate P;
  339. int rez = -1;
  340.  
  341. // Global Variables:
  342. HINSTANCE hInst;                                // current instance
  343. WCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  344. WCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  345.  
  346. // Forward declarations of functions included in this code module:
  347. ATOM                MyRegisterClass(HINSTANCE hInstance);
  348. BOOL                InitInstance(HINSTANCE, int);
  349. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  350. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  351. INT_PTR CALLBACK Circ(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  352. INT_PTR CALLBACK Lin(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  353. INT_PTR CALLBACK DelCirc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  354. INT_PTR CALLBACK DelLin(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  355.  
  356. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  357.                      _In_opt_ HINSTANCE hPrevInstance,
  358.                      _In_ LPWSTR    lpCmdLine,
  359.                      _In_ int       nCmdShow)
  360. {
  361.     UNREFERENCED_PARAMETER(hPrevInstance);
  362.     UNREFERENCED_PARAMETER(lpCmdLine);
  363.  
  364.     // TODO: Place code here.
  365.  
  366.     // Initialize global strings
  367.     LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  368.     LoadStringW(hInstance, IDC_WINDOWSPROJECT1, szWindowClass, MAX_LOADSTRING);
  369.     MyRegisterClass(hInstance);
  370.  
  371.     // Perform application initialization:
  372.     if (!InitInstance (hInstance, nCmdShow))
  373.     {
  374.         return FALSE;
  375.     }
  376.  
  377.     HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINDOWSPROJECT1));
  378.  
  379.     MSG msg;
  380.  
  381.     // Main message loop:
  382.     while (GetMessage(&msg, nullptr, 0, 0))
  383.     {
  384.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  385.         {
  386.             TranslateMessage(&msg);
  387.             DispatchMessage(&msg);
  388.         }
  389.     }
  390.  
  391.     return (int) msg.wParam;
  392. }
  393.  
  394.  
  395.  
  396. //
  397. //  FUNCTION: MyRegisterClass()
  398. //
  399. //  PURPOSE: Registers the window class.
  400. //
  401. ATOM MyRegisterClass(HINSTANCE hInstance)
  402. {
  403.     WNDCLASSEXW wcex;
  404.  
  405.     wcex.cbSize = sizeof(WNDCLASSEX);
  406.  
  407.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  408.     wcex.lpfnWndProc    = WndProc;
  409.     wcex.cbClsExtra     = 0;
  410.     wcex.cbWndExtra     = 0;
  411.     wcex.hInstance      = hInstance;
  412.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOWSPROJECT1));
  413.     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  414.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  415.     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_WINDOWSPROJECT1);
  416.     wcex.lpszClassName  = szWindowClass;
  417.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  418.  
  419.     return RegisterClassExW(&wcex);
  420. }
  421.  
  422. //
  423. //   FUNCTION: InitInstance(HINSTANCE, int)
  424. //
  425. //   PURPOSE: Saves instance handle and creates main window
  426. //
  427. //   COMMENTS:
  428. //
  429. //        In this function, we save the instance handle in a global variable and
  430. //        create and display the main program window.
  431. //
  432. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  433. {
  434.    hInst = hInstance; // Store instance handle in our global variable
  435.  
  436.    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  437.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
  438.  
  439.    if (!hWnd)
  440.    {
  441.       return FALSE;
  442.    }
  443.  
  444.    ShowWindow(hWnd, nCmdShow);
  445.    UpdateWindow(hWnd);
  446.  
  447.    return TRUE;
  448. }
  449.  
  450. //
  451. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  452. //
  453. //  PURPOSE: Processes messages for the main window.
  454. //
  455. //  WM_COMMAND  - process the application menu
  456. //  WM_PAINT    - Paint the main window
  457. //  WM_DESTROY  - post a quit message and return
  458. //
  459. //
  460. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  461. {
  462.     switch (message)
  463.     {
  464.     case WM_COMMAND:
  465.     {
  466.         int wmId = LOWORD(wParam);
  467.         // Parse the menu selections:
  468.         switch (wmId)
  469.         {
  470.         case IDM_EXIT:
  471.             DestroyWindow(hWnd);
  472.             break;
  473.         case IDM_LOAD:
  474.         {
  475.             rez = -1;
  476.             wchar_t wfname[300] = L"";
  477.             OPENFILENAME ofn;
  478.             size_t i;
  479.             memset(&ofn, 0, sizeof(ofn));
  480.  
  481.             ofn.lStructSize = sizeof(ofn);
  482.             ofn.hwndOwner = hWnd;
  483.             ofn.lpstrFile = wfname;
  484.             ofn.nMaxFile = 300;
  485.             ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY;
  486.  
  487.             if (GetOpenFileName(&ofn) == 0) {
  488.                 break;
  489.             }
  490.  
  491.             char fname[300];
  492.             wcstombs_s(&i, fname, wfname, 100);
  493.  
  494.             FILE* f;
  495.             fopen_s(&f, fname, "rt");
  496.             if (f == NULL) {
  497.                 break;
  498.             }
  499.  
  500.             char buf[100];
  501.             int x, y, r;
  502.             int x1, y1, x2, y2;
  503.             P.nc = 0;
  504.             P.nl = 0;
  505.             int nc, nl;
  506.             fgets(buf, 100, f);
  507.             sscanf_s(buf, "%d", &nc);
  508.             //P.nc = nc;
  509.             for (int i = 0; i < nc; i++)
  510.             {
  511.                 fgets(buf, 100, f);
  512.                 sscanf_s(buf, "%d%d%d", &x, &y, &r);
  513.                 P.AddCircle(x, y, r);
  514.             }
  515.  
  516.             fgets(buf, 100, f);
  517.             sscanf_s(buf, "%d", &nl);
  518.  
  519.             //P.nl = nl;
  520.             for (int i = 0; i < nl; i++) {
  521.                 fgets(buf, 100, f);
  522.                 sscanf_s(buf, "%d%d%d%d", &x1, &y1, &x2, &y2);
  523.                 P.AddLine(x1, x2, y1, y2);
  524.             }
  525.             fclose(f);
  526.  
  527.             InvalidateRect(hWnd, NULL, TRUE);
  528.  
  529.         }
  530.         break;
  531.         case IDM_ADDCIRCLE:
  532.         {
  533.             rez = -1;
  534.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ADDCIRCLE), hWnd, Circ);
  535.             InvalidateRect(hWnd, NULL, TRUE);
  536.         }
  537.         break;
  538.         case IDM_ADDLINE:
  539.         {
  540.             rez = -1;
  541.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ADDLINE), hWnd, Lin);
  542.             InvalidateRect(hWnd, NULL, TRUE);
  543.         }
  544.         break;
  545.         case IDM_DELETECIRCLE:
  546.         {
  547.             rez = -1;
  548.             DialogBox(hInst, MAKEINTRESOURCE(IDD_DELCIRCLE), hWnd, DelCirc);
  549.             InvalidateRect(hWnd, NULL, TRUE);
  550.         }
  551.         break;
  552.         case IDM_DELETELINE:
  553.         {
  554.             rez = -1;
  555.             DialogBox(hInst, MAKEINTRESOURCE(IDD_DELLINE), hWnd, DelLin);
  556.             InvalidateRect(hWnd, NULL, TRUE);
  557.         }
  558.         break;
  559.         case IDM_SAVE:
  560.         {
  561.             wchar_t wfname[300] = L"";
  562.             OPENFILENAME ofn;
  563.             size_t i;
  564.             memset(&ofn, 0, sizeof(ofn));
  565.  
  566.             ofn.lStructSize = sizeof(ofn);
  567.             ofn.hwndOwner = hWnd;
  568.             ofn.lpstrFile = wfname;
  569.             ofn.nMaxFile = 300;
  570.             ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
  571.  
  572.             if (GetSaveFileName(&ofn) == 0) {
  573.                 break;
  574.             }
  575.  
  576.             char fname[300];
  577.            
  578.             wcstombs_s(&i, fname, wfname, 100);
  579.             strcat_s(fname, ".txt");
  580.             FILE* f;
  581.             fopen_s(&f, fname, "w+");
  582.             if (f == NULL) {
  583.                 break;
  584.             }
  585.  
  586.             fprintf_s(f, "%i", P.nc);
  587.             fprintf_s(f, "\n");
  588.             for (int i = 0; i < P.nc; i++)
  589.             {
  590.                 fprintf_s(f, "%i", P.c[i].x0);
  591.                 fprintf_s(f, " ");
  592.                 fprintf_s(f, "%i", P.c[i].y0);
  593.                 fprintf_s(f, " ");
  594.                 fprintf_s(f, "%i", P.c[i].r);
  595.                 fprintf_s(f, "\n");
  596.             }
  597.             fprintf_s(f, "%i", P.nl);
  598.             fprintf_s(f, "\n");
  599.             for (int i = 0; i < P.nl; i++)
  600.             {
  601.                 fprintf_s(f, "%i", P.l[i].x1);
  602.                 fprintf_s(f, " ");
  603.                 fprintf_s(f, "%i", P.l[i].y1);
  604.                 fprintf_s(f, " ");
  605.                 fprintf_s(f, "%i", P.l[i].x2);
  606.                 fprintf_s(f, " ");
  607.                 fprintf_s(f, "%i", P.l[i].y2);
  608.                 fprintf_s(f, "\n");
  609.             }
  610.             fclose(f);
  611.  
  612.             InvalidateRect(hWnd, NULL, TRUE);
  613.  
  614.         }
  615.         break;
  616.         case IDM_USL:
  617.         {
  618.             char s1[200] = "Задано множество окружностей и отрезков. Если не все окружности лежат в 3 четверти, то найти окружность, центр которой наименее удалён от начала координат, иначе найти сумму длин отрезков.";
  619.             MessageBoxA(hWnd, s1, "Условие:", MB_OK);
  620.         }
  621.         break;
  622.         case IDM_RESH:
  623.         {
  624.             rez = P.Usl();
  625.             if (rez == 1) {
  626.                 double k = P.Cond2();
  627.                 char s1[100] = "Сумма длин отрезков: ";
  628.                 char s2[30];
  629.                 int i = 1;
  630.                 while (k / pow(10, i) > 1)
  631.                     i++;
  632.                 int t = int(k);
  633.                 sprintf_s(s2, "%i", t);
  634.                 strcat_s(s1, s2);
  635.                 strcat_s(s1, ".");
  636.                 t = int((int(round(k* 1000))%int(pow(10,i))));
  637.                 sprintf_s(s2, "%i", t);
  638.                 strcat_s(s1, s2);
  639.                 MessageBoxA(hWnd, s1, "Решение:", MB_OK);
  640.  
  641.             }
  642.             InvalidateRect(hWnd, NULL, TRUE);
  643.         }
  644.         break;
  645.         default:
  646.             return DefWindowProc(hWnd, message, wParam, lParam);
  647.         }
  648.     }
  649.     break;
  650.     case WM_PAINT:
  651.     {
  652.         HPEN Norm = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  653.         HPEN Res = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
  654.         HFONT Font = CreateFont(15, 10, 0, 0, 1, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, L"Arial Bold");
  655.         HBRUSH Brush = CreateSolidBrush(RGB(255, 255, 255));
  656.         PAINTSTRUCT ps;
  657.         HDC hdc = BeginPaint(hWnd, &ps);
  658.         RECT rect;
  659.         SelectObject(hdc, Brush);
  660.         GetClientRect(hWnd, &rect);
  661.         SelectObject(hdc, Norm);
  662.         Rectangle(hdc, 0, 0, rect.right, rect.bottom);
  663.         SelectObject(hdc, Norm);
  664.         P.PaintP(hdc, (rect.right - 400) / 2, rect.bottom / 2);
  665.         SelectObject(hdc, Norm);
  666.         SelectObject(hdc, Font);
  667.         MoveToEx(hdc, rect.right - 400, rect.bottom / 2, NULL);
  668.         LineTo(hdc, 0, rect.bottom / 2);
  669.         MoveToEx(hdc, rect.right - 400, rect.bottom / 2, NULL);
  670.         LineTo(hdc, rect.right - 410, rect.bottom / 2 + 10);
  671.         MoveToEx(hdc, rect.right - 400, rect.bottom / 2, NULL);
  672.         LineTo(hdc, rect.right - 410, rect.bottom / 2 - 10);
  673.         TextOutA(hdc, rect.right - 405, rect.bottom / 2 + 5, "x", 1);
  674.         MoveToEx(hdc, (rect.right - 400) / 2, 0, NULL);
  675.         LineTo(hdc, (rect.right - 400) / 2, rect.bottom);
  676.         MoveToEx(hdc, (rect.right - 400) / 2, 0, NULL);
  677.         LineTo(hdc, (rect.right - 400) / 2 + 10, 10);
  678.         MoveToEx(hdc, (rect.right - 400) / 2, 0, NULL);
  679.         LineTo(hdc, (rect.right - 400) / 2 - 10, 10);
  680.         TextOutA(hdc, (rect.right - 400) / 2 - 15, 2, "y", 1);
  681.         if (rez == 0) {
  682.             SelectObject(hdc, Res);
  683.             P.c[P.Cond1()].PaintC(hdc, (rect.right - 400) / 2, rect.bottom / 2);
  684.             //SelectObject(hdc, Norm);
  685.         }
  686.         // TODO: Add any drawing code that uses hdc here...
  687.         EndPaint(hWnd, &ps);
  688.     }
  689.     break;
  690.     case WM_DESTROY:
  691.         PostQuitMessage(0);
  692.         break;
  693.     default:
  694.         return DefWindowProc(hWnd, message, wParam, lParam);
  695.     }
  696.     return 0;
  697. }
  698.  
  699. // Message handler for about box.
  700. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  701. {
  702.     UNREFERENCED_PARAMETER(lParam);
  703.     switch (message)
  704.     {
  705.     case WM_INITDIALOG:
  706.         return (INT_PTR)TRUE;
  707.  
  708.     case WM_COMMAND:
  709.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  710.         {
  711.             EndDialog(hDlg, LOWORD(wParam));
  712.             return (INT_PTR)TRUE;
  713.         }
  714.         break;
  715.     }
  716.     return (INT_PTR)FALSE;
  717. }
  718.  
  719. INT_PTR CALLBACK Circ(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  720. {
  721.     UNREFERENCED_PARAMETER(lParam);
  722.     switch (message)
  723.     {
  724.     case WM_INITDIALOG:
  725.         return (INT_PTR)TRUE;
  726.  
  727.     case WM_COMMAND:
  728.         if (LOWORD(wParam) == IDOK)
  729.         {
  730.             TCHAR tmp1[5], tmp2[5], tmp3[5];
  731.             GetDlgItemText(hDlg, IDC_x0, tmp1, 5);
  732.             GetDlgItemText(hDlg, IDC_y0, tmp2, 5);
  733.             GetDlgItemText(hDlg, IDC_r, tmp3, 5);
  734.  
  735.             P.AddCircle(_tstof(tmp1), _tstof(tmp2), _tstof(tmp3));
  736.  
  737.             EndDialog(hDlg, LOWORD(wParam));
  738.             return (INT_PTR)TRUE;
  739.         }
  740.         else if (LOWORD(wParam) == IDCANCEL)
  741.         {
  742.             EndDialog(hDlg, LOWORD(wParam));
  743.             return (INT_PTR)TRUE;
  744.         }
  745.             break;
  746.     }
  747.     return (INT_PTR)FALSE;
  748. }
  749.  
  750. INT_PTR CALLBACK Lin(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  751. {
  752.     UNREFERENCED_PARAMETER(lParam);
  753.     switch (message)
  754.     {
  755.     case WM_INITDIALOG:
  756.         return (INT_PTR)TRUE;
  757.  
  758.     case WM_COMMAND:
  759.         if (LOWORD(wParam) == IDOK)
  760.         {
  761.             TCHAR tmp1[5], tmp2[5], tmp3[5], tmp4[5];
  762.             GetDlgItemText(hDlg, IDC_xx1, tmp1, 5);
  763.             GetDlgItemText(hDlg, IDC_yy1, tmp2, 5);
  764.             GetDlgItemText(hDlg, IDC_xx2, tmp3, 5);
  765.             GetDlgItemText(hDlg, IDC_yy2, tmp4, 5);
  766.             P.AddLine(_tstof(tmp1), _tstof(tmp3), _tstof(tmp2), _tstof(tmp4));
  767.             EndDialog(hDlg, LOWORD(wParam));
  768.             return (INT_PTR)TRUE;
  769.         }
  770.         else
  771.             if (LOWORD(wParam) == IDCANCEL)
  772.             {
  773.                 EndDialog(hDlg, LOWORD(wParam));
  774.                 return (INT_PTR)TRUE;
  775.             }
  776.         break;
  777.     }
  778.     return (INT_PTR)FALSE;
  779. }
  780.  
  781. INT_PTR CALLBACK DelCirc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  782. {
  783.     UNREFERENCED_PARAMETER(lParam);
  784.     switch (message)
  785.     {
  786.     case WM_INITDIALOG:
  787.         return (INT_PTR)TRUE;
  788.  
  789.     case WM_COMMAND:
  790.         if (LOWORD(wParam) == IDOK)
  791.         {
  792.             TCHAR tmp1[5], tmp2[5], tmp3[5];
  793.             GetDlgItemText(hDlg, IDC_x0, tmp1, 5);
  794.             GetDlgItemText(hDlg, IDC_y0, tmp2, 5);
  795.             GetDlgItemText(hDlg, IDC_r, tmp3, 5);
  796.  
  797.             P.DelCircle(_tstof(tmp1), _tstof(tmp2), _tstof(tmp3));
  798.  
  799.             EndDialog(hDlg, LOWORD(wParam));
  800.             return (INT_PTR)TRUE;
  801.         }
  802.         else if (LOWORD(wParam) == IDCANCEL)
  803.         {
  804.             EndDialog(hDlg, LOWORD(wParam));
  805.             return (INT_PTR)TRUE;
  806.         }
  807.         break;
  808.     }
  809.     return (INT_PTR)FALSE;
  810. }
  811.  
  812. INT_PTR CALLBACK DelLin(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  813. {
  814.     UNREFERENCED_PARAMETER(lParam);
  815.     switch (message)
  816.     {
  817.     case WM_INITDIALOG:
  818.         return (INT_PTR)TRUE;
  819.  
  820.     case WM_COMMAND:
  821.         if (LOWORD(wParam) == IDOK)
  822.         {
  823.             TCHAR tmp1[5], tmp2[5], tmp3[5], tmp4[5];
  824.             GetDlgItemText(hDlg, IDC_xx1, tmp1, 5);
  825.             GetDlgItemText(hDlg, IDC_yy1, tmp2, 5);
  826.             GetDlgItemText(hDlg, IDC_xx2, tmp3, 5);
  827.             GetDlgItemText(hDlg, IDC_yy2, tmp4, 5);
  828.             P.DelLine(_tstof(tmp1), _tstof(tmp3), _tstof(tmp2), _tstof(tmp4));
  829.             EndDialog(hDlg, LOWORD(wParam));
  830.             return (INT_PTR)TRUE;
  831.         }
  832.         else
  833.             if (LOWORD(wParam) == IDCANCEL)
  834.             {
  835.                 EndDialog(hDlg, LOWORD(wParam));
  836.                 return (INT_PTR)TRUE;
  837.             }
  838.         break;
  839.     }
  840.     return (INT_PTR)FALSE;
  841. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement