Advertisement
ArchonHS

lab3.4

Oct 31st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <vector>
  3. #define _USE_MATH_DEFINES
  4. #include <math.h>
  5. #include <Windows.h>
  6. #include <tchar.h>
  7.  
  8. using namespace std;
  9.  
  10. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  11. TCHAR WinName[] = _T("MainFrame");
  12.  
  13. vector <int> shape;
  14. int APIENTRY WinMain(HINSTANCE This, HINSTANCE Prev, LPSTR cmd, int mode)
  15. {
  16.     HWND hWnd;
  17.     MSG msg;
  18.     WNDCLASS wc;
  19.     wc.hInstance = This;
  20.     wc.lpszClassName = WinName;
  21.     wc.lpfnWndProc = WndProc;
  22.     wc.style = CS_HREDRAW | CS_VREDRAW;
  23.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  24.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  25.     wc.lpszMenuName = NULL;
  26.     wc.cbClsExtra = 0;
  27.     wc.cbWndExtra = 0;
  28.  
  29.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  30.     if (!RegisterClass(&wc)) return 0;
  31.  
  32.     hWnd = CreateWindow(WinName, _T("Каркас Windows-приложения"),
  33.         WS_OVERLAPPEDWINDOW,
  34.         CW_USEDEFAULT,
  35.         CW_USEDEFAULT,
  36.         CW_USEDEFAULT,
  37.         CW_USEDEFAULT,
  38.         HWND_DESKTOP,
  39.         NULL,
  40.         This,
  41.         NULL);
  42.     ShowWindow(hWnd, mode);
  43.  
  44.     while (GetMessage(&msg, NULL, 0, 0))
  45.     {
  46.         TranslateMessage(&msg);
  47.         DispatchMessage(&msg);
  48.     }
  49.     return 0;
  50. }
  51. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  52.     PAINTSTRUCT ps;
  53.     HDC hdc;
  54.     class Vector2D {
  55.     public:
  56.         int step;
  57.         int x1, y1, x2, y2;
  58.         int xaxix1() {
  59.             x1 = 200;
  60.             return x1;
  61.         }
  62.         int xaxix2() {
  63.             x2 = 0;
  64.             return x2;
  65.         }
  66.         int yaxix1() {
  67.             y1 = 100;
  68.             return y1;
  69.         }
  70.         int yaxix2() {
  71.             y2 = -100;
  72.             return y2;
  73.         }
  74.         void setstep() {
  75.             step = 200;
  76.         }
  77.         int getstep() {
  78.             return step;
  79.         }
  80.     };
  81.     Vector2D v;
  82.     Vector2D p;
  83.     int step;
  84.     v.setstep();
  85.     static int sx, sy;
  86.     static HPEN hpen;
  87.     int a, b, x1, y1=p.yaxix1(), x2, y2=p.yaxix2();
  88.     switch (message) {
  89.     case WM_CREATE:
  90.         hpen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255));
  91.         break;
  92.     case WM_SIZE:
  93.         sx = LOWORD(lParam);
  94.         sy = HIWORD(lParam);
  95.         break;
  96.     case WM_PAINT:
  97.         hdc = BeginPaint(hWnd, &ps);
  98.         a = sx / 2;
  99.         b = sy / 2;
  100.         SelectObject(hdc, hpen);
  101.         for (int i = 0; i < 3; i++) {
  102.             x1 = p.xaxix1();
  103.             x2 = p.xaxix2();
  104.             y1 += v.getstep();
  105.             y2 += v.getstep();
  106.             for (int j = 0; j < 3; j++) {
  107.                 x1 += v.getstep();
  108.                 x2 += v.getstep();
  109.                 Ellipse(hdc, x1, y1, x2, y2);
  110.             }
  111.         }
  112.         EndPaint(hWnd, &ps);
  113.         break;
  114.     case WM_DESTROY:
  115.         DeleteObject(hpen);
  116.         PostQuitMessage(0);
  117.         break;
  118.     default: return DefWindowProc(hWnd, message, wParam, lParam);
  119.     }
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement