501 lines
13 KiB
C++
501 lines
13 KiB
C++
|
// Lab11_1.OAIP.ProkonovKirill.cpp : Определяет точку входа для приложения.
|
|||
|
//
|
|||
|
|
|||
|
#include "framework.h"
|
|||
|
#include "Lab11_1.OAIP.ProkonovKirill.h"
|
|||
|
|
|||
|
#define MAX_LOADSTRING 100
|
|||
|
|
|||
|
// Глобальные переменные:
|
|||
|
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_LAB111OAIPPROKONOVKIRILL, szWindowClass, MAX_LOADSTRING);
|
|||
|
MyRegisterClass(hInstance);
|
|||
|
|
|||
|
// Выполнить инициализацию приложения:
|
|||
|
if (!InitInstance (hInstance, nCmdShow))
|
|||
|
{
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_LAB111OAIPPROKONOVKIRILL));
|
|||
|
|
|||
|
MSG msg;
|
|||
|
|
|||
|
// Цикл основного сообщения:
|
|||
|
while (GetMessage(&msg, nullptr, 0, 0))
|
|||
|
{
|
|||
|
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
|
|||
|
{
|
|||
|
TranslateMessage(&msg);
|
|||
|
DispatchMessage(&msg);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return (int) msg.wParam;
|
|||
|
}
|
|||
|
|
|||
|
void TestImage0(HDC hdc, int cx, int cy) {
|
|||
|
HPEN hPen;
|
|||
|
hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
|
|||
|
SelectObject(hdc, hPen);
|
|||
|
|
|||
|
POINT p[4];
|
|||
|
p[0].x = cx;
|
|||
|
p[0].y = cy + 20;
|
|||
|
p[1].x = cx + 20;
|
|||
|
p[1].y = cy - 20;
|
|||
|
p[2].x = cx - 20;
|
|||
|
p[2].y = cy - 20;
|
|||
|
p[3].x = cx;
|
|||
|
p[3].y = cy + 20;
|
|||
|
|
|||
|
Polyline(hdc, p, 4);
|
|||
|
DeleteObject(hPen);
|
|||
|
}
|
|||
|
|
|||
|
void Image0(HDC hdc, int cx, int cy, COLORREF color) {
|
|||
|
HPEN hPen;
|
|||
|
hPen = CreatePen(PS_SOLID, 2, color);
|
|||
|
SelectObject(hdc, hPen);
|
|||
|
|
|||
|
POINT p[5] = {
|
|||
|
cx, cy + 20,
|
|||
|
cx + 20, cy - 20,
|
|||
|
cx - 20, cy - 20,
|
|||
|
cx, cy + 20,
|
|||
|
cx, cy + 20,
|
|||
|
};
|
|||
|
|
|||
|
Polyline(hdc, p, 4);
|
|||
|
DeleteObject(hPen);
|
|||
|
}
|
|||
|
|
|||
|
void Image1(HDC hdc, int cx, int cy, COLORREF color) {
|
|||
|
HPEN hPen = CreatePen(PS_SOLID, 2, color);
|
|||
|
SelectObject(hdc, hPen);
|
|||
|
|
|||
|
POINT p[4] = {
|
|||
|
cx, cy - 20,
|
|||
|
cx + 20, cy + 20,
|
|||
|
cx - 20, cy + 20,
|
|||
|
cx, cy - 20
|
|||
|
};
|
|||
|
Polyline(hdc, p, 4);
|
|||
|
|
|||
|
DeleteObject(hPen);
|
|||
|
}
|
|||
|
|
|||
|
void Image2(HDC hdc, int cx, int cy, COLORREF color) {
|
|||
|
HPEN hPen = CreatePen(PS_SOLID, 2, color);
|
|||
|
SelectObject(hdc, hPen);
|
|||
|
|
|||
|
POINT p[5] = {
|
|||
|
cx, cy - 20,
|
|||
|
cx + 20, cy - 40,
|
|||
|
cx + 40, cy - 20,
|
|||
|
cx + 20, cy,
|
|||
|
cx, cy - 20,
|
|||
|
};
|
|||
|
Polyline(hdc, p, 5);
|
|||
|
|
|||
|
DeleteObject(hPen);
|
|||
|
}
|
|||
|
|
|||
|
void Image3(HDC hdc, int cx, int cy, COLORREF color) {
|
|||
|
HPEN hPen = CreatePen(PS_SOLID, 2, color);
|
|||
|
SelectObject(hdc, hPen);
|
|||
|
|
|||
|
POINT p[5] = {
|
|||
|
cx, cy,
|
|||
|
cx - 20, cy - 20,
|
|||
|
cx, cy + 20,
|
|||
|
cx + 20, cy -20,
|
|||
|
cx, cy,
|
|||
|
};
|
|||
|
Polyline(hdc, p, 5);
|
|||
|
|
|||
|
DeleteObject(hPen);
|
|||
|
}
|
|||
|
|
|||
|
void Image4(HDC hdc, int cx, int cy, COLORREF color) {
|
|||
|
HPEN hPen = CreatePen(PS_SOLID, 2, color);
|
|||
|
SelectObject(hdc, hPen);
|
|||
|
|
|||
|
POINT p[7] = {
|
|||
|
cx, cy,
|
|||
|
cx + 20, cy + 10,
|
|||
|
cx - 20, cy + 10,
|
|||
|
cx - 20, cy + 30,
|
|||
|
cx - 20, cy - 10,
|
|||
|
cx + 20, cy - 10,
|
|||
|
cx, cy
|
|||
|
};
|
|||
|
Polyline(hdc, p, 7);
|
|||
|
|
|||
|
DeleteObject(hPen);
|
|||
|
}
|
|||
|
|
|||
|
void Image5(HDC hdc, int cx, int cy, COLORREF color) {
|
|||
|
HPEN hPen = CreatePen(PS_SOLID, 2, color);
|
|||
|
SelectObject(hdc, hPen);
|
|||
|
|
|||
|
POINT p[7] = {
|
|||
|
cx, cy,
|
|||
|
cx + 20, cy + 10,
|
|||
|
cx + 20, cy - 10,
|
|||
|
cx, cy,
|
|||
|
cx - 20, cy + 10,
|
|||
|
cx - 20, cy - 10,
|
|||
|
cx, cy,
|
|||
|
};
|
|||
|
Polyline(hdc, p, 7);
|
|||
|
|
|||
|
DeleteObject(hPen);
|
|||
|
}
|
|||
|
|
|||
|
void Image6(HDC hdc, int cx, int cy, COLORREF color) {
|
|||
|
HPEN hPen = CreatePen(PS_SOLID, 2, color);
|
|||
|
SelectObject(hdc, hPen);
|
|||
|
|
|||
|
POINT p[10] = {
|
|||
|
cx - 40, cy + 20,
|
|||
|
cx - 30, cy - 10,
|
|||
|
cx - 20, cy + 10,
|
|||
|
cx - 10, cy - 20,
|
|||
|
cx, cy + 10,
|
|||
|
cx + 10, cy - 20,
|
|||
|
cx + 20, cy + 10,
|
|||
|
cx + 30, cy - 10,
|
|||
|
cx + 40, cy + 20,
|
|||
|
cx - 40, cy + 20,
|
|||
|
};
|
|||
|
|
|||
|
Polyline(hdc, p, 10);
|
|||
|
|
|||
|
DeleteObject(hPen);
|
|||
|
}
|
|||
|
|
|||
|
void PictureFLineY(HDC hdc, void(*pfImage)(HDC hdc, int cx, int cy, COLORREF color)) {
|
|||
|
short x = 40;
|
|||
|
short y = 40;
|
|||
|
char i = 0;
|
|||
|
while (i < 6) {
|
|||
|
pfImage(hdc, x, y, RGB(255, 0, 0));
|
|||
|
y += 50;
|
|||
|
i++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
void Picture0(HDC hdc) {
|
|||
|
Image0(hdc, 40, 40, RGB(255, 0, 0)); // Код был в лекции
|
|||
|
Image0(hdc, 140, 40, RGB(255, 0, 0));
|
|||
|
Image0(hdc, 240, 40, RGB(255, 0, 0));
|
|||
|
Image0(hdc, 240, 240, RGB(255, 0, 0));
|
|||
|
Image0(hdc, 40, 240, RGB(255, 0, 0));
|
|||
|
}
|
|||
|
|
|||
|
void Picture1(HDC hdc) {
|
|||
|
Image1(hdc, 40, 40, RGB(255, 0, 0));
|
|||
|
Image1(hdc, 140, 40, RGB(255, 0, 0));
|
|||
|
Image1(hdc, 240, 40, RGB(255, 0, 0));
|
|||
|
Image1(hdc, 240, 240, RGB(255, 0, 0));
|
|||
|
Image1(hdc, 40, 240, RGB(255, 0, 0));
|
|||
|
}
|
|||
|
|
|||
|
void Romb1(HDC hdc) {
|
|||
|
Image2(hdc, 40, 40, RGB(255, 0, 0));
|
|||
|
Image2(hdc, 140, 40, RGB(255, 0, 0));
|
|||
|
Image2(hdc, 240, 40, RGB(255, 0, 0));
|
|||
|
Image2(hdc, 240, 240, RGB(255, 0, 0));
|
|||
|
Image2(hdc, 40, 240, RGB(255, 0, 0));
|
|||
|
}
|
|||
|
|
|||
|
void CheckMark(HDC hdc) {
|
|||
|
Image3(hdc, 40, 40, RGB(255, 0, 0));
|
|||
|
Image3(hdc, 140, 40, RGB(255, 0, 0));
|
|||
|
Image3(hdc, 240, 40, RGB(255, 0, 0));
|
|||
|
Image3(hdc, 240, 240, RGB(255, 0, 0));
|
|||
|
Image3(hdc, 40, 240, RGB(255, 0, 0));
|
|||
|
}
|
|||
|
|
|||
|
void Flag1(HDC hdc) {
|
|||
|
Image4(hdc, 40, 40, RGB(255, 0, 0));
|
|||
|
Image4(hdc, 140, 40, RGB(255, 0, 0));
|
|||
|
Image4(hdc, 240, 40, RGB(255, 0, 0));
|
|||
|
Image4(hdc, 240, 240, RGB(255, 0, 0));
|
|||
|
Image4(hdc, 40, 240, RGB(255, 0, 0));
|
|||
|
}
|
|||
|
|
|||
|
void Infinity(HDC hdc) {
|
|||
|
Image5(hdc, 40, 40, RGB(255, 0, 0));
|
|||
|
Image5(hdc, 140, 40, RGB(255, 0, 0));
|
|||
|
Image5(hdc, 240, 40, RGB(255, 0, 0));
|
|||
|
Image5(hdc, 240, 240, RGB(255, 0, 0));
|
|||
|
Image5(hdc, 40, 240, RGB(255, 0, 0));
|
|||
|
}
|
|||
|
|
|||
|
void Crown(HDC hdc) {
|
|||
|
Image6(hdc, 40, 40, RGB(255, 0, 0));
|
|||
|
Image6(hdc, 140, 40, RGB(255, 0, 0));
|
|||
|
Image6(hdc, 240, 40, RGB(255, 0, 0));
|
|||
|
Image6(hdc, 240, 240, RGB(255, 0, 0));
|
|||
|
Image6(hdc, 40, 240, RGB(255, 0, 0));
|
|||
|
}
|
|||
|
|
|||
|
void Picture4Lines(HDC hdc) {
|
|||
|
short y = 40;
|
|||
|
char i = 0;
|
|||
|
|
|||
|
while (i < 6) {
|
|||
|
short x = 40;
|
|||
|
char j = 0;
|
|||
|
while (j < 10) {
|
|||
|
Image4(hdc, x, y, RGB(255, 0, 0));
|
|||
|
x += 50;
|
|||
|
j++;
|
|||
|
}
|
|||
|
y += 50;
|
|||
|
i++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void Picture4ColorLines(HDC hdc) {
|
|||
|
unsigned char r = 255;
|
|||
|
unsigned char g = 0;
|
|||
|
short y = 40;
|
|||
|
char i = 0;
|
|||
|
|
|||
|
while (i < 6) {
|
|||
|
short x = 40;
|
|||
|
char j = 0;
|
|||
|
unsigned char b = 0;
|
|||
|
|
|||
|
while (j < 10) {
|
|||
|
Image4(hdc, x, y, RGB(r, g, b));
|
|||
|
x += 50;
|
|||
|
j++;
|
|||
|
|
|||
|
b += 25;
|
|||
|
}
|
|||
|
y += 50;
|
|||
|
i++;
|
|||
|
|
|||
|
g += 50;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
enum Modes {
|
|||
|
image0,
|
|||
|
image1,
|
|||
|
romb1,
|
|||
|
checkMark,
|
|||
|
flag1,
|
|||
|
image1_line,
|
|||
|
//image1_with_colors,
|
|||
|
image2,
|
|||
|
infinity,
|
|||
|
crown,
|
|||
|
//image2_with_colors,
|
|||
|
//image3,
|
|||
|
//image3_lines,
|
|||
|
//image3_with_colors,
|
|||
|
//image4,
|
|||
|
image4_lines,
|
|||
|
image4_with_colors,
|
|||
|
mode_none
|
|||
|
};
|
|||
|
|
|||
|
enum Modes mode = image0;
|
|||
|
|
|||
|
|
|||
|
//
|
|||
|
// ФУНКЦИЯ: 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_LAB111OAIPPROKONOVKIRILL));
|
|||
|
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
|||
|
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
|||
|
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_LAB111OAIPPROKONOVKIRILL);
|
|||
|
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_KEYDOWN:
|
|||
|
mode = (enum Modes)(mode + 1); // переключение на следующий режим
|
|||
|
if (mode == mode_none) mode = image0; // если режимы закончились - начинаем заново
|
|||
|
InvalidateRect(hWnd, NULL, TRUE);
|
|||
|
break;
|
|||
|
case WM_PAINT:
|
|||
|
{
|
|||
|
PAINTSTRUCT ps;
|
|||
|
HDC hdc = BeginPaint(hWnd, &ps);
|
|||
|
// TODO: Добавьте сюда любой код прорисовки, использующий HDC...
|
|||
|
|
|||
|
switch (mode) {
|
|||
|
case image0:
|
|||
|
Picture0(hdc); // Код выше
|
|||
|
break;
|
|||
|
case image1:
|
|||
|
Picture1(hdc); // Код выше
|
|||
|
break;
|
|||
|
case romb1:
|
|||
|
Romb1(hdc); // Код выше
|
|||
|
break;
|
|||
|
case checkMark:
|
|||
|
CheckMark(hdc); // Код выше
|
|||
|
break;
|
|||
|
case flag1:
|
|||
|
Flag1(hdc); // Код выше
|
|||
|
break;
|
|||
|
case image1_line:
|
|||
|
PictureFLineY(hdc, Image1); // Код был в лекции
|
|||
|
break;
|
|||
|
case image2:
|
|||
|
PictureFLineY(hdc, Image2); // Код был в лекции
|
|||
|
break;
|
|||
|
case infinity:
|
|||
|
Infinity(hdc); // Код был в лекции
|
|||
|
break;
|
|||
|
case image4_lines:
|
|||
|
Picture4Lines(hdc);
|
|||
|
break;
|
|||
|
case image4_with_colors:
|
|||
|
Picture4ColorLines(hdc);
|
|||
|
break;
|
|||
|
case crown:
|
|||
|
Crown(hdc);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
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;
|
|||
|
}
|