1
2
3
4
5
6
|
111111111111111
100000000000001
100000000000001
100000000000001
100000000000001
111111111111111
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
|
void
CSnakeDlg::OnPaint()
{
if
(IsIconic())
{
CPaintDC dc(
this
);
// 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast
<
WPARAM
>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
int
cxIcon = GetSystemMetrics(SM_CXICON);
int
cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int
x = (rect.Width() - cxIcon + 1) / 2;
int
y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
|
1
2
3
4
5
6
|
void
CSnakeDlg::OnPaint()
{
CPaintDC dc(
this
);
// 用于绘制的设备上下文
CDialogEx::OnPaint();
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
void
CSnakeDlg::InitGameData()
{
for
(
int
i=0; i
{
for
(
int
j=0; j
{
if
((i==0||i==GAME_COL-1)||(j==0||j==GAME_ROW-1))
{
m_arrGameRange[i][j = 1;
}
else
{
m_arrGameRange[i][j = 0;
}
}
}
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
void
CSnakeDlg::OnPaint()
{
CPaintDC dc(
this
);
// 用于绘制的设备上下文
CBrush brushGame(RGB(255,255,255));
//创建黑色画刷 用来画游戏区域
CBrush brushBorder(RGB(34,176,76));
//创建绿色画刷 用来画边框
//遍历行、列来画不同的颜色
for
(
int
i = 0; i < GAME_COL; i++)
{
for
(
int
j = 0; j < GAME_ROW; j++)
{
//根据行列来计算一个矩形大小,每个矩形占20个像素
CRect rt;
rt.left = i*20;
rt.top = j*20;
rt.right = rt.left + 20;
rt.bottom = rt.top + 20;
if
(m_arrGameRange[i][j == 1)
//需要画边框
{
dc.SelectObject(brushBorder);
//把我们得画刷选入DC
dc.Rectangle(rt);
//填充矩形,参数表示要填充的矩形区域
}
else
{
dc.SelectObject(brushGame);
//把我们得画刷选入DC
dc.Rectangle(rt);
//填充矩形,参数表示要填充的矩形区域
}
}
}
CDialogEx::OnPaint();
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
void
CSnakeDlg::OnPaint()
{
CPaintDC dc(
this
);
// 用于绘制的设备上下文
CBrush brushGame(RGB(0,0,0));
//创建黑色画刷 用来画游戏区域
CBrush brushBorder(RGB(34,176,76));
//创建绿色画刷 用来画边框
//遍历行、列来画不同的颜色
for
(
int
i = 0; i < GAME_COL; i++)
{
for
(
int
j = 0; j < GAME_ROW; j++)
{
//根据行列来计算一个矩形大小,每个矩形占20个像素
CRect rt;
rt.left = i*20;
rt.top = j*20;
rt.right = rt.left + 20;
rt.bottom = rt.top + 20;
if
(m_arrGameRange[i][j == 1)
//需要画边框
{
//填充矩形的函数,
//第一个参数是要填充的矩形
//第二个参数是什么什么画刷填充矩形
dc.FillRect(rt, &brushBorder);
}
else
{
dc.FillRect(rt, &brushGame);
}
}
}
CDialogEx::OnPaint();
}
|