Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2.  
  3. #include <math.h>
  4.  
  5. #include<windows.h>
  6.  
  7. #include<tchar.h>
  8.  
  9. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  10.  
  11. TCHAR WinName[] = _T("MainFrame");
  12.  
  13. int APIENTRY WinMain(HINSTANCE This, HINSTANCE Preve, LPSTR cdm, int mode)
  14.  
  15. {
  16.  
  17. HWND hWnd;
  18.  
  19. MSG msg;
  20.  
  21. WNDCLASS wc;
  22.  
  23. wc.hInstance = This;
  24.  
  25. wc.lpszClassName = WinName;
  26.  
  27. wc.lpfnWndProc = WndProc;
  28.  
  29. wc.style = CS_HREDRAW | CS_VREDRAW;
  30.  
  31. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  32.  
  33. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  34.  
  35. wc.lpszMenuName = NULL;
  36.  
  37. wc.cbClsExtra = 0;
  38.  
  39. wc.cbWndExtra = 0;
  40.  
  41. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  42.  
  43. if (!RegisterClass(&wc)) return 0;
  44.  
  45. hWnd = CreateWindow(WinName,
  46.  
  47. _T("Каркас Windows-приложения"),
  48.  
  49. WS_OVERLAPPEDWINDOW,
  50.  
  51. CW_USEDEFAULT,
  52.  
  53. CW_USEDEFAULT,
  54.  
  55. CW_USEDEFAULT,
  56.  
  57. CW_USEDEFAULT,
  58.  
  59. HWND_DESKTOP,
  60.  
  61. NULL,
  62.  
  63. This,
  64.  
  65. NULL);
  66.  
  67. ShowWindow(hWnd, mode);
  68.  
  69. while (GetMessage(&msg, NULL, 0, 0))
  70.  
  71. {
  72.  
  73. TranslateMessage(&msg);
  74.  
  75. DispatchMessage(&msg);
  76.  
  77. }
  78.  
  79. return 0;
  80.  
  81. }
  82.  
  83. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  84.  
  85. {
  86.  
  87. PAINTSTRUCT ps;
  88.  
  89. HDC hdc;
  90.  
  91. static int sx, sy;
  92.  
  93. static HPEN hpen, hpen1;
  94.  
  95. int a, b, x_scr, y_scr, n, z_scr;
  96.  
  97. double x, y, z, x_min, y_min, x_max, y_max, Kx, Ky;
  98.  
  99. switch (message)
  100.  
  101. {
  102.  
  103. case WM_CREATE:
  104.  
  105. hpen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255));
  106.  
  107. break;
  108.  
  109. case WM_SIZE:
  110.  
  111. sx = LOWORD(lParam);
  112.  
  113. sy = HIWORD(lParam);
  114.  
  115. break;
  116.  
  117. case WM_PAINT:
  118.  
  119. hdc = BeginPaint(hWnd, &ps);
  120.  
  121. a = sx / 2;
  122.  
  123. b = sy / 2;
  124.  
  125. x_min = -100;
  126.  
  127. y_min = -100;
  128.  
  129. x_max = 100;
  130.  
  131. y_max = 100;
  132.  
  133. Kx = (sx - 220) / (x_max - x_min);
  134.  
  135. Ky = (sy - 220) / (y_max - y_min);
  136.  
  137. SelectObject(hdc, hpen);
  138.  
  139. MoveToEx(hdc, 0, b, NULL);
  140.  
  141. LineTo(hdc, sx, b);
  142.  
  143. MoveToEx(hdc, a, 0, NULL);
  144.  
  145. LineTo(hdc, a, sy);
  146.  
  147. MoveToEx(hdc, 20, sy - 20, NULL);
  148.  
  149. LineTo(hdc, sx - 20, 20);
  150.  
  151. n = y_max - y_min;
  152.  
  153. for (y = y_min; y < y_max; y += 5)
  154.  
  155. {
  156.  
  157. hpen1 = CreatePen(PS_SOLID, 2, RGB(255, 255 - 255. / n * (y + y_min), 255 - 255. / n * (y + y_min)));
  158.  
  159. SelectObject(hdc, hpen1);
  160.  
  161. z = b - 100 * sin(M_PI / 50 * sqrt(x_min * x_min + y * y));
  162.  
  163. MoveToEx(hdc, x_min * Kx + a + y, (z + y), NULL);
  164.  
  165. for (x = x_min; x < x_max; x += 5)
  166.  
  167. {
  168.  
  169. z = b - 100 * sin(M_PI / 50 * sqrt(x * x + y * y));
  170.  
  171. LineTo(hdc, x * Kx + a + y, z + y);
  172.  
  173. }
  174.  
  175. }
  176.  
  177. EndPaint(hWnd, &ps);
  178.  
  179. break;
  180.  
  181. case WM_DESTROY:
  182.  
  183. DeleteObject(hpen);
  184.  
  185. DeleteObject(hpen1);
  186.  
  187. PostQuitMessage(0);
  188.  
  189. break;
  190.  
  191. default: return DefWindowProc(hWnd, message, wParam, lParam);
  192.  
  193. }
  194.  
  195. return 0;
  196.  
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement