⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sh.cpp

📁 应用程序向导已为您创建了这个 SH 应用程序。此应用程序不仅演示 Microsoft 基础类的基本使用方法
💻 CPP
字号:
// SH.cpp : 定义应用程序的类行为。
//

#include "stdafx.h"
#include "SH.h"
#include "PlayMain.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CSHApp

BEGIN_MESSAGE_MAP(CSHApp, CWinApp)
	ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()


// CSHApp 构造

CSHApp::CSHApp()
{
	// TODO: 在此处添加构造代码,
	// 将所有重要的初始化放置在 InitInstance 中
}


// 唯一的一个 CSHApp 对象

CSHApp theApp;


// CSHApp 初始化

BOOL CSHApp::InitInstance()
{
	// 如果一个运行在 Windows XP 上的应用程序清单指定要
	// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
	//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// 将它设置为包括所有要在应用程序中使用的
	// 公共控件类。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	AfxEnableControlContainer();

	// 标准初始化
	// 如果未使用这些功能并希望减小
	// 最终可执行文件的大小,则应移除下列
	// 不需要的特定初始化例程
	// 更改用于存储设置的注册表项
	// TODO: 应适当修改该字符串,
	// 例如修改为公司或组织名
	SetRegistryKey(_T("应用程序向导生成的本地应用程序"));

	//1.程序开始,初始化基本配置
	InitConfig();

	//2.显示主窗体
	CPlayMain *pWnd =new CPlayMain();
	pWnd->Create();
	m_pMainWnd = pWnd;
	pWnd->ShowWindow(m_nCmdShow);
	pWnd->UpdateWindow();
	pWnd->SetFocus();
	//3.初始化DirectDraw环境
	HWND hwndTop = AfxGetMainWnd()->GetSafeHwnd();  
	m_CDirectManage.SetDrawhWnd(pWnd->m_hWnd);
	m_CDirectManage.SetDrawhWnd(hwndTop);
	if (m_CDirectManage.InitDDraw() == FALSE)
	{
		m_CDirectManage.FreeDDraw();
		AfxMessageBox(L"初始化DirectDraw环境失败");
		ExitInstance();
		return 0;
	}

	//初始化随机指数
	srand( (unsigned)time( NULL ) ); 
	//
	if (m_CPlayGame.Init() == 0)
	{
		m_CDirectManage.FreeDDraw();
		AfxMessageBox(L"初始化游戏失败");
		ExitInstance();
		return 0;
	}
	//4.进入消息循环,启动应用程序的消息泵。
	return TRUE;
}
BOOL CSHApp::InitConfig()
{
	//GetCurrentDirectory(MAX_PATH,m_strRootPath.GetBuffer(MAX_PATH));
	TCHAR   exeFullPath[MAX_PATH];    
    GetModuleFileName(NULL,exeFullPath,MAX_PATH);
	CString strAppFile = exeFullPath;
	int iFind = strAppFile.ReverseFind('\\');
	m_strRootPath = strAppFile.Left(iFind + 1);

	m_iWindowMode = 1;
	m_iScreenWidth = 640;
	m_iScreenHeight = 480;
	m_RectScreen.top = 0;
	m_RectScreen.left = 0;
	m_RectScreen.bottom = m_iScreenWidth;
	m_RectScreen.right = m_iScreenHeight;

	m_rectWindow.top = 0;
	m_rectWindow.left = 0;
	m_rectWindow.bottom = m_iScreenWidth;
	m_rectWindow.right = m_iScreenHeight;

	return TRUE;
}
int CSHApp::Run(void)
{
	MSG msg;
	while(1)
	{
		if (m_bShutDown)
		{
			ExitInstance();
			return 0;
		}
		if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		{
			if(GetMessage(&msg, NULL, 0, 0) == FALSE)
			{
				ExitInstance();
				return (int)msg.wParam;    // WM_QUIT
			}
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			if(m_CPlayGame.m_iStatus == 1)
			{

			}
			WaitMessage();
		}
	}
	return 0;
}
int CSHApp::ExitInstance(void) 
{	
	return CWinApp::ExitInstance();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -