From f610c4486bcdfa444a6ae7f26acefb8470ed5325 Mon Sep 17 00:00:00 2001 From: RavilGismatullin Date: Tue, 17 Dec 2024 09:35:24 +0400 Subject: [PATCH] 1234 --- .../ConsoleApplication1.cpp | 485 +++++++++++++++++- 1 file changed, 472 insertions(+), 13 deletions(-) diff --git a/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.cpp b/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.cpp index 9d6500d..23e61a5 100644 --- a/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.cpp +++ b/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.cpp @@ -1,20 +1,479 @@ -// ConsoleApplication1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы. +// lab18.cpp : . // +#define _CRT_SECURE_NO_WARNINGS -#include +#include "framework.h" +#include "lab18.h" +#include -int main() +#define MAX_LOADSTRING 100 + + +// : +int counter = 0; +HINSTANCE hInst; // +WCHAR szTitle[MAX_LOADSTRING]; // +WCHAR szWindowClass[MAX_LOADSTRING]; // +int numImage = 0; + +// , : +ATOM MyRegisterClass(HINSTANCE hInstance); +BOOL InitInstance(HINSTANCE, int); +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); + +int APIENTRY wWinMain(_In_ HINSTANCE hInstance, + _In_opt_ HINSTANCE hPrevInstance, + _In_ LPWSTR lpCmdLine, + _In_ int nCmdShow) { - std::cout << "Hello World!\n"; + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); + + // TODO: . + + // + LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + LoadStringW(hInstance, IDC_LAB18, szWindowClass, MAX_LOADSTRING); + MyRegisterClass(hInstance); + + // : + if (!InitInstance (hInstance, nCmdShow)) + { + return FALSE; + } + + HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_LAB18)); + + MSG msg; + + // : + while (GetMessage(&msg, nullptr, 0, 0)) + { + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + return (int) msg.wParam; } -// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки" -// Отладка программы: F5 или меню "Отладка" > "Запустить отладку" -// Советы по началу работы -// 1. В окне обозревателя решений можно добавлять файлы и управлять ими. -// 2. В окне Team Explorer можно подключиться к системе управления версиями. -// 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения. -// 4. В окне "Список ошибок" можно просматривать ошибки. -// 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода. -// 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл. + +// +// : MyRegisterClass() +// +// : . +// +ATOM MyRegisterClass(HINSTANCE hInstance) +{ + WNDCLASSEXW wcex; + + wcex.cbSize = sizeof(WNDCLASSEX); + + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_LAB18)); + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_LAB18); + wcex.lpszClassName = szWindowClass; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + + return RegisterClassExW(&wcex); +} + +// +// : InitInstance(HINSTANCE, int) +// +// : +// +// : +// +// , +// . +// +BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) +{ + hInst = hInstance; // + + HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); + + if (!hWnd) + { + return FALSE; + } + + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); + + return TRUE; +} + +// +// : WndProc(HWND, UINT, WPARAM, LPARAM) +// +// : . +// +// WM_COMMAND - +// WM_PAINT - +// WM_DESTROY - +// +void Image1(HDC hdc, int cx, int cy, int size) { + int x1 = cx - size / 2; + int y1 = cy - size / 2; + int x2 = cx + size / 2; + int y2 = cy - size / 2; + int x3 = cx; + int y3 = cy + size / 2; + + HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 0)); + SelectObject(hdc, hPen); + MoveToEx(hdc, x1, y1, NULL); + LineTo(hdc, x2, y2); + LineTo(hdc, x3, y3); + LineTo(hdc, x1, y1); + + char strC[5]; + sprintf(strC, "%d", counter); + TCHAR strWin[5]; + OemToChar(strC, strWin); + TextOut(hdc, cx, cy, (LPCWSTR)strWin, _tcslen(strWin)); + + DeleteObject(hPen); +} +void RecursiveImage1_1(HDC hdc, int cx, int cy, int size) { + counter++; + Image1(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage1_1(hdc, cx - size / 2, cy - size / 2, size / 2); + RecursiveImage1_1(hdc, cx + size / 2, cy - size / 2, size / 2); +} +void RecursiveImage1_2(HDC hdc, int cx, int cy, int size) { + counter++; + Image1(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage1_2(hdc, cx - size / 2, cy - size / 2, size / 2); + RecursiveImage1_2(hdc, cx, cy + size / 2, size / 2); +} +void RecursiveImage1_3(HDC hdc, int cx, int cy, int size) { + counter++; + Image1(hdc, cx, cy, size); + if (size < 10) { + return; + } + RecursiveImage1_3(hdc, cx - size / 2, cy - size / 2, size / 2); + RecursiveImage1_3(hdc, cx + size / 2, cy - size / 2, size / 2); + RecursiveImage1_3(hdc, cx - size / 2, cy - size / 2, size / 2); + RecursiveImage1_3(hdc, cx, cy + size / 2, size / 2); +} +void Image2(HDC hdc, int cx, int cy, int size) { + int x1 = cx - size / 2; + int y1 = cy - size; + int x2 = cx + size / 2; + int y2 = cy - size; + int x3 = cx - size; + int y3 = cy + size; + int x4 = cx + size; + int y4 = cy + size; + + HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); + SelectObject(hdc, hPen); + + MoveToEx(hdc, x1, y1, NULL); + LineTo(hdc, x2, y2); + LineTo(hdc, x3, y3); + LineTo(hdc, x4, y4); + LineTo(hdc, x1, y1); + + DeleteObject(hPen); +} +void RecursiveImage2_1(HDC hdc, int cx, int cy, int size) { + Image2(hdc, cx, cy, size); + if (size < 5) { + return; + } + RecursiveImage2_1(hdc, cx - size / 2, cy - size, size / 2); +} +void RecursiveImage2_2(HDC hdc, int cx, int cy, int size) { + Image2(hdc, cx, cy, size); + if (size < 5) { + return; + } + RecursiveImage2_2(hdc, cx - size / 2, cy - size, size / 2); + RecursiveImage2_2(hdc, cx + size / 2, cy - size, size / 2); +} +void RecursiveImage2_3(HDC hdc, int cx, int cy, int size) { + Image2(hdc, cx, cy, size); + if (size < 15) { + return; + } + RecursiveImage2_3(hdc, cx - size / 2, cy - size, size / 2); + RecursiveImage2_3(hdc, cx + size / 2, cy - size, size / 2); + RecursiveImage2_3(hdc, cx - size, cy + size, size / 2); + RecursiveImage2_3(hdc, cx + size, cy + size, size / 2); +} +void Image3(HDC hdc, int cx, int cy, int size) { + int x1 = cx; + int y1 = cy - size; + + int x2 = cx + size; + int y2 = cy; + + int x3 = cx; + int y3 = cy + size; + + int x4 = cx - size; + int y4 = cy; + + HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); + SelectObject(hdc, hPen); + + MoveToEx(hdc, x1, y1, NULL); + LineTo(hdc, x2, y2); + LineTo(hdc, x3, y3); + LineTo(hdc, x4, y4); + LineTo(hdc, x1, y1); + + DeleteObject(hPen); +} +void RecursiveImage3_1(HDC hdc, int cx, int cy, int size) { + Image3(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage3_1(hdc, cx + size, cy, size / 2); + RecursiveImage3_1(hdc, cx - size, cy, size / 2); +} +void RecursiveImage3_2(HDC hdc, int cx, int cy, int size) { + Image3(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage3_2(hdc, cx + size, cy, size / 2); + RecursiveImage3_2(hdc, cx - size, cy, size / 2); + RecursiveImage3_2(hdc, cx, cy + size, size / 2); +} +void RecursiveImage3_3(HDC hdc, int cx, int cy, int size) { + Image3(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage3_3(hdc, cx + size, cy, size / 2); + RecursiveImage3_3(hdc, cx - size, cy, size / 2); + RecursiveImage3_3(hdc, cx, cy - size, size / 2); +} +void RecursiveImage3_4(HDC hdc, int cx, int cy, int size) { + Image3(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage3_4(hdc, cx + size, cy, size / 2); + RecursiveImage3_4(hdc, cx - size, cy, size / 2); + RecursiveImage3_4(hdc, cx, cy - size, size / 2); + RecursiveImage3_4(hdc, cx, cy + size, size / 2); +} +void Image4(HDC hdc, int cx, int cy, int size) { + int x1 = cx; + int y1 = cy - size; + + int x2 = cx + size / 4; + int y2 = cy - size / 4; + + int x3 = cx + size; + int y3 = cy; + + int x4 = cx + size / 4; + int y4 = cy + size / 4; + + int x5 = cx; + int y5 = cy + size; + + int x6 = cx - size / 4; + int y6 = cy + size / 4; + + int x7 = cx - size; + int y7 = cy; + + int x8 = cx - size / 4; + int y8 = cy - size / 4; + HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); + SelectObject(hdc, hPen); + + MoveToEx(hdc, x1, y1, NULL); + LineTo(hdc, x2, y2); + LineTo(hdc, x3, y3); + LineTo(hdc, x4, y4); + LineTo(hdc, x5, y5); + LineTo(hdc, x6, y6); + LineTo(hdc, x7, y7); + LineTo(hdc, x8, y8); + LineTo(hdc, x1, y1); + + DeleteObject(hPen); +} +void RecursiveImage4_1(HDC hdc, int cx, int cy, int size) { + Image4(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage4_1(hdc, cx + size, cy, size / 2); + RecursiveImage4_1(hdc, cx - size, cy, size / 2); +} +void RecursiveImage4_2(HDC hdc, int cx, int cy, int size) { + Image4(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage4_2(hdc, cx, cy + size, size / 2); + RecursiveImage4_2(hdc, cx, cy - size, size / 2); +} +void RecursiveImage4_3(HDC hdc, int cx, int cy, int size) { + Image4(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage4_3(hdc, cx, cy + size, size / 2); + RecursiveImage4_3(hdc, cx, cy - size, size / 2); + RecursiveImage4_3(hdc, cx - size, cy, size / 2); +} +void Image5(HDC hdc, int cx, int cy, int size) { + int x1 = cx - size; + int y1 = cy - size / 1.5; + + int x2 = cx + size; + int y2 = cy - size / 1.5; + + int x3 = cx + size / 2; + int y3 = cy + size / 2; + + int x4 = cx - size * 1.5; + int y4 = cy + size / 2; + HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); + SelectObject(hdc, hPen); + + MoveToEx(hdc, x1, y1, NULL); + LineTo(hdc, x2, y2); + LineTo(hdc, x3, y3); + LineTo(hdc, x4, y4); + LineTo(hdc, x1, y1); + + DeleteObject(hPen); +} +void RecursiveImage5_1(HDC hdc, int cx, int cy, int size) { + Image5(hdc, cx, cy, size); + if (size < 20) { + return; + } + RecursiveImage5_1(hdc, cx - size, cy - size / 1.5, size / 2); + RecursiveImage5_1(hdc, cx + size / 1.5, cy + size / 2, size / 2); + RecursiveImage5_1(hdc, cx + size, cy - size / 1.5, size / 2); + RecursiveImage5_1(hdc, cx - size * 1.5, cy + size / 2, size / 2); +} +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_COMMAND: + { + case WM_KEYDOWN: + switch (wParam) + { + case 0xbe: + numImage++; + if (numImage >= 20) + numImage = 0; + InvalidateRect(hWnd, NULL, TRUE); + } + break; + int wmId = LOWORD(wParam); + // : + switch (wmId) + { + case IDM_ABOUT: + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); + break; + case IDM_EXIT: + DestroyWindow(hWnd); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + } + break; + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + // TODO: , HDC... + if (numImage == 0) + counter = 0; + RecursiveImage1_1(hdc, 200, 160, 160); + if (numImage == 1) + RecursiveImage1_2(hdc, 200, 160, 160); + if (numImage == 2) + RecursiveImage1_3(hdc, 200, 160, 160); + if (numImage == 3) + RecursiveImage2_1(hdc, 200, 200, 100); + if (numImage == 4) + RecursiveImage2_2(hdc, 200, 200, 100); + if (numImage == 5) + RecursiveImage2_3(hdc, 200, 200, 100); + if (numImage == 6) + RecursiveImage3_1(hdc, 200, 200, 100); + if (numImage == 7) + RecursiveImage3_2(hdc, 350, 200, 100); + if (numImage == 8) + RecursiveImage3_3(hdc, 350, 200, 100); + if (numImage == 9) + RecursiveImage3_4(hdc, 350, 200, 100); + if (numImage == 10) + RecursiveImage4_1(hdc, 300, 200, 100); + if (numImage == 11) + RecursiveImage4_2(hdc, 300, 200, 100); + if (numImage == 12) + RecursiveImage4_3(hdc, 300, 200, 100); + if (numImage == 13) + RecursiveImage5_1(hdc, 300, 200, 100); + EndPaint(hWnd, &ps); + } + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} + +// " ". +INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + switch (message) + { + case WM_INITDIALOG: + return (INT_PTR)TRUE; + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return (INT_PTR)TRUE; + } + break; + } + return (INT_PTR)FALSE; +} +