Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.89 KB | None | 0 0
  1. #pragma comment(linker,"\"/manifestdependency:type='win32' \
  2. name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
  3. processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
  4. #include <math.h>
  5. #include <iostream>
  6. #include <windows.h>
  7. using namespace std;
  8. int Width, Height;
  9. HWND Button1, Edit1, Label1, Label2, Label3,Label4, Edit2, Edit3, Button2, Button3;
  10. int CountNodes=3;
  11. typedef struct Node
  12. {
  13.     double x, y;
  14. }Node;
  15.  
  16. /*xright = x0 + r; //Правый край круга
  17. xleft = x0 - r; //Левый край круга*/
  18. class Graf
  19. {
  20. private:
  21.     double **Matr;
  22.     int n;
  23. public:
  24.     Graf()
  25.     {
  26.         n = 1;
  27.         Matr = new double*[n];
  28.         for (int z = 0; z < n; z++)
  29.             Matr[z] = new double[n];
  30.         Matr[1][1] = 0;
  31.     }
  32.     ~Graf()
  33.     {
  34.         for (int z = 0; z<n; z++)
  35.             delete[] Matr[z];
  36.         delete[] Matr;
  37.     }
  38.     Graf(int i)
  39.     {
  40.         n = i;
  41.         Matr = new double*[n];
  42.         for (int z = 0; z < n; z++)
  43.             Matr[z] = new double[n];
  44.  
  45.         for (int i = 0; i < n; i++)
  46.         {
  47.             for (int j = 0; j < n; j++)
  48.                 Matr[i][j] = 0;
  49.         }
  50.     }
  51.     void SetEl(int i, int j, int el)
  52.     {
  53.         this->Matr[i][j] = el;
  54.     }
  55. };
  56. /*void shimmel(int a[64][64], int num_start, int num_end)
  57. {
  58.  
  59.     int t, r, k, i, j, index = 0, c[64][64], ver[7], leng, x, y;
  60.     char *word;
  61.     for (i = 0; i < 5; i++)
  62.         ver[i] = 0;
  63.  
  64.     for (i = 0; i<64; i++) {
  65.         for (j = 0; j<64; j++) {
  66.             if (a[i][j] == 0 && i != j) { // Если не диагональ
  67.                 a[i][j] = 16000; // Во Все не заполненные пихаем бескоечность
  68.             }
  69.         }
  70.     }
  71.  
  72.     for (i = 0; i<64; i++) {
  73.         for (j = 0; j < 64; j++) {
  74.             c[i][j] = a[i][j]; // Построили матрицу в 1 степени, равную исходной
  75.         }
  76.     }
  77.  
  78.     for (k = 0; k<64; k++) {
  79.         for (i = 0; i<64; i++) {
  80.             for (j = 0; j<64; j++) {
  81.                 r = 16000;
  82.                 for (t = 0; t<64; t++) {
  83.                     if (c[i][t] + a[t][j]<r) { // Реализация формулы
  84.                         r = c[i][t] + a[t][j];
  85.                     }
  86.  
  87.                 }
  88.                 c[i][j] = r;
  89.             }
  90.         }
  91.     }
  92. }*/
  93.  
  94. void SetWindowSize(int _Width, int _Height) {
  95.     Width = _Width;
  96.     Height = _Height;
  97. }
  98.  
  99. int Tx(double X_Log) {
  100.     int X_Window;
  101.     X_Window = (1.0 / 6) * (X_Log + 3) * (Width);
  102.     return X_Window;
  103. }
  104.  
  105. int Ty(double Y_Log) {
  106.     int Y_Window;
  107.     Y_Window = (-1.0 / 6)*(Y_Log - 3)*(Height);
  108.     return Y_Window;
  109. }
  110.  
  111. void Draw(HDC hdc, Node *Array)
  112. {
  113.     for(int i=0; i<CountNodes; i++)
  114.     Ellipse(hdc, Array[i].x-7, Array[i].y - 7, Array[i].x + 7, Array[i].y + 7);
  115.  
  116. }
  117.  
  118. LRESULT CALLBACK WndProc(HWND hwnd, UINT messg, WPARAM wParam, LPARAM lParam)
  119. {
  120.     PAINTSTRUCT ps;
  121.     RECT Rect;
  122.     HDC hdc, hCmpDC;
  123.     HBITMAP hBmp;              
  124.     int xright = Tx(0.0) + Tx(-1.0),x,y; //Правый край круга
  125.     int xleft = Tx(0.0) - Tx(-1.0);
  126.     char buffer1[2], buffer2[2];
  127.     float h;
  128.     Node *ArrayNodes = new Node[CountNodes];
  129.     switch (messg)
  130.     {
  131.     case WM_SIZE:
  132.         GetClientRect(hwnd, &Rect);
  133.         SetWindowSize(Rect.right - Rect.left, Rect.bottom - Rect.top);
  134.         break;
  135.     case WM_ERASEBKGND:
  136.         return 1;
  137.         break;
  138.     case WM_CREATE:
  139.         Label1 = CreateWindowW(L"STATIC", L"Веедите кол-во вершин", WS_CHILD | WS_VISIBLE, 0, 5, 200, 25, hwnd, nullptr, nullptr, nullptr);
  140.         Edit1 = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 0, 30, 50, 25, hwnd, nullptr, nullptr, nullptr);
  141.         Button1 = CreateWindowW(L"Button", L"ок", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 55, 30, 50, 25, hwnd, reinterpret_cast<HMENU>(11), nullptr, nullptr);
  142.  
  143.         Label2 = CreateWindowW(L"STATIC", L"Проведите ребро", WS_CHILD | WS_VISIBLE, 0, 55, 200, 25, hwnd, nullptr, nullptr, nullptr);
  144.         Label3 = CreateWindowW(L"STATIC", L"от", WS_CHILD | WS_VISIBLE, 0, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
  145.         Edit2 = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 25, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
  146.         Label4 = CreateWindowW(L"STATIC", L"до", WS_CHILD | WS_VISIBLE, 50, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
  147.         Edit3 = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 75, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
  148.         Button2 = CreateWindowW(L"Button", L"ок", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 105, 80, 50, 25, hwnd, reinterpret_cast<HMENU>(12), nullptr, nullptr);
  149.  
  150.         Button3 = CreateWindowW(L"Button", L"Вычислить вершину", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 105, 200, 25, hwnd, reinterpret_cast<HMENU>(13), nullptr, nullptr);
  151.         break;
  152.     case WM_COMMAND:
  153.         switch (LOWORD(wParam))
  154.         {
  155.         case 11:
  156.             GetWindowText(Edit1, buffer1, GetWindowTextLength(Edit1));
  157.             CountNodes = atoi(buffer1);
  158.             if (CountNodes % 2 == 0)
  159.             {
  160.                 int i = 0;
  161.                 h = 2 * Tx(-1.0) / (CountNodes / 2 - 1);
  162.                 x = xleft + h;
  163.                 for (i = 0; i < CountNodes / 2; i++)
  164.                 {
  165.                     y = Ty(0.0) + sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0)));  // Разбили верх полукруг на n равных частей
  166.                     ArrayNodes[i].x = x;
  167.                     ArrayNodes[i].y = y;
  168.                     x = x + h;
  169.                 }
  170.                 for (i = 0; i < CountNodes / 2; i++)
  171.                 {
  172.                     y = Ty(0.0) - sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0)));  // Разбили верх полукруг на n равных частей
  173.                     ArrayNodes[i].x = x;
  174.                     ArrayNodes[i].y = y;
  175.                     x = x + h;
  176.                 }
  177.             }
  178.             else
  179.             {
  180.                 int i = 0;
  181.                 h = 2 * Tx(-1.0) / ((CountNodes-1) / 2 - 1);
  182.                 ArrayNodes[0].x = Tx(0.0)- Tx(-1.0);
  183.                 ArrayNodes[0].y = Ty(0.0);
  184.                 x = xleft + h;
  185.                 for (i = 1; i <= CountNodes / 2; i++)
  186.                 {
  187.                     y = Ty(0.0) + sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0)));  // Разбили верх полукруг на n равных частей
  188.                     ArrayNodes[i].x = x;
  189.                     ArrayNodes[i].y = y;
  190.                     x = x + h;
  191.                 }
  192.                 for (i = 1; i <= CountNodes / 2; i++)
  193.                 {
  194.                     y = Ty(0.0) - sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0)));  // Разбили верх полукруг на n равных частей
  195.                     ArrayNodes[i].x = x;
  196.                     ArrayNodes[i].y = y;
  197.                     x = x + h;
  198.                 }
  199.             }
  200.             break;
  201.         case 12:
  202.             break;
  203.         }
  204.  
  205.     case WM_PAINT:
  206.         GetClientRect(hwnd, &Rect);
  207.         hdc = BeginPaint(hwnd, &ps);
  208.  
  209.         hCmpDC = CreateCompatibleDC(hdc);
  210.         hBmp = CreateCompatibleBitmap(hdc, Rect.right - Rect.left,
  211.             Rect.bottom - Rect.top);
  212.         SelectObject(hCmpDC, hBmp);
  213.  
  214.         LOGBRUSH br;
  215.         br.lbStyle = BS_SOLID;
  216.         br.lbColor = 0xfaf9fb;
  217.         HBRUSH brush;
  218.         brush = CreateBrushIndirect(&br);
  219.         FillRect(hCmpDC, &Rect, brush);
  220.         DeleteObject(brush);
  221.         DeleteObject(brush);
  222.  
  223.         Draw(hCmpDC, ArrayNodes);
  224.         SetStretchBltMode(hdc, COLORONCOLOR);
  225.  
  226.         SetStretchBltMode(hdc, COLORONCOLOR);
  227.         BitBlt(hdc, 0, 0, Rect.right - Rect.left, Rect.bottom - Rect.top,
  228.             hCmpDC, 0, 0, SRCCOPY);
  229.  
  230.         DeleteDC(hCmpDC);
  231.         DeleteObject(hBmp);
  232.         hCmpDC = NULL;
  233.  
  234.         EndPaint(hwnd, &ps);
  235.         break;
  236.  
  237.     case WM_DESTROY:
  238.         PostQuitMessage(0);
  239.         break;
  240.  
  241.     default:
  242.         return (DefWindowProc(hwnd, messg, wParam, lParam));
  243.     }
  244.     return (0);
  245. }
  246.  
  247. int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR szCmdLine, int nCmdShow)
  248. {
  249.     MSG msg{};
  250.     HWND hwnd{};
  251.     WNDCLASSEX wc{ sizeof(WNDCLASSEX) };
  252.     wc.cbClsExtra = 0;
  253.     wc.cbWndExtra = 0;
  254.     wc.hbrBackground = reinterpret_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
  255.     wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
  256.     wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
  257.     wc.hIconSm = LoadIcon(nullptr, IDI_APPLICATION);
  258.     wc.hInstance = hInstance;
  259.     wc.lpfnWndProc = WndProc;
  260.  
  261.     wc.lpszClassName = "MyFunc";
  262.     wc.lpszMenuName = nullptr;
  263.     wc.style = CS_VREDRAW | CS_HREDRAW;
  264.     if (!RegisterClassEx(&wc))
  265.         return EXIT_FAILURE;
  266.     hwnd = CreateWindow(wc.lpszClassName, "Функция", WS_OVERLAPPEDWINDOW, 0, 0, 600, 600, nullptr, nullptr, wc.hInstance, nullptr);
  267.     if (hwnd == INVALID_HANDLE_VALUE)
  268.         return EXIT_FAILURE;
  269.     ShowWindow(hwnd, nCmdShow);
  270.     UpdateWindow(hwnd);
  271.     while (GetMessage(&msg, nullptr, 0, 0))
  272.     {
  273.         TranslateMessage(&msg);
  274.         DispatchMessage(&msg);
  275.     }
  276.     return (msg.wParam);
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement