Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include<windows.h>
- #include<tchar.h>
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- TCHAR WinName[] = _T("MainFrame");
- int APIENTRY WinMain(HINSTANCE This, HINSTANCE Preve, LPSTR cdm, int mode)
- {
- HWND hWnd;
- MSG msg;
- WNDCLASS wc;
- wc.hInstance = This;
- wc.lpszClassName = WinName;
- wc.lpfnWndProc = WndProc;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.lpszMenuName = NULL;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- if (!RegisterClass(&wc)) return 0;
- hWnd = CreateWindow(WinName,
- _T("Каркас Windows-приложения"),
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- HWND_DESKTOP,
- NULL,
- This,
- NULL);
- ShowWindow(hWnd, mode);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- static int sx, sy;
- static HPEN hpen, hpen1;
- int a, b, x_scr, y_scr, n, z_scr;
- double x, y, z, x_min, y_min, x_max, y_max, Kx, Ky;
- switch (message)
- {
- case WM_CREATE:
- hpen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255));
- break;
- case WM_SIZE:
- sx = LOWORD(lParam);
- sy = HIWORD(lParam);
- break;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- a = sx / 2;
- b = sy / 2;
- x_min = -100;
- y_min = -100;
- x_max = 100;
- y_max = 100;
- Kx = (sx - 220) / (x_max - x_min);
- Ky = (sy - 220) / (y_max - y_min);
- SelectObject(hdc, hpen);
- MoveToEx(hdc, 0, b, NULL);
- LineTo(hdc, sx, b);
- MoveToEx(hdc, a, 0, NULL);
- LineTo(hdc, a, sy);
- MoveToEx(hdc, 20, sy - 20, NULL);
- LineTo(hdc, sx - 20, 20);
- n = y_max - y_min;
- for (y = y_min; y < y_max; y += 5)
- {
- hpen1 = CreatePen(PS_SOLID, 2, RGB(255, 255 - 255. / n * (y + y_min), 255 - 255. / n * (y + y_min)));
- SelectObject(hdc, hpen1);
- z = b - 100 * sin(M_PI / 50 * sqrt(x_min * x_min + y * y));
- MoveToEx(hdc, x_min * Kx + a + y, (z + y), NULL);
- for (x = x_min; x < x_max; x += 5)
- {
- z = b - 100 * sin(M_PI / 50 * sqrt(x * x + y * y));
- LineTo(hdc, x * Kx + a + y, z + y);
- }
- }
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- DeleteObject(hpen);
- DeleteObject(hpen1);
- PostQuitMessage(0);
- break;
- default: return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement