Lucrarea de Laborator Nr. 2: Raport La
Lucrarea de Laborator Nr. 2: Raport La
Raport la
Lucrarea de laborator Nr. 2
Disciplina: Programarea pilotată de evenimente
Au efectuat:
A verificat:
Chișinău – 2021
Sarcina: Scrieţi un program care afişează în zona client un desen animat,
utilizând toate primitivele GDI.
#include "framework.h"
#include "laboratorul 2.h"
// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
RECT rcCurrent = { 0,0,20,20 };
POINT aptStar[6] = { 10,1, 1,19, 19,6, 1,6, 19,19, 10,1 };
int X = 2, Y = -1, idTimer = -1;
BOOL fVisible = FALSE;
HDC hdc;
MSG msg;
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
return RegisterClassExW(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT APIENTRY WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
RECT rc;
RECT rc2;
HBRUSH hBrush1 = CreateSolidBrush(RGB(235, 200, 21, 0));
HBRUSH hBrush2 = CreateSolidBrush(RGB(255, 255, 255, 255));
switch (message)
{
case WM_CREATE:
GetClientRect(hwnd, &rc);
OffsetRect(&rcCurrent, rc.right / 2, rc.bottom / 2);
hdc = GetDC(hwnd);
SetViewportOrgEx(hdc, rcCurrent.left,
rcCurrent.top, NULL);
SetROP2(hdc, R2_NOT);
case WM_DESTROY:
KillTimer(hwnd, 1);
PostQuitMessage(0);
return 0L;
case WM_SIZE:
switch (wParam)
{
case SIZE_MINIMIZED:
KillTimer(hwnd, 1);
idTimer = -1;
break;
case SIZE_RESTORED:
case SIZE_MAXIMIZED:
if (idTimer == -1)
SetTimer(hwnd, idTimer = 1, 10, NULL);
break;
}
return 0L;
case WM_TIMER:
if (fVisible)
Ellipse(hdc, 0, 20, 40, 60);
GetClientRect(hwnd, &rc);
if (rcCurrent.left + X < rc.left ||
rcCurrent.right + X > rc.right)
X = -X;
if (rcCurrent.top + Y < rc.top ||
rcCurrent.bottom + Y > rc.bottom)
Y = -Y;
OffsetRect(&rcCurrent, X, Y);
SetViewportOrgEx(hdc, rcCurrent.left,
rcCurrent.top, NULL);
fVisible = Ellipse(hdc, 0, 20, 40, 60);
return 0L;
case WM_ERASEBKGND:
fVisible = FALSE;
return DefWindowProc(hwnd, message, wParam, lParam);
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
if (!fVisible) {
SelectObject(hdc, hBrush2);
SetPolyFillMode(hdc, WINDING);
fVisible = Polyline(hdc, aptStar, 6);
SelectObject(hdc, hBrush1);
Ellipse(hdc, 0, 50, 100, 150);
RoundRect(hdc, 100, 150, 200, 250, 20, 20);
Rectangle(hdc, 200, 250, 300, 350);
Pie(hdc,300, 350, 400, 450, 300, 350, 450, 500);
}
EndPaint(hwnd, &ps);
return 0L;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;