Advertisement
ArchonHS

lab3.3

Oct 31st, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 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.     static int sx, sy;
  55.     static HPEN hpen1, hpen2;
  56.     int elps(1), sqr(0);
  57.     int a, b, x1(400), y1(400), x2(200), y2(200);
  58.     switch (message) {
  59.     case WM_CREATE:
  60.         hpen1 = CreatePen(PS_SOLID, 2, RGB(0, 0, 255));
  61.         hpen2 = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
  62.         shape.push_back(sqr);
  63.         shape.push_back(elps);
  64.         break;
  65.     case WM_SIZE:
  66.         sx = LOWORD(lParam);
  67.         sy = HIWORD(lParam);
  68.         break;
  69.     case WM_PAINT:
  70.         hdc = BeginPaint(hWnd, &ps);
  71.         a = sx / 2;
  72.         b = sy / 2;
  73.         for (int i = 0; i < shape.size(); i++) {
  74.             if (shape[i] == 0) {
  75.                 SelectObject(hdc, hpen1);
  76.                 Rectangle(hdc, x1, y1, x2, y2);
  77.             }
  78.             else {
  79.                 SelectObject(hdc, hpen2);
  80.                 Ellipse(hdc, x1, y1, x2, y2);
  81.             }
  82.         }
  83.         EndPaint(hWnd, &ps);
  84.         break;
  85.     case WM_DESTROY:
  86.         DeleteObject(hpen1);
  87.         DeleteObject(hpen2);
  88.         PostQuitMessage(0);
  89.         break;
  90.     default: return DefWindowProc(hWnd, message, wParam, lParam);
  91.     }
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement