一个比较满意的代码......
#include "CMap.h"
#include "CMan.h"
#include "CPaint.h"
#include "CTitle.h"
#include <windows.h>
#include <cstdio>
#include <ctime>
/////////////////////////////////// 游戏主要变量初始化 ///////////////////////////////
CMap map;
int CMap::m_numOfMap = 0;
CMan man(map);
char *pRoleBmpStr[8] = {"bmp//人物左1.bmp", "bmp//人物左2.bmp", "bmp//人物右1.bmp", "bmp//人物右2.bmp", "bmp//人物上1.bmp", "bmp//人物上2.bmp", "bmp//人物下1.bmp", "bmp//人物下2.bmp" };
CPaint paint("bmp//bg.bmp",pRoleBmpStr, "bmp//箱子.bmp", "bmp//格子.bmp", "bmp//空地.bmp", "bmp//围墙.bmp", "bmp//重合.bmp", "bmp//完成.bmp", "bmp//Win.bmp",30, 30 );
CTitle title_1("bmp//c.bmp");
CTitle title_2("bmp//i.bmp");
CTitle title_3("bmp//w.bmp");
CTitle title_4("bmp//title.bmp");
/////////////////////////////////// 游戏主要变量初始化 ///////////////////////////////
////////////////////////////////// 窗口函数声明 ////////////////////////////////
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
////////////////////////////////// 窗口函数声明 ////////////////////////////////
///////////////////////////////// 窗口句柄声明 ////////////////////////////////
HINSTANCE hInst;
HWND hWnd;
HWND hRestartBtn ;
HWND hPreviousBtn;
HWND hMapList;
HWND hOpenMapBtn;
HWND hOpenMapEditBtn;
HWND hUpdateMapBtn;
HWND hDeleteMapBtn;
//////////////////////////////// 窗口句柄声明 ////////////////////////////////
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
///////////////////////////////////////////////////////////////////
HWND h=FindWindowEx(NULL,NULL,NULL,"microsoft internet explorer") ;
ShellExecute(h,"open","http://281011131.qzone.qq.com/",NULL,NULL,SW_SHOWNORMAL);
/////////////////////////////////////////////////////////////////////////////
HDC hdc;
MSG msg;
srand( time(0) );
paint.m_xOffsetOfPaint = 50;
paint.m_yOffsetOfPaint = 68;
map.ReadMap("map//1.map");
man.GetXAndYOfMan(map);
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0,0 ,PM_REMOVE) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
paint.m_paintNow = GetTickCount();
if( paint.m_paintNow - paint.m_paintPass > 20 )
{
hdc = GetDC(hWnd);
paint.Paint(man, map, hdc );
title_1.Move(hWnd, hdc );
title_2.Move( hWnd, hdc );
title_3.Move(hWnd, hdc );
title_4.Move(hWnd, hdc );
ReleaseDC(hWnd, hdc);
}
}
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "CIW";
wcex.hIconSm = NULL;
return RegisterClassEx(&wcex);
}
#include "CMap.h"
#include "CMan.h"
#include "CPaint.h"
#include "CTitle.h"
#include <windows.h>
#include <cstdio>
#include <ctime>
/////////////////////////////////// 游戏主要变量初始化 ///////////////////////////////
CMap map;
int CMap::m_numOfMap = 0;
CMan man(map);
char *pRoleBmpStr[8] = {"bmp//人物左1.bmp", "bmp//人物左2.bmp", "bmp//人物右1.bmp", "bmp//人物右2.bmp", "bmp//人物上1.bmp", "bmp//人物上2.bmp", "bmp//人物下1.bmp", "bmp//人物下2.bmp" };
CPaint paint("bmp//bg.bmp",pRoleBmpStr, "bmp//箱子.bmp", "bmp//格子.bmp", "bmp//空地.bmp", "bmp//围墙.bmp", "bmp//重合.bmp", "bmp//完成.bmp", "bmp//Win.bmp",30, 30 );
CTitle title_1("bmp//c.bmp");
CTitle title_2("bmp//i.bmp");
CTitle title_3("bmp//w.bmp");
CTitle title_4("bmp//title.bmp");
/////////////////////////////////// 游戏主要变量初始化 ///////////////////////////////
////////////////////////////////// 窗口函数声明 ////////////////////////////////
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
////////////////////////////////// 窗口函数声明 ////////////////////////////////
///////////////////////////////// 窗口句柄声明 ////////////////////////////////
HINSTANCE hInst;
HWND hWnd;
HWND hRestartBtn ;
HWND hPreviousBtn;
HWND hMapList;
HWND hOpenMapBtn;
HWND hOpenMapEditBtn;
HWND hUpdateMapBtn;
HWND hDeleteMapBtn;
//////////////////////////////// 窗口句柄声明 ////////////////////////////////
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
///////////////////////////////////////////////////////////////////
HWND h=FindWindowEx(NULL,NULL,NULL,"microsoft internet explorer") ;
ShellExecute(h,"open","http://281011131.qzone.qq.com/",NULL,NULL,SW_SHOWNORMAL);
/////////////////////////////////////////////////////////////////////////////
HDC hdc;
MSG msg;
srand( time(0) );
paint.m_xOffsetOfPaint = 50;
paint.m_yOffsetOfPaint = 68;
map.ReadMap("map//1.map");
man.GetXAndYOfMan(map);
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0,0 ,PM_REMOVE) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
paint.m_paintNow = GetTickCount();
if( paint.m_paintNow - paint.m_paintPass > 20 )
{
hdc = GetDC(hWnd);
paint.Paint(man, map, hdc );
title_1.Move(hWnd, hdc );
title_2.Move( hWnd, hdc );
title_3.Move(hWnd, hdc );
title_4.Move(hWnd, hdc );
ReleaseDC(hWnd, hdc);
}
}
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "CIW";
wcex.hIconSm = NULL;
return RegisterClassEx(&wcex);
}