1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
int xL = 225, xR = 250;
int yT = 430, yB = 450;
int move = 30;
int fall = 10;
int left2 = rand() % 200 + 50;
int right2 = left2 + 20;
int left3 = rand() % 200 + 50;
int right3 = left3 + 20;
int left4 = rand() % 200 + 50;
int right4 = left4 + 20;
int left5 = rand() % 200 + 50;
int right5 = left5 + 20;
int left6 = rand() % 200 + 50;
int right6 = left6 + 20;
int t = 35;
int b = 60;
static RECT r1 = {};
static RECT r2 = {};
static RECT r3 = {};
static RECT r4 = {};
static RECT r5 = {};
static RECT r6 = {};
switch (message)
{
case WM_CREATE:
{
srand(time(NULL));
r1 = { 270, 445, 295, 470 };
r2 = { left2, t, right2, b };
r3 = { left3, t, right3, b };
r4 = { left4, t, right4, b };
r5 = { left5, t, right5, b };
r6 = { left6, t, right6, b };
return 0;
}
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
DrawEnclosure(hWnd, hdc);
RoundRect(hdc, r1.left, r1.top, r1.right, r1.bottom, 2, 2);
RoundRect(hdc, r2.left, r2.top, r2.right, r2.bottom, 3, 3);
r2.top += fall;
r2.bottom += fall;
if (r2.bottom > 470){
r2.top = 35;
r2.bottom = 60;
r2.left = left2;
r2.right = right2;
}
RoundRect(hdc, r3.left, r3.top, r3.right, r3.bottom, 3, 3);
r3.top += fall;
r3.bottom += fall;
if (r3.bottom > 470){
r3.top = 35;
r3.bottom = 60;
r3.left = left3;
r3.right = right3;
}
RoundRect(hdc, r4.left, r4.top, r4.right, r4.bottom, 3, 3);
r4.top += fall;
r4.bottom += fall;
if (r4.bottom > 470){
r4.top = 35;
r4.bottom = 60;
r4.left = left4;
r4.right = right4;
}
RoundRect(hdc, r5.left, r5.top, r5.right, r5.bottom, 3, 3);
r5.top += fall;
r5.bottom += fall;
if (r5.bottom > 470){
r5.top = 35;
r5.bottom = 60;
r5.left = left5;
r5.right = right5;
}
RoundRect(hdc, r6.left, r6.top, r6.right, r6.bottom, 3, 3);
r6.top += fall;
r6.bottom += fall;
if (r6.bottom > 470){
r6.top = 35;
r6.bottom = 60;
r6.left = left6;
r6.right = right6;
}
EndPaint(hWnd, &ps);
break;
case WM_TIMER:
InvalidateRect(hWnd, NULL, true);
break;
case WM_KEYDOWN:
switch (wParam)
{
case VK_LEFT:
r1.left -= move;
r1.right -= move;
if (r1.left < 20){
r1.left = 20;
r1.right = 45;
}
break;
case VK_RIGHT:
r1.left += move;
r1.right += move;
if (r1.right > 295){
r1.right = 295;
r1.left = 270;
}
break;
}
InvalidateRect(hWnd, NULL, TRUE);
UpdateWindow(hWnd);
return 0;
case WM_SIZE:
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
|