Advertisement
lofojak

5sPP2Task5

Oct 9th, 2024
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | Source Code | 0 0
  1. #include <windows.h>
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. HWND edt;
  9. HDC dc;
  10.  
  11. LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
  12. {
  13.     if (message == WM_DESTROY)
  14.         PostQuitMessage(0);
  15.     else if (message == WM_COMMAND)
  16.     {
  17.         if (LOWORD(wparam) == 1) {
  18.             SetDCBrushColor(dc, RGB(255, 255, 255));
  19.             SetDCPenColor(dc, RGB(255, 255, 255));
  20.  
  21.             Rectangle(dc, 0, 0, 400, 400);
  22.  
  23.             int textLength = GetWindowTextLength(edt);
  24.             string txt(textLength, '\0');
  25.             GetWindowTextA(edt, &txt[0], textLength + 1);
  26.  
  27.             SetDCBrushColor(dc, RGB(230, 230, 230));
  28.             SetDCPenColor(dc, RGB(0, 0, 0));
  29.  
  30.             for (int i = 0; i < stoi(txt); i++) {
  31.                 int r = 1 + rand() % 50;
  32.                 int x1 = 1 + rand() % 300;
  33.                 int y1 = 1 + rand() % 300;
  34.                 int x2 = x1 + 2 * r;
  35.                 int y2 = y1 + 2 * r;
  36.                 Ellipse(dc, x1, y1, x2, y2);
  37.             }
  38.         }
  39.     }
  40.     else return DefWindowProcA(hwnd, message, wparam, lparam);
  41. }
  42.  
  43. int main()
  44. {
  45.     srand(time(NULL));
  46.  
  47.     WNDCLASSA wcl;
  48.     memset(&wcl, 0, sizeof(WNDCLASSA));
  49.     wcl.lpszClassName = "my_Window";
  50.     wcl.lpfnWndProc = WndProc;
  51.     RegisterClassA(&wcl);
  52.     HWND hwnd = CreateWindow(L"my_Window", L"Окошечко", WS_OVERLAPPEDWINDOW, 10, 10, 640, 480, NULL, NULL, NULL, NULL);
  53.  
  54.     MSG msg;
  55.     ShowWindow(hwnd, SW_SHOWNORMAL);
  56.  
  57.     dc = GetDC(hwnd);
  58.     SelectObject(dc, GetStockObject(DC_BRUSH));
  59.     SelectObject(dc, GetStockObject(DC_PEN));
  60.  
  61.     HWND lbl = CreateWindow(L"static", L"Number: ", WS_VISIBLE | WS_CHILD, 440, 10, 65, 25, hwnd, NULL, NULL, NULL);
  62.     edt = CreateWindow(L"edit", L"30", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_RIGHT, 515, 10, 45, 20, hwnd, NULL, NULL, NULL);
  63.     HWND btn = CreateWindow(L"button", L"Ok", WS_VISIBLE | WS_CHILD, 570, 10, 50, 20, hwnd, (HMENU)1, NULL, NULL);
  64.  
  65.     while (GetMessage(&msg, NULL, 0, 0))
  66.     {
  67.         TranslateMessage(&msg);
  68.         DispatchMessage(&msg);
  69.     }
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement