376 lines
9.4 KiB
C++
376 lines
9.4 KiB
C++
// tasks.cpp : Определяет точку входа для приложения.
|
||
//
|
||
|
||
#include "framework.h"
|
||
#include "tasks.h"
|
||
|
||
#define MAX_LOADSTRING 100
|
||
//обчные треугольники (разноцветные
|
||
void Im0(HDC hdc, int cx, int cy, COLORREF color) {
|
||
HPEN 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 Im1(HDC hdc, int cx, int cy, COLORREF color) {
|
||
HPEN hPen;
|
||
hPen = CreatePen(PS_SOLID, 2, color);
|
||
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 Im2(HDC hdc, int cx, int cy, COLORREF color) {
|
||
HPEN hPen;
|
||
hPen = CreatePen(PS_SOLID, 2, color);
|
||
SelectObject(hdc, hPen);
|
||
|
||
POINT p[5];
|
||
p[0].x = cx;
|
||
p[0].y = cy - 20;
|
||
p[1].x = cx + 20;
|
||
p[1].y = cy;
|
||
p[2].x = cx;
|
||
p[2].y = cy + 20;
|
||
p[3].x = cx - 20;
|
||
p[3].y = cy;
|
||
p[4].x = cx;
|
||
p[4].y = cy - 20;
|
||
|
||
Polyline(hdc, p, 5);
|
||
DeleteObject(hPen);
|
||
}
|
||
|
||
void Im3(HDC hdc, int cx, int cy, COLORREF color) {
|
||
HPEN hPen;
|
||
hPen = CreatePen(PS_SOLID, 2, color);
|
||
SelectObject(hdc, hPen);
|
||
|
||
POINT p[5] = {
|
||
cx + 20, cy - 20,
|
||
cx, cy + 20,
|
||
cx - 20, cy - 20,
|
||
cx, cy,
|
||
cx + 20, cy - 20,
|
||
};
|
||
|
||
Polyline(hdc, p, 5);
|
||
DeleteObject(hPen);
|
||
}
|
||
|
||
void Im4(HDC hdc, int cx, int cy, COLORREF color) {
|
||
HPEN hPen;
|
||
hPen = CreatePen(PS_SOLID, 2, color);
|
||
SelectObject(hdc, hPen);
|
||
|
||
POINT p[5] = {
|
||
cx + 20, cy - 20,
|
||
cx, cy + 20,
|
||
cx - 20, cy - 20,
|
||
cx, cy,
|
||
cx + 20, cy - 20,
|
||
};
|
||
|
||
Polyline(hdc, p, 5);
|
||
DeleteObject(hPen);
|
||
}
|
||
|
||
|
||
struct Image {
|
||
int x;
|
||
int y;
|
||
int vx;
|
||
int vy;
|
||
COLORREF color;
|
||
};
|
||
|
||
// Глобальные переменные:
|
||
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);
|
||
|
||
struct Image im1 = { 200, 200, 10, 0, RGB(128, 128, 0) };
|
||
|
||
struct Image im2 = { 400, 100, -10, 0, RGB(45, 100, 87) };
|
||
|
||
struct Image im3 = { 100, 200, 0, 10, RGB(0, 100, 98) };
|
||
|
||
struct Image im4 = { 120, 500, 0, -10, RGB(255, 100, 0) };
|
||
|
||
struct Image im5[3] = {
|
||
{500, 100, 10, 5, RGB(150, 100, 100)},
|
||
{500, 100, 0, 10, RGB(150, 100, 100)},
|
||
{500, 100, -10, 5, RGB(150, 100, 100)},
|
||
};
|
||
|
||
|
||
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_TASKS, szWindowClass, MAX_LOADSTRING);
|
||
MyRegisterClass(hInstance);
|
||
|
||
// Выполнить инициализацию приложения:
|
||
if (!InitInstance (hInstance, nCmdShow))
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TASKS));
|
||
|
||
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_TASKS));
|
||
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_TASKS);
|
||
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;
|
||
}
|
||
|
||
|
||
|
||
void Image1(HDC hdc, int cx, int cy, COLORREF color) {
|
||
HPEN 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;
|
||
hPen = CreatePen(PS_SOLID, 2, color);
|
||
SelectObject(hdc, hPen);
|
||
|
||
POINT p[5] = {
|
||
cx, cy - 20,
|
||
cx + 20, cy,
|
||
cx, 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;
|
||
hPen = CreatePen(PS_SOLID, 2, color);
|
||
SelectObject(hdc, hPen);
|
||
|
||
POINT p[5] = {
|
||
cx, cy - 20,
|
||
cx + 20, cy,
|
||
cx + 40, cy - 20,
|
||
cx + 20, cy + 20,
|
||
cx, cy - 20
|
||
};
|
||
Polyline(hdc, p, 5);
|
||
DeleteObject(hPen);
|
||
}
|
||
//
|
||
// ФУНКЦИЯ: 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_CREATE:
|
||
SetTimer(hWnd, 1, 500, 0);
|
||
break;
|
||
|
||
case WM_TIMER:
|
||
|
||
im1.x += im1.vx;
|
||
im1.y += im1.vy;
|
||
im2.x += im2.vx;
|
||
im2.y += im2.vy;
|
||
im3.x += im3.vx;
|
||
im3.y += im3.vy;
|
||
im4.x += im4.vx;
|
||
im4.y += im4.vy;
|
||
|
||
im5[0].x += im5[0].vx;
|
||
im5[0].y += im5[0].vy;
|
||
|
||
im5[1].x += im5[1].vx;
|
||
im5[1].y += im5[1].vy;
|
||
|
||
im5[2].x += im5[2].vx;
|
||
im5[2].y += im5[2].vy;
|
||
|
||
InvalidateRect(hWnd, NULL, TRUE);
|
||
break;
|
||
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);
|
||
|
||
Im0(hdc, im1.x, im1.y, im1.color);
|
||
Im1(hdc, im2.x, im2.y, im2.color);
|
||
Im2(hdc, im3.x, im3.y, im1.color);
|
||
Im3(hdc, im4.x, im4.y, im1.color);
|
||
Im4(hdc, im5[0].x, im5[0].y, im5[0].color);
|
||
Im4(hdc, im5[1].x, im5[1].y, im5[1].color);
|
||
Im4(hdc, im5[2].x, im5[2].y, im5[2].color);
|
||
|
||
|
||
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;
|
||
}
|