1234 #2
@ -1,20 +1,479 @@
|
||||
// ConsoleApplication1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
|
||||
// lab18.cpp : Îïðåäåëÿåò òî÷êó âõîäà äëÿ ïðèëîæåíèÿ.
|
||||
//
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <iostream>
|
||||
#include "framework.h"
|
||||
#include "lab18.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user