16. 16
V鱈 d畛 2
M担 ph畛ng banh r董i
M担 t畉 bi to叩n:
M畛t qu畉 banh r董i t畛 do t畛 畛 cao H xu畛ng n畛n r畛i
d畛i l棚n l畉i 畛 cao H.
Y棚u c畉u:
Thi畉t k畉 d畛 li畛u
Vi畉t m達 gi畉 x畛 l箪 cho c叩c s畛 ki畛n sau:
WM_CREATE, WM_DESTROY
WM_PAINT
WM_TIMER
17. 17
V鱈 d畛 2
D畛 li畛u:
double h; //畛 cao hi畛n t畉i
double a = -5;//gia t畛c
double v, //v畉n t畛c hi畛n t畉i
double H=300; //畛 cao t畛i a
int r=5; //b叩n k鱈nh
int T = 50;//s畛 nh畛p d湛ng 畛 畉t trong SetTimer
WM_PAINT
x = 100; y = H+100-h; //畉o h畛 t畛a 畛
Ellipse(hdc,x-r,y-r, x+r,y+r);
MoveToEx(hdc,0,H+100,NULL);
LineTo(hdc,300,H+100);
18. 18
V鱈 d畛 2
case WM_TIMER:
t = T / 1000.0;
h = a*t*t + v*t + h;
v = a*t + v;
if (h<0) {
h = 0;
v = -v;
}
InvalidateRect(hWnd,NULL,TRUE);
break;
19. 19
V鱈 d畛 2
case WM_CREATE:
v = 0;//v畉n t畛c ban 畉u
h = H;//畛 cao ban 畉u
SetTimer(hWnd,1,T,NULL);
break;
case WM_DESTROY:
KillTimer(hWnd,1);
PostQuitMessage(0);
break;
20. 20
M担 t畉 bi to叩n:
Y棚u c畉u:
Thi畉t k畉 d畛 li畛u
Vi畉t m達 gi畉 x畛 l箪 cho c叩c s畛 ki畛n sau:
WM_CREATE , WM_DESTROY
WM_PAINT
WM_TIMER
Bi t畉p 2
H
V
L