Visual Studio - GDI și animație

Previzualizare laborator:

Extras din laborator:

1.Tema : Interfaţa GDI

2.Scopul lucrarii : De a studia primitivele oferite de interfaţa GDI

3.Listingul pogramului :

#include <windows.h>

int i,j,dir;

int a[3][6] ={ {123,343,100,163,232,166},{128,15,129,74,234,255},{1,2,3,4,1,4} };

int circle(HWND hwnd,HDC hdc,int i, int j, int dir, RECT rect,int nr)

{

HPEN hBluePen,hRedPen,hYellowPen,hGreenPen,hVioletPen,hOrangePen;

HBRUSH hRedBrush,hBlueBrush,hYellowBrush,hGreenBrush,hVioletBrush,hOrangeBrush;

hBluePen = CreatePen ( PS_SOLID, 1, RGB(0,0,255) );

hRedPen = CreatePen ( PS_SOLID, 1, RGB(255,0,0) );

hGreenPen = CreatePen ( PS_SOLID, 1, RGB(0,255,0) );

hYellowPen = CreatePen ( PS_SOLID, 1, RGB(255,255,0) );

hVioletPen = CreatePen ( PS_SOLID, 1, RGB(255,0,255) );

hOrangePen = CreatePen ( PS_SOLID, 1, RGB(255,90,0) );

hRedBrush = CreateSolidBrush (RGB(255,0,0));

hBlueBrush = CreateSolidBrush (RGB(0,0,255));

hGreenBrush = CreateSolidBrush (RGB(0,255,0));

hYellowBrush = CreateSolidBrush (RGB(255,255,0));

hVioletBrush = CreateSolidBrush (RGB(255,0,255));

hOrangeBrush = CreateSolidBrush (RGB(255,90,0));

if(j+150>rect.bottom)

{

if(dir==1)a[2][nr]=2;else a[2][nr]=3;

}

if(i+150>rect.right)

{

if(dir==2)a[2][nr]=3;else a[2][nr]=4;

}

if(j+50<rect.top)

{

if(dir==3)a[2][nr]=4;else a[2][nr]=1;

}

if(i+50<rect.left)

{

if(dir==4)a[2][nr]=1;else a[2][nr]=2;

}

switch(a[2][nr])

{

case 1:{

a[0][nr]++; a[1][nr]++;break;

}

case 2:{

a[0][nr]++; a[1][nr]--;break;

}

case 3:{

a[0][nr]--; a[1][nr]--;break;

}

case 4:{

a[0][nr]--; a[1][nr]++;break;

}

}

switch(nr)

{

case 0:{SelectObject(hdc,hYellowPen); SelectObject(hdc,hRedBrush); break;}

case 1:{SelectObject(hdc,hBluePen); SelectObject(hdc,hGreenBrush); break;}

case 2:{SelectObject(hdc,hRedPen) ; SelectObject(hdc,hYellowBrush); break;}

case 3:{SelectObject(hdc,hGreenPen); SelectObject(hdc,hBlueBrush); break;}

case 4:{SelectObject(hdc,hOrangePen); SelectObject(hdc,hVioletBrush); break;}

case 5:{SelectObject(hdc,hVioletPen); SelectObject(hdc,hOrangeBrush); break;}

}

Ellipse (hdc,a[0][nr]+50,a[1][nr]+50,a[0][nr]+150,a[1][nr]+150);

DeleteObject(hBluePen);

DeleteObject(hRedPen);

DeleteObject(hYellowPen);

DeleteObject(hGreenPen);

DeleteObject(hVioletPen);

DeleteObject(hOrangePen);

DeleteObject(hRedBrush);

DeleteObject(hGreenBrush);

DeleteObject(hYellowBrush);

DeleteObject(hBlueBrush);

DeleteObject(hVioletBrush);

DeleteObject(hOrangeBrush);

return dir;

}

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

PSTR szCmdLine, int iCmdShow)

{

static TCHAR szAppName[] = TEXT ("Windows - Lab2 Motion") ;

HWND hwnd ;

MSG msg ;

WNDCLASS 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 (WHITE_BRUSH) ;

wndclass.lpszMenuName = NULL ;

wndclass.lpszClassName = szAppName ;

RegisterClass(&wndclass);

hwnd = CreateWindow (szAppName,

TEXT ("Windows - Lab2 Motion"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ;

i=1; dir=1;

ShowWindow (hwnd, iCmdShow) ;

UpdateWindow (hwnd) ;

while (GetMessage (&msg, NULL, 0, 0))

{

TranslateMessage (&msg) ;

DispatchMessage (&msg) ;

}

return msg.wParam ;

}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

HDC hdc ;

static int cxclient, cyclient;

PAINTSTRUCT ps ;

RECT rect;

GetClientRect(hwnd,&rect);

switch (message)

{

case WM_SIZE:

cxclient=LOWORD(lParam);

cyclient=HIWORD(lParam);

return 0;

case WM_PAINT:

hdc = BeginPaint (hwnd, &ps) ;

InvalidateRect (hwnd,NULL,TRUE);

circle(hwnd,hdc,a[0][0],a[1][0],a[2][0],rect,0);

circle(hwnd,hdc,a[0][1],a[1][1],a[2][1],rect,1);

circle(hwnd,hdc,a[0][2],a[1][2],a[2][2],rect,2);

circle(hwnd,hdc,a[0][3],a[1][3],a[2][3],rect,3);

circle(hwnd,hdc,a[0][4],a[1][4],a[2][4],rect,4);

circle(hwnd,hdc,a[0][5],a[1][5],a[2][5],rect,5);

Observații:

Universitatea Tehnica a Moldovei

Filiera Francofona Informatica

Download gratuit

Documentul este oferit gratuit,
trebuie doar să te autentifici in contul tău.

Structură de fișiere:
  • Visual Sudio - GDI si Animatie.doc
Alte informații:
Tipuri fișiere:
doc
Nota:
7/10 (1 voturi)
Nr fișiere:
1 fisier
Pagini (total):
4 pagini
Imagini extrase:
4 imagini
Nr cuvinte:
563 cuvinte
Nr caractere:
4 689 caractere
Marime:
87.47KB (arhivat)
Publicat de:
NNT 1 P.
Nivel studiu:
Facultate
Tip document:
Laborator
Domeniu:
Limbaje de Programare
Predat:
la facultate
Materie:
Limbaje de Programare
Profesorului:
George Slavan
Sus!