You are on page 1of 3

#include <Windows.

h>
#include <Math.h>
#include <stdio.h>

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

int WINAPI WinMain(


HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hwndMain;
MSG msg;
WNDCLASS wndCls;
UNREFERENCED_PARAMETER(lpCmdLine);

wndCls.style = 0;
wndCls.lpfnWndProc = (WNDPROC) WndProc;
wndCls.cbClsExtra = 0;
wndCls.cbWndExtra = 0;
wndCls.hInstance = hInstance;
wndCls.hIcon = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
wndCls.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
wndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndCls.lpszMenuName = NULL;
wndCls.lpszClassName = "WndClass";

if (!RegisterClass(&wndCls))
return FALSE;

hwndMain = CreateWindow(
"WndClass",
"Laboratorul nr 2",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,760,350,
(HWND) NULL,(HMENU) NULL,hInstance,(LPVOID) NULL);

if (!hwndMain)
return FALSE;

ShowWindow(hwndMain, nCmdShow);
UpdateWindow(hwndMain);

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


{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg,


WPARAM wParam, LPARAM lParam)
{
HDC hdc,hCompatibleDC ;
PAINTSTRUCT ps ;
RECT rect ;
HPEN pen,pen2,old_pen;
HBRUSH brush,brush2,old_br;
HANDLE hOldBitmap;
HANDLE hBitmap;
BITMAP Bitmap;

char sir[150];
short lungime=sprintf(sir, "Animatie");

switch(uMsg){
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);

//---------------------------------------------------------------------------
---
//Desenam linii dreapte
//
//crearea a doua penite noi
pen = CreatePen(PS_SOLID,2,RGB(1, 1, 254));
pen2 = CreatePen(PS_SOLID,2,RGB(2, 170, 255));
//pastrarea penitei vechi
old_pen=(HPEN)SelectObject(hdc,pen);

MoveToEx(hdc,55,55,NULL);
LineTo(hdc,150,150);
//MoveToEx(hdc,20,80,NULL);
//stergerea penitei pen
DeleteObject(pen);

//---------------------------------------------------------------------------
---

//crearea unei noi pensule


brush2=CreateSolidBrush(RGB(2, 170, 255));
Ellipse(hdc,500, 50, 675, 150);
DeleteObject(brush2);
brush = CreateHatchBrush(HS_BDIAGONAL, RGB(1, 1, 254));
//pastrarea pensulei vechi
old_br=(HBRUSH)SelectObject(hdc,brush);
SelectObject(hdc,pen2);
//Desenam un dreptunghi
Rectangle(hdc,250, 55, 375, 150); //Dreptunghi
//stergerea obiectelor create
DeleteObject(pen2);
DeleteObject(brush);
//restaurarea obiectelor anterioare
SelectObject(hdc,old_pen);
SelectObject(hdc,old_br);

//---------------------------------------------------------------------------
---
//Incarcam o imagine BITMAP
//
hBitmap =(HBITMAP)LoadImage(NULL,
("poza.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
//Obtinem marimea imaginii bitmap
GetObject(hBitmap,sizeof(BITMAP),&Bitmap);
//Cream o noua variabila handle a contextului de dispozitiv
hCompatibleDC = CreateCompatibleDC(hdc);
//Pastram imaginea veche bitmap
hOldBitmap = SelectObject(hCompatibleDC,hBitmap);

//Copiem imaginea bitmap si o deplasam


StretchBlt(hdc,520,30,170,156,
hCompatibleDC,0,0,Bitmap.bmWidth,
Bitmap.bmHeight,SRCCOPY);

//Restauram obiectul anterior


SelectObject(hCompatibleDC,hOldBitmap);
//Stergem imaginea bitmap incarcata
DeleteObject(hBitmap);
//Stergem variabila handle a contextului de dispozitiv
DeleteDC(hCompatibleDC);

//---------------------------------------------------------------------------
---
//Afisam text
//
SetTextColor(hdc, RGB(60,100,220));
//SetBkColor(hdc, RGB(60,100,100));
TextOut(hdc,150,200,sir,lungime);
//---------------------------------------------------------------------------
---

EndPaint(hwnd,&ps);
return 0;

case WM_CLOSE:
PostMessage(hwnd, WM_QUIT, 0L, 0L);
return 0;

default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}

You might also like