Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker,"\"/manifestdependency:type='win32' \
- name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
- processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
- #include <math.h>
- #include <iostream>
- #include <windows.h>
- using namespace std;
- int Width, Height;
- HWND Button1, Edit1, Label1, Label2, Label3,Label4, Edit2, Edit3, Button2, Button3;
- int CountNodes=0;
- typedef struct Node
- {
- double x, y;
- }Node;
- /*xright = x0 + r; //Правый край круга
- xleft = x0 - r; //Левый край круга*/
- class Graf
- {
- private:
- double **Matr;
- int n;
- public:
- Graf()
- {
- n = 1;
- Matr = new double*[n];
- for (int z = 0; z < n; z++)
- Matr[z] = new double[n];
- Matr[1][1] = 0;
- }
- ~Graf()
- {
- for (int z = 0; z<n; z++)
- delete[] Matr[z];
- delete[] Matr;
- }
- Graf(int i)
- {
- n = i;
- Matr = new double*[n];
- for (int z = 0; z < n; z++)
- Matr[z] = new double[n];
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- Matr[i][j] = 0;
- }
- }
- void SetEl(int i, int j, int el)
- {
- this->Matr[i][j] = el;
- }
- };
- /*void shimmel(int a[64][64], int num_start, int num_end)
- {
- int t, r, k, i, j, index = 0, c[64][64], ver[7], leng, x, y;
- char *word;
- for (i = 0; i < 5; i++)
- ver[i] = 0;
- for (i = 0; i<64; i++) {
- for (j = 0; j<64; j++) {
- if (a[i][j] == 0 && i != j) { // Если не диагональ
- a[i][j] = 16000; // Во Все не заполненные пихаем бескоечность
- }
- }
- }
- for (i = 0; i<64; i++) {
- for (j = 0; j < 64; j++) {
- c[i][j] = a[i][j]; // Построили матрицу в 1 степени, равную исходной
- }
- }
- for (k = 0; k<64; k++) {
- for (i = 0; i<64; i++) {
- for (j = 0; j<64; j++) {
- r = 16000;
- for (t = 0; t<64; t++) {
- if (c[i][t] + a[t][j]<r) { // Реализация формулы
- r = c[i][t] + a[t][j];
- }
- }
- c[i][j] = r;
- }
- }
- }
- }*/
- void SetWindowSize(int _Width, int _Height) {
- Width = _Width;
- Height = _Height;
- }
- int Tx(double X_Log) {
- int X_Window;
- X_Window = (1.0 / 6) * (X_Log + 3) * (Width);
- return X_Window;
- }
- int Ty(double Y_Log) {
- int Y_Window;
- Y_Window = (-1.0 / 6)*(Y_Log - 3)*(Height);
- return Y_Window;
- }
- void Draw(HDC hdc)
- {
- int xright = Tx(0.0) + Tx(-1.0), x, y; //Правый край круга
- int xleft = Tx(0.0) - Tx(-1.0);
- float h;
- if (CountNodes != 0)
- {
- Node *ArrayNodes = new Node[CountNodes];
- if (CountNodes % 2 == 0)
- {
- int i = 0;
- h = (xright- xleft) / ((CountNodes / 2) + 1);
- x = xleft + h;
- for (i; i < CountNodes / 2; i++)
- {
- y = Ty(0.0) + sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0))); // Разбили верх полукруг на n равных частей
- ArrayNodes[i].x = x;
- ArrayNodes[i].y = y;
- x = x + h;
- }
- h = (xright - xleft) / ((CountNodes / 2) + 1);
- x = xleft + h;
- for (i; i < CountNodes; i++)
- {
- y = Ty(0.0) - sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0))); // Разбили верх полукруг на n равных частей
- ArrayNodes[i].x = x;
- ArrayNodes[i].y = y;
- x = x + h;
- }
- }
- else
- {
- int i = 0;
- h = (xright - xleft) / ((CountNodes - 1) / 2 + 1);
- ArrayNodes[0].x = Tx(0.0) - Tx(-1.0);
- ArrayNodes[0].y = Ty(0.0);
- x = xleft + h;
- for (i; i <= CountNodes / 2; i++)
- {
- y = Ty(0.0) + sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0))); // Разбили верх полукруг на n равных частей
- ArrayNodes[i].x = x;
- ArrayNodes[i].y = y;
- x = x + h;
- }
- h = (xright - xleft) / ((CountNodes - 1) / 2 + 1);
- x = xleft + h;
- for (i; i <= CountNodes; i++)
- {
- y = Ty(0.0) - sqrt(Tx(-1.0) * Tx(-1.0) - (x - Tx(0.0)) * (x - Tx(0.0))); // Разбили верх полукруг на n равных частей
- ArrayNodes[i].x = x;
- ArrayNodes[i].y = y;
- x = x + h;
- }
- }
- for (int i = 0; i < CountNodes; i++)
- Ellipse(hdc, ArrayNodes[i].x - 7, ArrayNodes[i].y - 7, ArrayNodes[i].x + 7, ArrayNodes[i].y + 7);
- delete[] ArrayNodes;
- }
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT messg, WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- RECT Rect;
- HDC hdc, hCmpDC;
- HBITMAP hBmp;
- char buffer1[3], buffer2[3];
- switch (messg)
- {
- case WM_SIZE:
- GetClientRect(hwnd, &Rect);
- SetWindowSize(Rect.right - Rect.left, Rect.bottom - Rect.top);
- break;
- case WM_ERASEBKGND:
- return 1;
- break;
- case WM_CREATE:
- Label1 = CreateWindowW(L"STATIC", L"Веедите кол-во вершин", WS_CHILD | WS_VISIBLE, 0, 5, 200, 25, hwnd, nullptr, nullptr, nullptr);
- Edit1 = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 0, 30, 50, 25, hwnd, nullptr, nullptr, nullptr);
- Button1 = CreateWindowW(L"Button", L"ок", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 55, 30, 50, 25, hwnd, reinterpret_cast<HMENU>(11), nullptr, nullptr);
- Label2 = CreateWindowW(L"STATIC", L"Проведите ребро", WS_CHILD | WS_VISIBLE, 0, 55, 200, 25, hwnd, nullptr, nullptr, nullptr);
- Label3 = CreateWindowW(L"STATIC", L"от", WS_CHILD | WS_VISIBLE, 0, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
- Edit2 = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 25, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
- Label4 = CreateWindowW(L"STATIC", L"до", WS_CHILD | WS_VISIBLE, 50, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
- Edit3 = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 75, 80, 25, 25, hwnd, nullptr, nullptr, nullptr);
- Button2 = CreateWindowW(L"Button", L"ок", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 105, 80, 50, 25, hwnd, reinterpret_cast<HMENU>(12), nullptr, nullptr);
- Button3 = CreateWindowW(L"Button", L"Вычислить вершину", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 105, 200, 25, hwnd, reinterpret_cast<HMENU>(13), nullptr, nullptr);
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case 11:
- GetWindowText(Edit1, buffer1, 3);
- CountNodes = atoi(buffer1);
- InvalidateRect(hwnd, 0, true);
- break;
- case 12:
- break;
- }
- case WM_PAINT:
- GetClientRect(hwnd, &Rect);
- hdc = BeginPaint(hwnd, &ps);
- hCmpDC = CreateCompatibleDC(hdc);
- hBmp = CreateCompatibleBitmap(hdc, Rect.right - Rect.left,
- Rect.bottom - Rect.top);
- SelectObject(hCmpDC, hBmp);
- LOGBRUSH br;
- br.lbStyle = BS_SOLID;
- br.lbColor = 0xfaf9fb;
- HBRUSH brush;
- brush = CreateBrushIndirect(&br);
- FillRect(hCmpDC, &Rect, brush);
- DeleteObject(brush);
- DeleteObject(brush);
- if (CountNodes!=0)
- Draw(hCmpDC);
- SetStretchBltMode(hdc, COLORONCOLOR);
- SetStretchBltMode(hdc, COLORONCOLOR);
- BitBlt(hdc, 0, 0, Rect.right - Rect.left, Rect.bottom - Rect.top,
- hCmpDC, 0, 0, SRCCOPY);
- DeleteDC(hCmpDC);
- DeleteObject(hBmp);
- hCmpDC = NULL;
- EndPaint(hwnd, &ps);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return (DefWindowProc(hwnd, messg, wParam, lParam));
- }
- return (0);
- }
- int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR szCmdLine, int nCmdShow)
- {
- MSG msg{};
- HWND hwnd{};
- WNDCLASSEX wc{ sizeof(WNDCLASSEX) };
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hbrBackground = reinterpret_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
- wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
- wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
- wc.hIconSm = LoadIcon(nullptr, IDI_APPLICATION);
- wc.hInstance = hInstance;
- wc.lpfnWndProc = WndProc;
- wc.lpszClassName = "MyFunc";
- wc.lpszMenuName = nullptr;
- wc.style = CS_VREDRAW | CS_HREDRAW;
- if (!RegisterClassEx(&wc))
- return EXIT_FAILURE;
- hwnd = CreateWindow(wc.lpszClassName, "Функция", WS_OVERLAPPEDWINDOW, 0, 0, 600, 600, nullptr, nullptr, wc.hInstance, nullptr);
- if (hwnd == INVALID_HANDLE_VALUE)
- return EXIT_FAILURE;
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while (GetMessage(&msg, nullptr, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (msg.wParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement