//--------------------------------------------InitInstance() 函数----------------------------------------------
//加载资源
//-------------------------------------------------------------------------------------------------------------
BOOL InitInstance(HINSTANCE hInstance, int nShowCmd)
{
HWND hwnd;
HDC hdc;
const int rows = 8, cols = 8;
CImage m_Image;

//创建窗口第三步:正式创建窗口
//创建窗口函数
hwnd = CreateWindow("GameClass", WINDOW_TITLE, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hwnd)
{
return FALSE;
}
//创建窗口第四步:窗口的移动,显示和更新
MoveWindow(hwnd, 250, 80, WINDOW_WIDTH, WINDOW_HEIGHT, true);//调整窗口显示时的位置及窗口的大小
ShowWindow(hwnd, nShowCmd);//设定显示窗口时的状态
UpdateWindow(hwnd);//将窗口绘制于显示设备上

int mapIndex[rows * cols] =
{
0, 1, 2, 2, 0, 1, 0, 1,
0, 1, 2, 0, 0, 0, 1, 1,
2, 0, 0, 0, 0, 0, 0, 1,
2, 0, 0, 1, 1, 0, 2, 2,
2, 2, 0, 0, 2, 2, 0, 0,
0, 2, 2, 2, 2, 0, 0, 1,
0, 2, 2, 2, 2, 2, 1, 1
};
hdc = GetDC(hwnd);

//按照mapIndex数组的定义取出对应的图块,进行地图拼接
for (int i = 0; i < rows * cols; i++)
{
int x, y;
//i / cols;//求列编号
//i % cols;//求行编号
x = i % cols * 50;//求贴图x坐标
y = i / cols * 50;//求贴图y坐标

m_Image.Destroy();
switch (mapIndex[i])
{
case 0:
m_Image.Load("m0.png");
m_Image.Draw(hdc, x, y);
break;
case 1:
m_Image.Load("m1.png");
m_Image.Draw(hdc, x, y);
break;
case 2:
m_Image.Load("m2.png");
m_Image.Draw(hdc, x, y);
break;
default:
break;
}
}

MyPaint(hdc);

ReleaseDC(hwnd, hdc);

return TRUE;
}

posted on 2015-11-22 22:11  zishen  阅读(350)  评论(0编辑  收藏  举报