1/67.cpp
Адель Алимов 957758f360 123
2024-11-18 08:58:23 +04:00

296 lines
7.2 KiB
C++

// ëàáà 6.cpp : Îïðåäåëÿåò òî÷êó âõîäà äëÿ ïðèëîæåíèÿ.
//
#include "framework.h"
#include "ëàáà 6.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_MY6, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Âûïîëíèòü èíèöèàëèçàöèþ ïðèëîæåíèÿ:
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MY6));
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_MY6));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_MY6);
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);
// TODO: Äîáàâüòå ñþäà ëþáîé êîä ïðîðèñîâêè, èñïîëüçóþùèé HDC...
int x1 = 447, y1 = 128;
int x2 = 447, y2 = 332;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
x1 -= 10;
y1 += 10;
x2 += 10;
y2 -= 10;
} while (x2 <= 600);
x1 = 390, y1 = 570;
x2 = 550, y2 = 570;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
x1 += 10;
y2 -= 7;
} while (y2 >= 455);
x1 = 750, y1 = 570;
x2 = 750, y2 = 452;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
x2 -= 5;
y1 -= 5;
y2 += 5;
} while (x2 >= 670);
x1 = 950, y1 = 570;
x2 = 1050, y2 = 570;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
y1 -= 5;
y2 += 10;
} while (y1 >= 500);
x1 = 950, y1 = 170;
x2 = 1000, y2 = 150;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
y2 -= 7;
x1 -= 7;
} while (y2 >= 80);
x1 = 750, y1 = 170;
x2 = 750, y2 = 370;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
x1 += 7;
x2 -= 7;
} while (x2 >= 650);
x1 = 150, y1 = 170;
x2 = 150, y2 = 370;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
x1 += 5;
y2 -= 5;
} while (x1 <= 300);
x1 = 150, y1 = 470;
x2 = 150, y2 = 670;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
x1 += 5;
x2 += 5;
y1 -= 5;
y2 += 5;
} while (x1 <= 200);
x1 = 150, y1 = 70;
x2 = 150, y2 = 130;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
x1 += 5;
x2 += 5;
y1 += 5;
y2 -= 5;
} while (x1 <= 180);
x1 = 220, y1 = 60;
x2 = 220, y2 = 140;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
x1 -= 5;
x2 -= 5;
y1 += 5;
y2 -= 5;
} while (x1 >= 180);
x1 = 1220, y1 = 60;
x2 = 1340, y2 = 160;
do {
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
x1 += 10;
x2 += 3;
y2 -= 5;
y1 += 5;
} while (x1 <= 1440);
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;
}