Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <time.h>
- #include <stdio.h>
- #include <string>
- using namespace std;
- HWND edt;
- HDC dc;
- LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
- {
- if (message == WM_DESTROY)
- PostQuitMessage(0);
- else if (message == WM_COMMAND)
- {
- if (LOWORD(wparam) == 1) {
- SetDCBrushColor(dc, RGB(255, 255, 255));
- SetDCPenColor(dc, RGB(255, 255, 255));
- Rectangle(dc, 0, 0, 400, 400);
- int textLength = GetWindowTextLength(edt);
- string txt(textLength, '\0');
- GetWindowTextA(edt, &txt[0], textLength + 1);
- SetDCBrushColor(dc, RGB(230, 230, 230));
- SetDCPenColor(dc, RGB(0, 0, 0));
- for (int i = 0; i < stoi(txt); i++) {
- int r = 1 + rand() % 50;
- int x1 = 1 + rand() % 300;
- int y1 = 1 + rand() % 300;
- int x2 = x1 + 2 * r;
- int y2 = y1 + 2 * r;
- Ellipse(dc, x1, y1, x2, y2);
- }
- }
- }
- else return DefWindowProcA(hwnd, message, wparam, lparam);
- }
- int main()
- {
- srand(time(NULL));
- WNDCLASSA wcl;
- memset(&wcl, 0, sizeof(WNDCLASSA));
- wcl.lpszClassName = "my_Window";
- wcl.lpfnWndProc = WndProc;
- RegisterClassA(&wcl);
- HWND hwnd = CreateWindow(L"my_Window", L"Окошечко", WS_OVERLAPPEDWINDOW, 10, 10, 640, 480, NULL, NULL, NULL, NULL);
- MSG msg;
- ShowWindow(hwnd, SW_SHOWNORMAL);
- dc = GetDC(hwnd);
- SelectObject(dc, GetStockObject(DC_BRUSH));
- SelectObject(dc, GetStockObject(DC_PEN));
- HWND lbl = CreateWindow(L"static", L"Number: ", WS_VISIBLE | WS_CHILD, 440, 10, 65, 25, hwnd, NULL, NULL, NULL);
- edt = CreateWindow(L"edit", L"30", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_RIGHT, 515, 10, 45, 20, hwnd, NULL, NULL, NULL);
- HWND btn = CreateWindow(L"button", L"Ok", WS_VISIBLE | WS_CHILD, 570, 10, 50, 20, hwnd, (HMENU)1, NULL, NULL);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement