#include "GameMap.h"
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
MSG msg;
HDC hdc;
int i;
char filename[20] = "";
MyRegisterClass(hInstance);
InitInstance(hInstance, nShowCmd);
for(i = 0; i < 3; i++)
{
sprintf(filename, "Image/map%d.bmp", i);
map[i] = (HBITMAP)LoadImage(hInstance, filename, IMAGE_BITMAP, 100, 100, LR_LOADFROMFILE);
}
hdc = GetDC(hWnd);
MyPaint(hdc);
ReleaseDC(hWnd, hdc);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//****************************************
//
// 注册函数
//
//****************************************
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wce;
wce.cbSize = sizeof(wce);
wce.style = CS_VREDRAW|CS_HREDRAW;
wce.lpfnWndProc = MyProc;
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hInstance = hInstance;
wce.hIcon = NULL;
wce.hCursor = LoadCursor(NULL, IDC_CROSS);
wce.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wce.lpszMenuName = NULL;
wce.lpszClassName = "MyWClass";
wce.hIconSm = NULL;
RegisterClassEx(&wce);
return 0;
}
//****************************************
//
// 创建窗体函数
//
//****************************************
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hinst = hInstance;
hWnd = CreateWindow("MyWClass", "coco", WS_SYSMENU, 100, 100, 300, 350, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//****************************************
//
// 消息处理函数
//
//****************************************
LRESULT CALLBACK MyProc(
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
MyPaint(hdc);
EndPaint(hWnd, &ps);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
//****************************************
//
// 绘图函数
//
//****************************************
void MyPaint(HDC hdc)
{
mdc = CreateCompatibleDC(hdc);
fulldc = CreateCompatibleDC(hdc);
fullmap = CreateCompatibleBitmap(hdc, 300, 300);
int i, x, y;
int mapIndex[rows*cols] = {0, 1, 1,
0, 1, 1,
2, 2, 2
};
SelectObject(fulldc, fullmap);
for(i = 0; i < 9; i++)
{
x = i%rows * 100;
y = i/3 *100;
SelectObject(mdc, map[mapIndex[i]]);
BitBlt(fulldc, x, y, 100, 100, mdc, 0, 0, SRCCOPY);
}
SelectObject(fulldc, fullmap);
BitBlt(hdc, 0, 0, 300, 300, fulldc, 0, 0, SRCCOPY);
DeleteDC(mdc);
DeleteDC(fulldc);
DeleteObject(fullmap);
}