Documente Academic
Documente Profesional
Documente Cultură
Lab 3 Ppe
Lab 3 Ppe
Raport la
Lucrarea de laborator Nr. 3
Disciplina: Programarea pilotată de evenimente
Au efectuat:
A verificat:
Chișinău – 2021
Obiective:
#include "framework.h"
#include "Nastea.h"
// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
bool bezier1 = false;
bool bezier2 = false;
POINT Pt[4] = { { 100, 48 }, { 88, 246 }, { 364, 192 }, { 250, 48 } };
int varvar = 0;
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 CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
HMENU hMenubar = CreateMenu();
HMENU hFile = CreateMenu();
HMENU hOptions = CreateMenu();
switch (message)
{
case WM_CREATE: {
HMENU hMenubar = CreateMenu();
HMENU hFile = CreateMenu();
HMENU hOptions = CreateMenu();
SetMenu(hWnd, hMenubar);
break;
}
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case IDM_BEZ1:
bezier2 = false;
bezier1 = true;
InvalidateRect(hWnd, NULL, TRUE);
break;
case IDM_BEZ2:
bezier2 = true;
bezier1 = false;
InvalidateRect(hWnd, NULL, TRUE);
break;
case IDM_CLEAR:
bezier2 = false;
bezier1 = false;
InvalidateRect(hWnd, NULL, TRUE);
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
if (bezier1)
PolyBezier(hdc, Pt, 4);
else if (bezier2)
mybezier(hdc, Pt);
EndPaint(hWnd, &ps);
}
break;
case WM_KEYDOWN:
switch (wParam)
{
case VK_NUMPAD8:
Pt[3].y--;
InvalidateRect(hWnd, NULL, TRUE);
break;
case VK_NUMPAD2:
Pt[3].y++;
InvalidateRect(hWnd, NULL, TRUE);
break;
case VK_NUMPAD6:
Pt[3].x++;
InvalidateRect(hWnd, NULL, TRUE);
break;
case VK_NUMPAD4:
Pt[3].x--;
InvalidateRect(hWnd, NULL, TRUE);
break;
case VK_UP:
Pt[0].y--;
InvalidateRect(hWnd, NULL, TRUE);
break;
case VK_DOWN:
Pt[0].y++;
InvalidateRect(hWnd, NULL, TRUE);
break;
case VK_RIGHT:
Pt[0].x++;
InvalidateRect(hWnd, NULL, TRUE);
break;
case VK_LEFT:
Pt[0].x--;
InvalidateRect(hWnd, NULL, TRUE);
break;
default:
break;
}
break;
case WM_MOUSEMOVE:
if (GetKeyState(MK_RBUTTON))
{
Pt[varvar].x = LOWORD(lParam);
Pt[varvar].y = HIWORD(lParam);
InvalidateRect(hWnd, NULL, TRUE);
}
break;
case WM_LBUTTONDOWN:
if (varvar == 3) varvar = -1;
varvar++;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
Rezultatul programului:
Fig.1 – Curba Bezier modificata cu ajutorul tastaturii si a mouse-ului