You are on page 1of 7

Ploaia Dan TI-181

Aceasta lucrare a fost verificata cu o nota de 9!


Tema: “Grafica de tip rastru si vectoriala si realizarea scenelor 2D

Listingul programului:
#include <windows.h>
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 Programarea Pilotata pe evenimente ", // window
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))
{
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 = 170;
Pt[0].y = 137;
Pt[1].x = 230;
Pt[1].y = 160;
Pt[2].x = 280;
Pt[2].y = 140;
Pt[3].x = 288;
Pt[3].y = 162;
Pt[4].x = 230;
Pt[4].y = 170;
Pt[5].x = 163;
Pt[5].y = 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, 695, 45, 790, 77);
Ellipse(hdc, 737, 33, 823, 70);
Ellipse(hdc, 785, 36, 850, 62);
Ellipse(hdc, 755, 50, 873, 90);
Ellipse(hdc, 725, 65, 792, 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 = 190;
Pt2[0].y = 220;
Pt2[1].x = 229;
Pt2[1].y = 185;
Pt2[2].x = 275;
Pt2[2].y = 228;
Pt2[3].x = 190;
Pt2[3].y = 220;
Pt2[4].x = 225;
Pt2[4].y = 257;
Pt2[5].x = 259;
Pt2[5].y = 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:

You might also like