Lab3.cpp Defines the entry point for the application.
#include framework.h
#include Lab3.h
Lab2.1.cpp Defines the entry point for the application.
#include windows.h
#include iostream
#include stdlib.h
#include string.h
#include tchar.h
#include resource.h
#include time.h
#include map
#include string
#define IDT_MOVETIMER 2L se defineste un identificator pentru
#define IDT_COLORTIMER 1L
#define MS 1000
static TCHAR szWindowClass[] = _T(DesktopApp);
static TCHAR szTitle[] = _T(Tehnologia Informației în Educație);
HINSTANCE hInst;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
RECT clR;
int r, g, b;
struct RectStruct {
int x; top-left vertical
int y; top-left horizontal
int x1; bottom-right horizontal
int y1; bottom-right vertical
int vX;
int vY;
bool kW;
bool kS;
bool kA;
bool kD;
bool spbar;
bool shift;
bool ctrl;
};
RectStruct rct;
bool setPos(int posX, int posY, int posX1, int posY1) {
stdcout stdendl stdendl;
stdcout rct.x , rct.y , rct.x1 , rct.y1 stdendl;
rct.x = posX;
rct.y = posY;
rct.x1 = posX1;
rct.y1 = posY1;
r = re;
stdcout re.x , re.y , re.x1 , re.y1 stdendl;
stdcout rct.x , rct.y , rct.x1 , rct.y1 stdendl;
stdcout stdendl stdendl;
return true;
}
bool setKeyState()
functia care initializeaza punctele
POINT apt[4]; definim variabila globala
void InitBezierParams()
{
apt[0].x = 220; apt[0].y = 110;
apt[1].x = 260; apt[1].y = 20;
apt[2].x = 360; apt[2].y = 190;
apt[3].x = 420; apt[3].y = 110;
}
int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpC
mdLine, _In_ int nCmdShow)
{
WNDCLASSEX wcex;
AllocConsole();
freopen(CONOUT$, w, stdout);
freopen(CONOUT$, w, stderr);
freopen_s(0, CONOUT$, w, stdout)
freopen_s((FILE)stdout, CONOUT$, w, stdout);
freopen_s(0, CONOUT$, w, stderr);
rct.x = 0; rct.y = 0; rct.x1 = 0; rct.y1 = 0; rct.vX = 0; rct.vY = 0;
setPos(50, 50, 200, 200);
rct.kW = rct.kA = rct.kS = rct.kD = rct.shift = rct.spbar = rct.ctrl = false;
stdcout Called WinMain stdendl; is called only once
r = g = b = 0;
int colorRefresh = 1 MS;
int movementTrack = 50;
srand(time(0)); functia care inbunatateste randomizarea
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
HBITMAP backgroundImage = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1));
wcex.hbrBackground = CreatePatternBrush(backgroundImage);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T(Call to RegisterClassEx failed!),
_T(Windows Desktop Guided Tour),
NULL);
return 1;
}
hInst = hInstance;
HWND hWnd = CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
{
MessageBox(NULL,
_T(Call to CreateWindow failed!),
_T(Windows Desktop Guided Tour),
NULL);
return 1;
}
InitBezierParams(); Chemam functia care initializeaza pentru prima data punctele curbei Bezier
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
SetTimer(hWnd, IDT_COLORTIMER, colorRefresh, (TIMERPROC)NULL); Setarea TIMER NULL- ca WMD
Proc sa prelucreze evenimentul
SetTimer(hWnd, IDT_MOVETIMER, movementTrack, (TIMERPROC)NULL);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc, hdcBitmap, hdcWindow;
HBRUSH hBrush;
SHORT Wstate;
TCHAR greeting[] = _T(Programarea Pilotata pe Evenimente);
stdcout rct.x , rct.y , rct.x1 , rct.y1 stdendl;
stdcout Called WndProc stdendl; is called every time mouse moves, resize etc..
HBITMAP backgroundImage = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_APPLICA
TION)); incarcam imaginea
BITMAP bp; structura pentru imagine
GetObject(backgroundImage, sizeof(bp), &bp); copiem imaginea din handle in Bitmap
switch (message)
{
case WM_PAINT
hdc = BeginPaint(hWnd, &ps);
hdcWindow = GetWindowDC(hWnd);
SetTextColor(hdc, RGB(50, 70, 70));
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc, 10, 10, greeting, _tcslen(greeting));
PolyBezier(hdc, apt, 4); draw beizer
EndPaint(hWnd, &ps);
break;
case WM_KEYDOWN
if (GetKeyState('W')) stdcout W is DOWN stdendl;
switch (wParam) 0x57 W key 0x41 A key 0x53 S key 0x44 D key
{
case 'W' 0x57
Process a W.
stdcout Pressed W stdendl;
rct.kW = true;
break;
case 'A' 0x41
Process a A.
stdcout Pressed A stdendl;
rct.kA = true;
break;
case 'S' 0x53
Process an S.
stdcout Pressed S stdendl;
rct.kS = true;
break;
case 'D' 0x44
Process a D.
stdcout Pressed D stdendl;
rct.kD = true;
break;
case VK_SHIFT 0x44
Process a D.
stdcout Pressed D stdendl;
rct.shift = true;
break;
case VK_SPACE 0x44
Process a D.
stdcout Pressed D stdendl;
rct.shift = true;
break;
case VK_CONTROL 0x44
Process a D.
stdcout Pressed D stdendl;
rct.ctrl = true;
break;
default
Process displayable characters.
stdcout Pressed wParam stdendl;
break;
}
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_KEYUP
switch (wParam) 0x57 W key 0x41 A key 0x53 S key 0x44 D key
{
case 'W' 0x57
Process a W.
stdcout Released W stdendl;
rct.kW = false;
break;
case 'A' 0x41
Process a A.
stdcout Released A stdendl;
rct.kA = false;
break;
case 'S' 0x53
Process an S.
stdcout Released S stdendl;
rct.kS = false;
break;
case 'D' 0x44
Process a D.
stdcout Released D stdendl;
rct.kD = false;
break;
case VK_SHIFT 0x44
Process a D.
stdcout Pressed D stdendl;
rct.shift = false;
break;
case VK_SPACE 0x44
Process a D.
stdcout Pressed D stdendl;
rct.shift = false;
break;
case VK_CONTROL 0x44
Process a D.
stdcout Pressed D stdendl;
rct.ctrl = false;
break;
default
Process displayable characters.
stdcout Released wParam stdendl;
break;
}
break;
case WM_DESTROY
PostQuitMessage(0);
break;
case WM_CLOSE
DeleteObject(backgroundImage);
KillTimer(hWnd, IDT_MOVETIMER); KillTimer(hWnd, IDT_COLORTIMER);
PostQuitMessage(0);
break;
case WM_TIMER
switch (wParam)
{
case IDT_COLORTIMER {
r = rand() % 255; g = rand() % 255; b = rand() % 255;
InvalidateRect(hWnd, NULL, true); ca sa redeseneze tot ce este in WM_PAINT
break;
}
case IDT_MOVETIMER {
Wstate = GetKeyState('W'); 0x57 W key 0x41 A key 0x53 S key 0x44 D key
setPos(50, 50, 200, 200);
stdcout W state Wstate stdendl;
int maxV = 10;
if (rct.kW == true)
{
if (rct.ctrl == true)
{
apt[2].y -= 10;
}
else apt[1].y -= 10;
}
if (rct.kS == true)
{
if (rct.ctrl == true)
{
apt[2].y += 6;
}
else apt[1].y += 6;
}
GetClientRect(hWnd, &clR);
if (rct.kA == true)
{
if (rct.shift == true)
{
apt[0].x = clR.right 4;
apt[0].y = clR.bottom
apt[1].x = clR.right 2;
apt[1].y = clR.bottom
apt[2].x = clR.right 2;
apt[2].y = 3 clR.bottom
apt[3].x = 3 clR.right 4;
apt[3].y = clR.bottom
}
else apt[2].x -= 10;
}
if (rct.kD == true)
{
if (rct.shift == true)
{
apt[0].x = clR.right 2;
apt[0].y = clR.bottom
apt[1].x = 3 clR.right 4;
apt[1].y = clR.bottom
apt[2].x = clR.right 4;
apt[2].y = clR.bottom
apt[3].x = clR.right 2;
apt[3].y = 3 clR.bottom
}
else apt[2].x += 6;
}
if (rct.spbar)
for (size_t i = 0; i 4; i++)
{
if(rct.kA == true)
apt[i].x--;
else if (rct.kD == true)
apt[i].x++;
else if (rct.kW == true)
apt[i].y--;
2;
4;
4;
2;
4;
2;
2;
4;
else if (rct.kS == true)
apt[i].y++;
}
InvalidateRect(hWnd, NULL, TRUE);
break;
}
default
break;
}
break;
default
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )