Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <time.h>
- #include <stdlib.h>
- #include <stdio.h>
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- POINT start;
- int max = 500, current = 10;
- int randx, randy, randz;
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
- srand(time(0));
- HWND Main;
- MSG msg;
- WNDCLASSEX wc;
- char szClassName[] = "AppClass";
- wc.style = 0;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hIcon = 0;
- wc.hCursor = 0;
- wc.hbrBackground = 0;
- wc.lpszMenuName = NULL;
- wc.hIconSm = 0;
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = szClassName;
- wc.hInstance = hInstance;
- wc.lpfnWndProc = WndProc;
- if (!RegisterClassEx(&wc)) {
- MessageBox(NULL, "Не удалось зарегистрировать класс окна", "Ошибка", MB_OK);
- return 0;
- }
- Main = CreateWindow(szClassName, "dsg", DS_CENTER | WS_MAXIMIZEBOX | WS_SYSMENU, CW_USEDEFAULT, 0, 500, 500, 0,0, hInstance,0);
- ShowWindow(Main, nCmdShow);
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 1;
- }
- LRESULT CALLBACK WndProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) {
- PAINTSTRUCT ps;
- RECT rect;
- HDC hdc;
- switch (Msg) {
- case WM_CREATE: {
- break;
- }
- case WM_LBUTTONDOWN: {
- start.x = LOWORD(lParam);
- start.y = HIWORD(lParam);
- hdc = GetDC(hDlg);
- current = 10;
- randx = 0 + rand() % 255,
- randy = 0 + rand() % 255,
- randz = 0 + rand() % 255;
- HBRUSH hPen = CreateSolidBrush(RGB(randx, randy, randz));
- SelectObject(hdc, hPen);
- Ellipse(hdc, start.x - current, start.y - current, start.x + current, start.y + current);
- ReleaseDC(hDlg, hdc);
- SetTimer(hDlg, 100, 100, NULL);
- break;
- }
- case WM_TIMER: {
- current += 10;
- hdc = GetDC(hDlg);
- HBRUSH hPen = CreateSolidBrush(RGB(randx, randy, randz));
- SelectObject(hdc, hPen);
- Ellipse(hdc, start.x - current, start.y - current, start.x + current, start.y + current);
- ReleaseDC(hDlg, hdc);
- if (current >= max) KillTimer(hDlg, 100);
- break;
- }
- case WM_CLOSE: {
- DestroyWindow(hDlg);
- break;
- }
- case WM_DESTROY: {
- PostQuitMessage(0);
- break;
- }
- default: {
- return DefWindowProc(hDlg, Msg, wParam, lParam); //обработка сообщений по умолчанию
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement