Raport: Lucrarea de Laborator nr.2 [PDF]

  • 0 0 0
  • Gefällt Ihnen dieses papier und der download? Sie können Ihre eigene PDF-Datei in wenigen Minuten kostenlos online veröffentlichen! Anmelden
Datei wird geladen, bitte warten...
Zitiervorschau

Ministerul Educației al Republicii Moldova Universitatea Tehnică a Moldovei Facultatea Calculatoare, Informatică şi Microelectronică Departamentul Ingineria Software şi Automatică

Raport Lucrarea de laborator nr.2 Disciplina: Programarea Pilotată de Evenimente

A efectuat:

st. gr. Ploaia Dan

A verificat

conf.univ. Cojocaru Svetlana

Chișinău - 2020

Tema: “Interfața GDI”

Scopul lucrării: De studiat primitivele oferite de interfaţa GDI. Sarcina lucrării: Scrieţi un program care afişează în zona client un desen animat, utilizând toate primitivele GDI.

Listingul programului: #include LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = "HelloWin"; HWND hwnd; MSG msg; WNDCLASSEX wndclass; wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wndclass); hwnd = CreateWindow(szAppName, // window class name "Labroratorul nr.2 la Programarea Pilotata de Evenimente ", caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) {

// window

TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc, hCompatibleDC; PAINTSTRUCT ps; RECT rect; HBRUSH BrushRed = CreateSolidBrush(RGB(255, 2, 5)); HBRUSH BrushBlack = CreateSolidBrush(RGB(0, 0, 0)); HBRUSH BrushYellow = CreateSolidBrush(RGB(255, 255, 0)); HBRUSH BrushWhite = CreateSolidBrush(RGB(255, 255, 255)); HBRUSH BrushGreen = CreateSolidBrush(RGB(4, 167, 0)); HBRUSH BrushBrown = CreateSolidBrush(RGB(51, 13, 0)); HBRUSH BrushLime = CreateSolidBrush(RGB(51, 239, 0)); HANDLE hOldBitmap; HANDLE hBitmap; BITMAP Bitmap; HFONT font; LOGFONT LogFont;

POINT Pt[6]; Pt[0].x Pt[0].y Pt[1].x Pt[1].y Pt[2].x Pt[2].y Pt[3].x Pt[3].y Pt[4].x Pt[4].y Pt[5].x Pt[5].y

= = = = = = = = = = = =

170; 137; 230; 160; 280; 140; 288; 162; 230; 170; 163; 157;

switch (iMsg) { // case WM_CREATE : //PlaySound ("hellowin.wav", NULL, SND_FILENAME | SND_ASYNC) ;// //return 0 ; case WM_PAINT:

hdc = BeginPaint(hwnd, &ps); HPEN hPenOld; SelectObject(hdc, BrushGreen); HPEN hRectanglePen; COLORREF qRectangleColor; qRectangleColor = RGB(0, 0, 0); hRectanglePen = CreatePen(PS_SOLID, 3, qRectangleColor);

hPenOld = (HPEN)SelectObject(hdc, hRectanglePen); Rectangle(hdc,-10, 450, 1010, 610); DeleteObject(hRectanglePen); SelectObject(hdc, BrushBrown); Rectangle(hdc,600, 300, 1100, 350); Rectangle(hdc,650, 350, 700, 610); DeleteObject(hRectanglePen); //Ellipse HPEN hEllipse1Pen; COLORREF qEllipse1Color; qEllipse1Color = RGB(0, 0, 0); hEllipse1Pen = CreatePen(PS_SOLID, 3, qEllipse1Color); hPenOld = (HPEN)SelectObject(hdc, hEllipse1Pen); SelectObject(hdc, BrushRed); Ellipse(hdc, 107, 50, 200, 80); Ellipse(hdc, 165, 18, 205, 95); DeleteObject(hEllipse1Pen);

//Draw a ellipse HPEN hEllipsePen; COLORREF qEllipseColor; qEllipseColor = RGB(0, 0, 0); hEllipsePen = CreatePen(PS_SOLID, 3, qEllipseColor); hPenOld = (HPEN)SelectObject(hdc, hEllipsePen); SelectObject(hdc, BrushRed); Ellipse(hdc, 67, 74, 296, 282);

DeleteObject(hEllipsePen); HPEN hEllipse2Pen; COLORREF qEllipse2Color; qEllipse2Color = RGB(0, 0, 0); hEllipse2Pen = CreatePen(PS_SOLID, 3, qEllipse2Color); hPenOld = (HPEN) SelectObject(hdc, hEllipse2Pen); SelectObject(hdc, BrushWhite); Ellipse(hdc, 180, 155, 230, 203); Ellipse(hdc, 230, 155, 273, 200); qEllipse2Color = RGB(255, 255, 0); hEllipse2Pen = CreatePen(PS_SOLID, 3, qEllipse2Color); hPenOld = (HPEN)SelectObject(hdc, hEllipse2Pen); SelectObject(hdc, BrushYellow); Ellipse(hdc,460, 25, 600, 156); qEllipse2Color = RGB(255, 255, 255); hEllipse2Pen = CreatePen(PS_SOLID, 3, qEllipse2Color); hPenOld = (HPEN)SelectObject(hdc, hEllipse2Pen); SelectObject(hdc, BrushWhite); Ellipse(hdc, 340, 67, 555, 120); Ellipse(hdc, 380, 50, 460, 95); Ellipse(hdc, 428, 39, 503, 80); Ellipse(hdc, 400, 100, 512, 138); Ellipse(hdc,367, 90, 420, 130);

Ellipse(hdc, Ellipse(hdc, Ellipse(hdc, Ellipse(hdc, Ellipse(hdc,

695, 737, 785, 755, 725,

45, 33, 36, 50, 65,

790, 823, 850, 873, 792,

77); 70); 62); 90); 88);

qEllipse2Color = RGB(0, 0, 0); hEllipse2Pen = CreatePen(PS_SOLID, 3, qEllipse2Color); hPenOld = (HPEN)SelectObject(hdc, hEllipse2Pen); SelectObject(hdc, BrushGreen); Ellipse(hdc,777, 95, 818, 150); Ellipse(hdc,850, 80, 882, 128); Ellipse(hdc,747, 104, 971, 310); SelectObject(hdc, BrushLime); Ellipse(hdc, 830, 200, 890, 260); Ellipse(hdc, 810, 170, 910, 240); DeleteObject(hEllipse2Pen); //Line HPEN hLinePen; COLORREF qLineColor; qLineColor = RGB(0, 0, 0); hLinePen = CreatePen(PS_SOLID, 3, qLineColor); hPenOld = (HPEN)SelectObject(hdc, hLinePen); SelectObject(hdc, NULL); MoveToEx(hdc,176, 0,NULL); LineTo(hdc, 372, 132);

MoveToEx(hdc, 20, 318,NULL); LineTo(hdc, 336, 264); MoveToEx(hdc, 2, 8, NULL); LineTo(hdc, 94, 74); MoveToEx(hdc, 0, 103, NULL); LineTo(hdc, 53, 113); MoveToEx(hdc, 7, 190, NULL); LineTo(hdc, 48, 210); MoveToEx(hdc, 2, 265, NULL); LineTo(hdc, 64, 257); DeleteObject(hLinePen); HPEN hEllipse3Pen; COLORREF qEllipse3Color; qEllipse3Color = RGB(0, 0, 0); hEllipse3Pen = CreatePen(PS_SOLID, 3, qEllipse3Color); hPenOld = (HPEN)SelectObject(hdc, hEllipse3Pen); SelectObject(hdc, BrushBlack); Ellipse(hdc, 203, 172, 218, 186); Ellipse(hdc, 236, 173, 250, 186); SelectObject(hdc, BrushWhite); Ellipse(hdc,758, 185, 808, 230); Ellipse(hdc,912, 185, 960, 230); SelectObject(hdc, BrushBlack); Ellipse(hdc, 770, 200, 785, 215); Ellipse(hdc,923, 200, 940, 215); Ellipse(hdc,830, 197, 845, 215);

Ellipse(hdc,870, 200, 885, 215); DeleteObject(hEllipse3Pen);

HPEN hPolygon2Pen; COLORREF qPolygon2Color; qPolygon2Color = RGB(0, 0, 0); hPolygon2Pen = CreatePen(PS_SOLID, 3, qPolygon2Color); hPenOld = (HPEN)SelectObject(hdc, hPolygon2Pen); SelectObject(hdc, BrushYellow); POINT Pt2[6]; Pt2[0].x Pt2[0].y Pt2[1].x Pt2[1].y Pt2[2].x Pt2[2].y Pt2[3].x Pt2[3].y Pt2[4].x Pt2[4].y Pt2[5].x Pt2[5].y

= = = = = = = = = = = =

190; 220; 229; 185; 275; 228; 190; 220; 225; 257; 259; 229;

Polygon(hdc, Pt2, 6); SelectObject(hdc, hPenOld); DeleteObject(hPolygon2Pen); //Polygon SelectObject(hdc, BrushBlack); HPEN hPolygonPen; COLORREF qPolygonColor; qPolygonColor = RGB(0, 0, 0); hPolygonPen = CreatePen(PS_SOLID, 3, qPolygonColor); hPenOld = (HPEN)SelectObject(hdc, hPolygonPen);

Polygon(hdc, Pt, 6); DeleteObject(hPolygonPen);

//-----------------SelectObject(hdc, BrushBlack); HPEN hPolygon1Pen; COLORREF qPolygon1Color; qPolygon1Color = RGB(0, 0, 0); hPolygon1Pen = CreatePen(PS_SOLID, 3, qPolygon1Color); hPenOld = (HPEN)SelectObject(hdc, hPolygon1Pen); POINT Pt[10]; Pt[0].x = 73;

Pt[0].y = 157; Pt[1].x = 60; Pt[1].y = 135; Pt[2].x = 50; Pt[2].y = 145; Pt[3].x = 60; Pt[3].y = 160; Pt[4].x = 37; Pt[4].y = 147; Pt[5].x = 32; Pt[5].y = 166; Pt[6].x = 55; Pt[6].y = 172; Pt[7].x = 45; Pt[7].y = 180; Pt[8].x = 50; Pt[8].y = 190; Pt[9].x = 67; Pt[9].y = 178; Polygon(hdc, Pt, 10); DeleteObject(hPolygon1Pen); SetBkMode(hdc, TRANSPARENT); LogFont.lfStrikeOut = 0; LogFont.lfUnderline = 0; LogFont.lfHeight = 82; LogFont.lfEscapement = 0; font = CreateFontIndirect(&LogFont); SelectObject(hdc, font); TextOut(hdc, 80, 340, "Angry Birds", 11);

EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, iMsg, wParam, lParam); }

Rezultatul programului:

Fig.1 – Desenul afisat in zona client

Concluzie: In urma efectuarii acestei lucrari de laborator am studiat bazele şi principiile de functionare a functiilor GDI.Am invatat sa folosim resursele acestei biblioteci pentru a desena diferite figuri utilizind primitivele GDI.