Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.07 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=0;
  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)
  112. {
  113.     int xright = Tx(0.0) + Tx(-1.0), x, y; //Правый край круга
  114.     int xleft = Tx(0.0) - Tx(-1.0);
  115.     float h;
  116.     if (CountNodes != 0)
  117.     {
  118.         Node *ArrayNodes = new Node[CountNodes];
  119.         if (CountNodes % 2 == 0)
  120.         {
  121.             int i = 0;
  122.             h = (xright- xleft) / ((CountNodes / 2) + 1);
  123.             x = xleft + h;
  124.             for (i; i < CountNodes / 2; i++)
  125.             {
  126.                 y = Ty(0.0) + sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0)));  // Разбили верх полукруг на n равных частей
  127.                 ArrayNodes[i].x = x;
  128.                 ArrayNodes[i].y = y;
  129.                 x = x + h;
  130.             }
  131.             h = (xright - xleft) / ((CountNodes / 2) + 1);
  132.             x = xleft + h;
  133.             for (i; i < CountNodes; i++)
  134.             {
  135.                 y = Ty(0.0) - sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0)));  // Разбили верх полукруг на n равных частей
  136.                 ArrayNodes[i].x = x;
  137.                 ArrayNodes[i].y = y;
  138.                 x = x + h;
  139.             }
  140.         }
  141.         else
  142.         {
  143.             int i = 0;
  144.             h = (xright - xleft) / ((CountNodes - 1) / 2 + 1);
  145.             ArrayNodes[0].x = Tx(0.0) - Tx(-1.0);
  146.             ArrayNodes[0].y = Ty(0.0);
  147.             x = xleft + h;
  148.             for (i; i <= CountNodes / 2; i++)
  149.             {
  150.                 y = Ty(0.0) + sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0)));  // Разбили верх полукруг на n равных частей
  151.                 ArrayNodes[i].x = x;
  152.                 ArrayNodes[i].y = y;
  153.                 x = x + h;
  154.             }
  155.             h = (xright - xleft) / ((CountNodes - 1) / 2 + 1);
  156.             x = xleft + h;
  157.             for (i; i <= CountNodes; i++)
  158.             {
  159.                 y = Ty(0.0) - sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0)));  // Разбили верх полукруг на n равных частей
  160.                 ArrayNodes[i].x = x;
  161.                 ArrayNodes[i].y = y;
  162.                 x = x + h;
  163.             }
  164.         }
  165.         for (int i = 0; i < CountNodes; i++)
  166.             Ellipse(hdc, ArrayNodes[i].x - 7, ArrayNodes[i].y - 7, ArrayNodes[i].x + 7, ArrayNodes[i].y + 7);
  167.         delete[] ArrayNodes;
  168.     }
  169.  
  170. }
  171.  
  172. LRESULT CALLBACK WndProc(HWND hwnd, UINT messg, WPARAM wParam, LPARAM lParam)
  173. {
  174.     PAINTSTRUCT ps;
  175.     RECT Rect;
  176.     HDC hdc, hCmpDC;
  177.     HBITMAP hBmp;              
  178.     char buffer1[3], buffer2[3];
  179.     switch (messg)
  180.     {
  181.     case WM_SIZE:
  182.         GetClientRect(hwnd, &Rect);
  183.         SetWindowSize(Rect.right - Rect.left, Rect.bottom - Rect.top);
  184.         break;
  185.     case WM_ERASEBKGND:
  186.         return 1;
  187.         break;
  188.     case WM_CREATE:
  189.         Label1 = CreateWindowW(L"STATIC", L"Веедите кол-во вершин", WS_CHILD | WS_VISIBLE, 0, 5, 200, 25, hwnd, nullptr, nullptr, nullptr);
  190.         Edit1 = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 0, 30, 50, 25, hwnd, nullptr, nullptr, nullptr);
  191.         Button1 = CreateWindowW(L"Button", L"ок", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 55, 30, 50, 25, hwnd, reinterpret_cast<HMENU>(11), nullptr, nullptr);
  192.  
  193.         Label2 = CreateWindowW(L"STATIC", L"Проведите ребро", WS_CHILD | WS_VISIBLE, 0, 55, 200, 25, hwnd, nullptr, nullptr, nullptr);
  194.         Label3 = CreateWindowW(L"STATIC", L"от", WS_CHILD | WS_VISIBLE, 0, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
  195.         Edit2 = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 25, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
  196.         Label4 = CreateWindowW(L"STATIC", L"до", WS_CHILD | WS_VISIBLE, 50, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
  197.         Edit3 = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 75, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
  198.         Button2 = CreateWindowW(L"Button", L"ок", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 105, 80, 50, 25, hwnd, reinterpret_cast<HMENU>(12), nullptr, nullptr);
  199.  
  200.         Button3 = CreateWindowW(L"Button", L"Вычислить вершину", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 105, 200, 25, hwnd, reinterpret_cast<HMENU>(13), nullptr, nullptr);
  201.         break;
  202.     case WM_COMMAND:
  203.         switch (LOWORD(wParam))
  204.         {
  205.         case 11:
  206.             GetWindowText(Edit1, buffer1, 3);
  207.             CountNodes = atoi(buffer1);
  208.             InvalidateRect(hwnd, 0, true);
  209.             break;
  210.         case 12:
  211.             break;
  212.         }
  213.  
  214.     case WM_PAINT:
  215.         GetClientRect(hwnd, &Rect);
  216.         hdc = BeginPaint(hwnd, &ps);
  217.  
  218.         hCmpDC = CreateCompatibleDC(hdc);
  219.         hBmp = CreateCompatibleBitmap(hdc, Rect.right - Rect.left,
  220.             Rect.bottom - Rect.top);
  221.         SelectObject(hCmpDC, hBmp);
  222.  
  223.         LOGBRUSH br;
  224.         br.lbStyle = BS_SOLID;
  225.         br.lbColor = 0xfaf9fb;
  226.         HBRUSH brush;
  227.         brush = CreateBrushIndirect(&br);
  228.         FillRect(hCmpDC, &Rect, brush);
  229.         DeleteObject(brush);
  230.         DeleteObject(brush);
  231.         if (CountNodes!=0)
  232.         Draw(hCmpDC);
  233.         SetStretchBltMode(hdc, COLORONCOLOR);
  234.  
  235.         SetStretchBltMode(hdc, COLORONCOLOR);
  236.         BitBlt(hdc, 0, 0, Rect.right - Rect.left, Rect.bottom - Rect.top,
  237.             hCmpDC, 0, 0, SRCCOPY);
  238.  
  239.         DeleteDC(hCmpDC);
  240.         DeleteObject(hBmp);
  241.         hCmpDC = NULL;
  242.  
  243.         EndPaint(hwnd, &ps);
  244.         break;
  245.  
  246.     case WM_DESTROY:
  247.         PostQuitMessage(0);
  248.         break;
  249.  
  250.     default:
  251.         return (DefWindowProc(hwnd, messg, wParam, lParam));
  252.     }
  253.     return (0);
  254. }
  255.  
  256. int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR szCmdLine, int nCmdShow)
  257. {
  258.     MSG msg{};
  259.     HWND hwnd{};
  260.     WNDCLASSEX wc{ sizeof(WNDCLASSEX) };
  261.     wc.cbClsExtra = 0;
  262.     wc.cbWndExtra = 0;
  263.     wc.hbrBackground = reinterpret_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
  264.     wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
  265.     wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
  266.     wc.hIconSm = LoadIcon(nullptr, IDI_APPLICATION);
  267.     wc.hInstance = hInstance;
  268.     wc.lpfnWndProc = WndProc;
  269.  
  270.     wc.lpszClassName = "MyFunc";
  271.     wc.lpszMenuName = nullptr;
  272.     wc.style = CS_VREDRAW | CS_HREDRAW;
  273.     if (!RegisterClassEx(&wc))
  274.         return EXIT_FAILURE;
  275.     hwnd = CreateWindow(wc.lpszClassName, "Функция", WS_OVERLAPPEDWINDOW, 0, 0, 600, 600, nullptr, nullptr, wc.hInstance, nullptr);
  276.     if (hwnd == INVALID_HANDLE_VALUE)
  277.         return EXIT_FAILURE;
  278.     ShowWindow(hwnd, nCmdShow);
  279.     UpdateWindow(hwnd);
  280.     while (GetMessage(&msg, nullptr, 0, 0))
  281.     {
  282.         TranslateMessage(&msg);
  283.         DispatchMessage(&msg);
  284.     }
  285.     return (msg.wParam);
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement