Advertisement
alexx876

Untitled

Jan 12th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6.  
  7. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  8. POINT start;
  9.  
  10. int max = 500, current = 10;
  11. int randx, randy, randz;
  12.  
  13. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  14.     srand(time(0));
  15.  
  16.     HWND Main;
  17.     MSG msg;
  18.  
  19.     WNDCLASSEX wc;
  20.  
  21.     char szClassName[] = "AppClass";
  22.  
  23.     wc.style = 0;
  24.     wc.cbClsExtra = 0;
  25.     wc.cbWndExtra = 0;
  26.     wc.hIcon = 0;
  27.     wc.hCursor = 0;
  28.     wc.hbrBackground = 0;
  29.     wc.lpszMenuName = NULL;
  30.     wc.hIconSm = 0;
  31.  
  32.     wc.cbSize = sizeof(wc);
  33.     wc.lpszClassName = szClassName;
  34.     wc.hInstance = hInstance;
  35.     wc.lpfnWndProc = WndProc;
  36.  
  37.     if (!RegisterClassEx(&wc)) {
  38.         MessageBox(NULL, "Не удалось зарегистрировать класс окна", "Ошибка", MB_OK);
  39.         return 0;
  40.     }
  41.  
  42.     Main = CreateWindow(szClassName, "dsg", DS_CENTER | WS_MAXIMIZEBOX | WS_SYSMENU, CW_USEDEFAULT, 0, 500, 500, 0,0, hInstance,0);
  43.  
  44.     ShowWindow(Main, nCmdShow);
  45.  
  46.     while (GetMessage(&msg, NULL, 0, 0)) {
  47.         TranslateMessage(&msg);
  48.         DispatchMessage(&msg);
  49.     }
  50.  
  51.     return 1;
  52. }
  53.  
  54.  
  55. LRESULT CALLBACK WndProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) {
  56.     PAINTSTRUCT ps;
  57.     RECT rect;
  58.     HDC hdc;
  59.  
  60.     switch (Msg) {
  61.         case WM_CREATE: {
  62.  
  63.             break;
  64.         }
  65.         case WM_LBUTTONDOWN: {
  66.             start.x = LOWORD(lParam);
  67.             start.y = HIWORD(lParam);
  68.  
  69.             hdc = GetDC(hDlg);
  70.             current = 10;
  71.            
  72.             randx = 0 + rand() % 255,
  73.                 randy = 0 + rand() % 255,
  74.                 randz = 0 + rand() % 255;
  75.  
  76.             HBRUSH hPen = CreateSolidBrush(RGB(randx, randy, randz));
  77.             SelectObject(hdc, hPen);
  78.  
  79.             Ellipse(hdc, start.x - current, start.y - current, start.x + current, start.y + current);
  80.  
  81.             ReleaseDC(hDlg, hdc);
  82.  
  83.             SetTimer(hDlg, 100, 100, NULL);
  84.             break;
  85.         }
  86.         case WM_TIMER: {
  87.             current += 10;
  88.             hdc = GetDC(hDlg);
  89.  
  90.             HBRUSH hPen = CreateSolidBrush(RGB(randx, randy, randz));
  91.             SelectObject(hdc, hPen);
  92.            
  93.             Ellipse(hdc, start.x - current, start.y - current, start.x + current, start.y + current);
  94.  
  95.             ReleaseDC(hDlg, hdc);
  96.             if (current >= max) KillTimer(hDlg, 100);
  97.             break;
  98.         }
  99.         case WM_CLOSE: {
  100.             DestroyWindow(hDlg);
  101.             break;
  102.         }
  103.         case WM_DESTROY: {
  104.             PostQuitMessage(0);
  105.             break;
  106.         }
  107.         default: {
  108.             return DefWindowProc(hDlg, Msg, wParam, lParam); //обработка сообщений по умолчанию
  109.         }
  110.     }
  111.     return 1;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement