449 lines
13 KiB
C++
449 lines
13 KiB
C++
|
// 18.cpp : Определяет точку входа для приложения.
|
|||
|
//
|
|||
|
|
|||
|
#include "framework.h"
|
|||
|
#include "stdio.h"
|
|||
|
#include "18.h"
|
|||
|
|
|||
|
#define MAX_LOADSTRING 100
|
|||
|
|
|||
|
int count = 0;
|
|||
|
int Action = 0;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
void triangle(HDC hdc, int cx, int cy, int size) {
|
|||
|
SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
|||
|
POINT pt[3] = {
|
|||
|
{cx,cy + size},
|
|||
|
{cx + size,cy - size},
|
|||
|
{cx - size,cy - size}
|
|||
|
};
|
|||
|
Polygon(hdc, pt, 3);
|
|||
|
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
|||
|
}
|
|||
|
|
|||
|
void triangleFact1(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
triangle(hdc, cx, cy, size);
|
|||
|
triangleFact1(hdc, cx - size, cy - size, size / 2);
|
|||
|
triangleFact1(hdc, cx, cy + size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void triangleFact2(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
triangle(hdc, cx, cy, size);
|
|||
|
triangleFact2(hdc, cx - size, cy - size, size / 2);
|
|||
|
triangleFact2(hdc, cx + size, cy - size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void triangleFact3(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
triangle(hdc, cx, cy, size);
|
|||
|
triangleFact3(hdc, cx - size, cy - size, size / 2);
|
|||
|
triangleFact3(hdc, cx + size, cy - size, size / 2);
|
|||
|
triangleFact3(hdc, cx, cy + size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void time(HDC hdc, int cx, int cy, int size) {
|
|||
|
SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
|||
|
POINT pt[4] = {
|
|||
|
{cx + size,cy + size},
|
|||
|
{cx - size,cy + size},
|
|||
|
{cx + size / 2,cy - size},
|
|||
|
{cx - size / 2,cy - size},
|
|||
|
};
|
|||
|
Polygon(hdc, pt, 4);
|
|||
|
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
|||
|
}
|
|||
|
|
|||
|
void timeFact1(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
time(hdc, cx, cy, size);
|
|||
|
timeFact1(hdc, cx - size / 2 , cy - size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void timeFact2(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
time(hdc, cx, cy, size);
|
|||
|
timeFact2(hdc, cx - size / 2, cy - size, size / 2);
|
|||
|
timeFact2(hdc, cx + size / 2, cy - size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void timeFact3(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
time(hdc, cx, cy, size);
|
|||
|
timeFact3(hdc, cx - size / 2, cy - size, size / 2);
|
|||
|
timeFact3(hdc, cx - size, cy + size, size / 2);
|
|||
|
timeFact3(hdc, cx + size / 2, cy - size, size / 2);
|
|||
|
timeFact3(hdc, cx + size, cy + size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void dimond(HDC hdc, int cx, int cy, int size) {
|
|||
|
SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
|||
|
POINT pt[4] = {
|
|||
|
{cx,cy - size},
|
|||
|
{cx + size,cy},
|
|||
|
{cx,cy + size},
|
|||
|
{cx - size,cy},
|
|||
|
};
|
|||
|
Polygon(hdc, pt, 4);
|
|||
|
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
|||
|
}
|
|||
|
|
|||
|
void dimondFact1(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
dimond(hdc, cx, cy, size);
|
|||
|
dimondFact1(hdc, cx - size, cy, size / 2);
|
|||
|
dimondFact1(hdc, cx + size, cy, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void dimondFact2(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
dimond(hdc, cx, cy, size);
|
|||
|
dimondFact2(hdc, cx - size, cy, size / 2);
|
|||
|
dimondFact2(hdc, cx + size, cy, size / 2);
|
|||
|
dimondFact2(hdc, cx, cy + size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void dimondFact3(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
dimond(hdc, cx, cy, size);
|
|||
|
dimondFact2(hdc, cx - size, cy, size / 2);
|
|||
|
dimondFact2(hdc, cx + size, cy, size / 2);
|
|||
|
dimondFact2(hdc, cx, cy - size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void dimondFact4(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
dimond(hdc, cx, cy, size);
|
|||
|
dimondFact3(hdc, cx - size, cy, size / 2);
|
|||
|
dimondFact3(hdc, cx + size, cy, size / 2);
|
|||
|
dimondFact3(hdc, cx, cy + size, size / 2);
|
|||
|
dimondFact3(hdc, cx, cy - size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void star(HDC hdc, int cx, int cy, int size) {
|
|||
|
SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
|||
|
POINT pt[8] = {
|
|||
|
{cx,cy - size},
|
|||
|
{cx + size / 4,cy - size / 4},
|
|||
|
{cx + size,cy},
|
|||
|
{cx + size / 4,cy + size / 4},
|
|||
|
{cx,cy + size},
|
|||
|
{cx - size / 4,cy + size / 4},
|
|||
|
{cx - size,cy},
|
|||
|
{cx - size / 4,cy - size / 4},
|
|||
|
};
|
|||
|
Polygon(hdc, pt, 8);
|
|||
|
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
|||
|
}
|
|||
|
|
|||
|
void starFact1(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
star(hdc, cx, cy, size);
|
|||
|
starFact1(hdc, cx - size, cy, size / 2);
|
|||
|
starFact1(hdc, cx + size, cy, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void starFact2(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
star(hdc, cx, cy, size);
|
|||
|
starFact2(hdc, cx, cy - size, size / 2);
|
|||
|
starFact2(hdc, cx, cy + size, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void starFact3(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
star(hdc, cx, cy, size);
|
|||
|
starFact3(hdc, cx, cy - size, size / 2);
|
|||
|
starFact3(hdc, cx, cy + size, size / 2);
|
|||
|
starFact3(hdc, cx - size, cy, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void arrow(HDC hdc, int cx, int cy, int size) {
|
|||
|
SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
|||
|
POINT pt[7] = {
|
|||
|
{cx - size / 2,cy - size},
|
|||
|
{cx + size / 2,cy - size},
|
|||
|
{cx + size / 2,cy},
|
|||
|
{cx + size,cy},
|
|||
|
{cx,cy + size},
|
|||
|
{cx - size,cy},
|
|||
|
{cx - size / 2,cy},
|
|||
|
};
|
|||
|
Polygon(hdc, pt, 7);
|
|||
|
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
|||
|
}
|
|||
|
|
|||
|
void arrowFactMini(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
arrow(hdc, cx, cy, size);
|
|||
|
|
|||
|
count++;
|
|||
|
char text[80];
|
|||
|
sprintf_s(text, "%d", count);
|
|||
|
TextOutA(hdc, cx, cy, (LPCSTR)text, strlen(text));
|
|||
|
|
|||
|
arrowFactMini(hdc, cx - size / 2, cy - size, size / 2);
|
|||
|
arrowFactMini(hdc, cx + size / 2, cy - size, size / 2);
|
|||
|
arrowFactMini(hdc, cx + size, cy, size / 2);
|
|||
|
arrowFactMini(hdc, cx, cy + size, size / 2);
|
|||
|
arrowFactMini(hdc, cx - size, cy, size / 2);
|
|||
|
}
|
|||
|
|
|||
|
void arrowFactMaxi(HDC hdc, int cx, int cy, int size) {
|
|||
|
if (size <= 10) return;
|
|||
|
arrow(hdc, cx, cy, size);
|
|||
|
|
|||
|
count++;
|
|||
|
char text[80];
|
|||
|
sprintf_s(text, "%d", count);
|
|||
|
TextOutA(hdc, cx, cy, (LPCSTR)text, strlen(text));
|
|||
|
|
|||
|
arrowFactMaxi(hdc, cx - size / 2, cy - size, size / 3);
|
|||
|
arrowFactMaxi(hdc, cx + size / 2, cy - size, size / 3);
|
|||
|
arrowFactMaxi(hdc, cx + size, cy, size / 3);
|
|||
|
arrowFactMaxi(hdc, cx, cy + size, size / 3);
|
|||
|
arrowFactMaxi(hdc, cx - size, cy, size / 3);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// Глобальные переменные:
|
|||
|
HINSTANCE hInst; // текущий экземпляр
|
|||
|
WCHAR szTitle[MAX_LOADSTRING]; // Текст строки заголовка
|
|||
|
WCHAR szWindowClass[MAX_LOADSTRING]; // имя класса главного окна
|
|||
|
|
|||
|
// Отправить объявления функций, включенных в этот модуль кода:
|
|||
|
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)
|
|||
|
{
|
|||
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
|||
|
UNREFERENCED_PARAMETER(lpCmdLine);
|
|||
|
|
|||
|
// TODO: Разместите код здесь.
|
|||
|
|
|||
|
// Инициализация глобальных строк
|
|||
|
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
|||
|
LoadStringW(hInstance, IDC_MY18, szWindowClass, MAX_LOADSTRING);
|
|||
|
MyRegisterClass(hInstance);
|
|||
|
|
|||
|
// Выполнить инициализацию приложения:
|
|||
|
if (!InitInstance (hInstance, nCmdShow))
|
|||
|
{
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MY18));
|
|||
|
|
|||
|
MSG msg;
|
|||
|
|
|||
|
// Цикл основного сообщения:
|
|||
|
while (GetMessage(&msg, nullptr, 0, 0))
|
|||
|
{
|
|||
|
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
|
|||
|
{
|
|||
|
TranslateMessage(&msg);
|
|||
|
DispatchMessage(&msg);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return (int) msg.wParam;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//
|
|||
|
// ФУНКЦИЯ: 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_MY18));
|
|||
|
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
|||
|
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
|||
|
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_MY18);
|
|||
|
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 - отправить сообщение о выходе и вернуться
|
|||
|
//
|
|||
|
//
|
|||
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
|
{
|
|||
|
switch (message)
|
|||
|
{
|
|||
|
case WM_COMMAND:
|
|||
|
{
|
|||
|
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);
|
|||
|
|
|||
|
count = 0;
|
|||
|
|
|||
|
switch (Action % 15) {
|
|||
|
case 0:
|
|||
|
triangleFact1(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 1:
|
|||
|
triangleFact2(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
triangleFact3(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
timeFact1(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
timeFact2(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 5:
|
|||
|
timeFact3(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 6:
|
|||
|
dimondFact1(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 7:
|
|||
|
dimondFact2(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 8:
|
|||
|
dimondFact3(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 9:
|
|||
|
dimondFact4(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 10:
|
|||
|
starFact1(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 11:
|
|||
|
starFact2(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 12:
|
|||
|
starFact3(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 13:
|
|||
|
arrowFactMini(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
case 14:
|
|||
|
arrowFactMaxi(hdc, 200, 200, 100);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
EndPaint(hWnd, &ps);
|
|||
|
}
|
|||
|
break;
|
|||
|
case WM_KEYDOWN:
|
|||
|
Action ++;
|
|||
|
InvalidateRect(hWnd, NULL, TRUE);
|
|||
|
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;
|
|||
|
}
|