vesso8

kg-zad1

Oct 15th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.34 KB | None | 0 0
  1. // CG-Veso.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "CG-Veso.h"
  6.  
  7. #define MAX_LOADSTRING 100
  8.  
  9. // Global Variables:
  10. HINSTANCE hInst;                                // current instance
  11. TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  12. TCHAR szWindowClass[MAX_LOADSTRING];
  13. VOID DRAW_TEST(HDC hdc, int ak, int xend, int yend);
  14. int ak = 0;
  15. // the main window class name
  16. // Forward declarations of functions included in this code module:
  17.  
  18.  
  19. ATOM                MyRegisterClass(HINSTANCE hInstance);
  20. BOOL                InitInstance(HINSTANCE, int);
  21. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  22. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  23.  
  24. int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
  25.                      _In_opt_ HINSTANCE hPrevInstance,
  26.                      _In_ LPTSTR    lpCmdLine,
  27.                      _In_ int       nCmdShow)
  28. {
  29.     UNREFERENCED_PARAMETER(hPrevInstance);
  30.     UNREFERENCED_PARAMETER(lpCmdLine);
  31.  
  32.     // TODO: Place code here.
  33.     GdiplusStartupInput gdiplusStartupInput;
  34.     ULONG_PTR gdiplusToken;
  35.     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  36.  
  37.     MSG msg;
  38.     HACCEL hAccelTable;
  39.  
  40.     // Initialize global strings
  41.     LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  42.     LoadString(hInstance, IDC_CGVESO, szWindowClass, MAX_LOADSTRING);
  43.     MyRegisterClass(hInstance);
  44.  
  45.     // Perform application initialization:
  46.     if (!InitInstance (hInstance, nCmdShow))
  47.     {
  48.         return FALSE;
  49.     }
  50.  
  51.     hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CGVESO));
  52.  
  53.     // Main message loop:
  54.     while (GetMessage(&msg, NULL, 0, 0))
  55.     {
  56.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  57.         {
  58.             TranslateMessage(&msg);
  59.             DispatchMessage(&msg);
  60.         }
  61.     }
  62.     GdiplusShutdown(gdiplusToken);
  63.     return (int) msg.wParam;
  64. }
  65.  
  66.  
  67.  
  68. //
  69. //  FUNCTION: MyRegisterClass()
  70. //
  71. //  PURPOSE: Registers the window class.
  72. //
  73. ATOM MyRegisterClass(HINSTANCE hInstance)
  74. {
  75.     WNDCLASSEX wcex;
  76.  
  77.     wcex.cbSize = sizeof(WNDCLASSEX);
  78.  
  79.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  80.     wcex.lpfnWndProc    = WndProc;
  81.     wcex.cbClsExtra     = 0;
  82.     wcex.cbWndExtra     = 0;
  83.     wcex.hInstance      = hInstance;
  84.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CGVESO));
  85.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  86.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  87.     wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_CGVESO);
  88.     wcex.lpszClassName  = szWindowClass;
  89.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  90.  
  91.     return RegisterClassEx(&wcex);
  92. }
  93.  
  94. //
  95. //   FUNCTION: InitInstance(HINSTANCE, int)
  96. //
  97. //   PURPOSE: Saves instance handle and creates main window
  98. //
  99. //   COMMENTS:
  100. //
  101. //        In this function, we save the instance handle in a global variable and
  102. //        create and display the main program window.
  103. //
  104. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  105. {
  106.    HWND hWnd;
  107.  
  108.    hInst = hInstance; // Store instance handle in our global variable
  109.  
  110.    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  111.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  112.  
  113.    if (!hWnd)
  114.    {
  115.       return FALSE;
  116.    }
  117.  
  118.    ShowWindow(hWnd, nCmdShow);
  119.    UpdateWindow(hWnd);
  120.  
  121.    return TRUE;
  122. }
  123.  
  124. //
  125. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  126. //
  127. //  PURPOSE:  Processes messages for the main window.
  128. //
  129. //  WM_COMMAND  - process the application menu
  130. //  WM_PAINT    - Paint the main window
  131. //  WM_DESTROY  - post a quit message and return
  132. //
  133. //
  134. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  135. {
  136.     int wmId, wmEvent;
  137.     PAINTSTRUCT ps;
  138.     HDC hdc;
  139.  
  140.     switch (message)
  141.     {
  142.     case WM_RBUTTONDOWN:
  143.     {
  144.                            InvalidateRect(hWnd, NULL, false);
  145.                            ak++;  (ak > 7);
  146.                            ::UpdateWindow(hWnd);
  147.     }
  148.         break;
  149.     case WM_COMMAND:
  150.         wmId    = LOWORD(wParam);
  151.         wmEvent = HIWORD(wParam);
  152.         // Parse the menu selections:
  153.         switch (wmId)
  154.         {
  155.         case IDM_ABOUT:
  156.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  157.             break;
  158.         case IDM_EXIT:
  159.             DestroyWindow(hWnd);
  160.             break;
  161.         default:
  162.             return DefWindowProc(hWnd, message, wParam, lParam);
  163.         }
  164.         break;
  165.  
  166.     case WM_PAINT:
  167.         hdc = BeginPaint(hWnd, &ps);
  168.         // TODO: Add any drawing code here...
  169.         RECT rt;
  170.         GetClientRect(hWnd, &rt);
  171.         DRAW_TEST(hdc, ak, (int)rt.right, (int)rt.bottom);
  172.         EndPaint(hWnd, &ps);
  173.         break;
  174.     case WM_DESTROY:
  175.         PostQuitMessage(0);
  176.         break;
  177.     default:
  178.         return DefWindowProc(hWnd, message, wParam, lParam);
  179.     }
  180.     return 0;
  181. }
  182.  
  183. // Message handler for about box.
  184. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  185. {
  186.     UNREFERENCED_PARAMETER(lParam);
  187.     switch (message)
  188.     {
  189.     case WM_INITDIALOG:
  190.         return (INT_PTR)TRUE;
  191.  
  192.     case WM_COMMAND:
  193.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  194.         {
  195.             EndDialog(hDlg, LOWORD(wParam));
  196.             return (INT_PTR)TRUE;
  197.         }
  198.         break;
  199.     }
  200.     return (INT_PTR)FALSE;
  201. }
  202. VOID DRAW_TEST(HDC hdc, int ak, int xend, int yend)
  203. {
  204.     Graphics graphics(hdc); // инициация на графичен обект върху екрана
  205.     Rect ellipseRect(xend / 10, yend / 9, yend / 1.3, yend / 1.3);  //дефиниране на елипса с горен ляв ъгъл
  206.     //на описващия правоъгълник в средата на растера и рамери ¼ растер
  207.     Pen bluePen(Color(255, 0, 0, 255)); // дефиниране на син молив
  208.     Pen redPen(Color(255, 255, 0, 0));// дефиниране на червен молив
  209.     Pen greenPen(Color(255, 0, 128, 0));
  210.     Pen purplePen(Color(255, 128, 0, 128));
  211.     Pen yellowPen(Color(255, 255, 255, 0));
  212.     Pen aquaPen(Color(255, 0, 255, 255));
  213.     Pen blackPen(Color(255, 0, 0, 0));
  214.  
  215.     graphics.DrawEllipse(&bluePen, ellipseRect); //чертае елипса
  216.  
  217.     if (ak == 1)
  218.         graphics.DrawLine(&redPen, xend / 3.5, yend / 2, xend / 2.25, yend / 2);//чертае отсечка
  219.     else if (ak == 2)
  220.         graphics.DrawLine(&bluePen, xend / 3.5, yend / 2, xend / 9.9, yend / 2);
  221.     else if (ak == 3)
  222.         graphics.DrawLine(&greenPen, xend / 3.5, yend / 2, xend / 7, yend / 4);
  223.     else if (ak == 4)
  224.         graphics.DrawLine(&purplePen, xend / 3.5, yend / 2, xend / 2.8, yend / 6);
  225.     else if (ak == 5)
  226.         graphics.DrawLine(&yellowPen, xend / 3.5, yend / 2, xend / 4.1, yend / 9);
  227.     else if (ak == 6)
  228.         graphics.DrawLine(&aquaPen, xend / 3.5, yend / 2, xend / 8.8, yend / 2.9);
  229.     else if (ak == 7)
  230.         graphics.DrawLine(&blackPen, xend / 3.5, yend / 2, xend / 2.35, yend / 3);
  231. }
  232.  
Add Comment
Please, Sign In to add comment