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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
| int WINAPI WinMain (HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
//* * *
//* * *
//* * *
while (TRUE)
{
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage (&msg);
DispatchMessage (&msg);
}// end if
//draw auto in the window-------------------------------------------------------
if (pressed_button == 300) // select auto
{
avto.LoadAvto (hmemdc, type_selector);
if (MOUSE_BUTTON & MK_LBUTTON)
{
avto.PlaceAvto (hmemdc);
}
MOUSE_BUTTON = NULL;
}
//move auto---------------------------------------------------------------------
if (pressed_button == 1200)
{
avto.StartMoving (hmemdc);
MOUSE_BUTTON = NULL;
}
//stop moving-------------------------------------------------------------------
if (pressed_button == 1300)
{
avto.StopMoving ();
MOUSE_BUTTON = NULL;
}
//------------------------------------------------------------------------------
//quit in window
if (KEYDOWN(VK_ESCAPE))
{
PostMessage (main_window_handle, WM_CLOSE, 0, 0);
}
//hold back the 30 fps
while ((GetTickCount() - start_time) < 33);
//===================================================================
}//while (TRUE)
DeleteDC (hmemdc);
ReleaseDC (main_window_handle, hgraphdc);
//===================================================================
return (msg.wParam);
}//WinMaim
//*******************************************************************
//Other functions*************************************************************
//class Avto Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Avto::Avto()
{
avto_type = 20;
}//constructor
int Avto::LoadAvto (HDC hmemdc, int type_selector)
{
switch (type_selector)
{
case 1:
{
avto_type = 10;
}break;
case 2:
{
avto_type = 11;
}break;
case 3:
{
avto_type = 12;
}break;
default: break;
}//switch
//load selected auto image
hbmp_avto = LoadBitmap (hinstance_app, MAKEINTRESOURCE(avto_type))
GetObject (hbmp_avto, sizeof(BITMAP), &bmp_avto)
SelectObject (hmemdc, hbmp_avto);
//place curent object into small window
StretchBlt (hgraphdc,
4,
293,
74,
74,
hmemdc,
0,
0,
bmp_avto.bmWidth,
bmp_avto.bmHeight,
SRCCOPY);
return (0);
}//int LoadAvto (int type_selector)
int Avto::PlaceAvto (HDC hmemdc)
{
avto_rect.left = MOUSE_XPOS;
avto_rect.top = MOUSE_YPOS;
avto_rect.right = MOUSE_XPOS + bmp_avto.bmWidth;
avto_rect.bottom = MOUSE_YPOS + bmp_avto.bmHeight;
//copy bacground before auto placed
hgroundrect = GetBitmap (hgraphdc, avto_rect, hmemdc);
SelectObject (hmemdc, hbmp_avto);
//place auto into window
BitBlt (hgraphdc,
avto_rect.left,
avto_rect.top,
avto_rect.right,
avto_rect.bottom,
hmemdc,
0, 0,
SRCCOPY);
return (0);
}//int Avto::PlaceAvto (HDC hmemdc)
int Avto::StartMoving (HDC hmemdc)
{
//select and place bacground
SelectObject (hmemdc, hgroundrect);
BitBlt (hgraphdc,
avto_rect.left,
avto_rect.top,
avto_rect.right,
avto_rect.bottom,
hmemdc,
0, 0,
SRCCOPY);
speed = 1;
boost = 1;
avto_rect.left += (speed * boost);
//load bacground
hgroundrect = GetBitmap (hgraphdc, avto_rect, hmemdc);
SelectObject (hmemdc, hbmp_avto);
//place auto into window
BitBlt (hgraphdc,
avto_rect.left,
avto_rect.top,
avto_rect.right,
avto_rect.bottom,
hmemdc,
0, 0,
SRCCOPY);
return (0);
}
int Avto::StopMoving ()
{
speed += 0;
return (0);
}
Avto::~Avto()
{
DeleteObject (hbmp_avto);
DeleteObject (hgroundrect);
}//destructor |