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

📄 gamedlg.cpp

📁 网络游戏魔域源代码 测试可以完整变异
💻 CPP
字号:
// GameDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Game.h"
#include "GameDlg.h"
#include "GameDataSet.h"
#include "ndsound.h"
#include <afxinet.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

const int _BTN_WIDTH = 86;
const int _BTN_HEIGHT = 30;
/////////////////////////////////////////////////////////////////////////////
// CGameDlg dialog

CGameDlg::CGameDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGameDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGameDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_nMouseX = m_nMouseY = 0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_dwFrameTimer = ::TimeGet();
}

CGameDlg::~CGameDlg()
{
	CMyBitmap::GameFontDestroy();

	//g_objGameDataSet.Destroy();
	//CMyBitmap::Quit3D();
	//delete m_pWebDlg;
}

void CGameDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGameDlg)
	DDX_Control(pDX, IDC_STATIC_PIC, m_picMain);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGameDlg, CDialog)
	//{{AFX_MSG_MAP(CGameDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_LBUTTONDOWN()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGameDlg message handlers

BOOL CGameDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	strcpy(m_szVersion, "");
	FILE* fp = fopen("version.dat", "r");
	if(fp)
	{
		fscanf(fp, "%s", m_szVersion);
		fclose(fp);
	}

	CMyBitmap::GameFontCreate();
	g_objGameDataSet.Init();
	CMyBitmap::Init3DEx(m_picMain.m_hWnd, 640, 480, 1, 1);
	this->SetTimer(WM_TIMER, 30, NULL);
	m_bnEnterGame.Init("ani/play.ani", "Enter", 530, 90);

	m_bnPage.Init("ani/play.ani", "Page", 530, 170);
	m_bnRegist.Init("ani/play.ani", "Regist", 530, 216);
	m_bnPay.Init("ani/play.ani", "Pay", 530, 262);
	m_bnSystem.Init("ani/play.ani", "System", 530, 308);
	m_bnCredit.Init("ani/play.ani", "Credit", 530, 354);

	m_bnExitGame.Init("ani/play.ani", "Exit", 530, 400);

	this->SetWindowText("Play");
	m_nOffset = 0;
	m_bClick = false;
/*	RECT rectTool;
	m_pWebDlg = new CDialogWeb(this);
	m_pWebDlg->Create(IDD_DIALOG_WEB);
	m_pWebDlg->ShowWindow(SW_SHOW);*/

#ifndef _SOUND_DISABLE
	if ( 0 != DXSoundinit ( this->GetSafeHwnd ( ) ) )
	{
		this->MessageBox ( g_objGameDataSet.GetStr ( 10048 ), "Error", MB_OK|MB_ICONERROR ) ;		
		//		this->MessageBox("初始化声效系统失败。请检查声卡驱动程序", "Error", MB_OK|MB_ICONERROR);
	}
#endif

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGameDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGameDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CGameDlg::OnOK() 
{
	// TODO: Add extra validation here
	return;
	CDialog::OnOK();
}

void CGameDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void CGameDlg::GameMain()
{
	int re = IfDeviceLost ();
	if ( re == 1 )
		return;
	if ( re == 2 )
		ResetDevice ();

	CMyBitmap::Begin3D();
	CMySize sizeScr;
	sizeScr.iWidth = 640;
	sizeScr.iHeight = 480;
	CMyBitmap::GameCameraBuild(sizeScr);
	CMyBitmap::GameCameraSet(sizeScr.iWidth/2, sizeScr.iHeight/2);
	//-----------------------------------------------------------
	this->Loop();
	//-----------------------------------------------------------
	CMyBitmap::End3D();
	CMyBitmap::Flip();
	g_objGameDataSet.Process();
}

void CGameDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	this->GameMain();
	CDialog::OnTimer(nIDEvent);
}

void CGameDlg::Loop()
{
	CMyBitmap::ClearBuffer(true, true, 0xff000000);
	this->ShowBG();

#ifndef _SOUND_DISABLE
	DXProcessSound(0,0) ;
#endif

	if(m_bnEnterGame.Process(m_nMouseX, m_nMouseY,m_bClick))
	{
		if(m_bClick)
		{
			DXPlaySound ( "Sound/Dlg_Ok.wav" ) ;
			::ShellExecute(m_hWnd, NULL, "AutoPatch.exe", "blacknull", NULL, SW_SHOW|SW_RESTORE );	
			this->EndDialog(0);
		}
	}
	if(m_bnExitGame.Process(m_nMouseX, m_nMouseY,m_bClick))
	{
		if(m_bClick)
		{
			DXPlaySound ( "Sound/Dlg_Ok.wav" ) ;
			this->OnCancel();
		}
	}
	if(m_bnPage.Process(m_nMouseX, m_nMouseY,m_bClick))
	{
		if(m_bClick)
		{
			DXPlaySound ( "Sound/Dlg_Ok.wav" ) ;
			/*			char szFile[]="ini/play.ini";
			char szTitle[]="Link";
			char szSubTitle[]="Page";
			char szLink[512]="";
			m_bClick = false;
			::IniStrGet(szFile, szTitle, szSubTitle, szLink);
			::ShellExecute(m_hWnd, NULL, szLink, NULL, NULL, SW_SHOW);	*/
		}
	}
	if(m_bnRegist.Process(m_nMouseX, m_nMouseY,m_bClick))
	{
		if(m_bClick)
		{
			DXPlaySound ( "Sound/Dlg_Ok.wav" ) ;
			/*			char szFile[]="ini/play.ini";
			char szTitle[]="Link";
			char szSubTitle[]="Regist";
			char szLink[512]="";
			m_bClick = false;
			::IniStrGet(szFile, szTitle, szSubTitle, szLink);
			::ShellExecute(m_hWnd, NULL, szLink, NULL, NULL, SW_SHOW);	*/
		}
	}
	if(m_bnPay.Process(m_nMouseX, m_nMouseY,m_bClick))
	{
		if(m_bClick)
		{
			DXPlaySound ( "Sound/Dlg_Ok.wav" ) ;
			/*			char szFile[]="ini/play.ini";
			char szTitle[]="Link";
			char szSubTitle[]="Pay";
			char szLink[512]="";
			m_bClick = false;
			::IniStrGet(szFile, szTitle, szSubTitle, szLink);
			::ShellExecute(m_hWnd, NULL, szLink, NULL, NULL, SW_SHOW);	*/
		}
	}
	if(m_bnSystem.Process(m_nMouseX, m_nMouseY,m_bClick))
	{
		if(m_bClick)
		{
		DXPlaySound ( "Sound/Dlg_Ok.wav" ) ;
/*		m_setString.clear();
			CInternetSession	session;
			CInternetFile* file = NULL;
			
			// get url ...
			char szIniFile[] = "ini/play.ini";
			char szTitle[] = "Link";
			char szSubtitle[]= "System";
			char szUrl[1024];
			if(::IniStrGet(szIniFile, szTitle, szSubtitle, szUrl))
			{
				try{file = (CInternetFile*)session.OpenURL(szUrl);}
				catch(CInternetException* pEx){file = NULL; pEx->Delete();}
				if(file)
				{
					while(true)
					{
						CString string;
						if(!file->ReadString(string))
							break;
						m_setString.push_back(string);
						string.Empty();					
					}
					file->Close();
					delete	file;
				}
			}*/
		}
	}
	if(m_bnCredit.Process(m_nMouseX, m_nMouseY,m_bClick))
	{
		if(m_bClick)
		{
			DXPlaySound ( "Sound/Dlg_Ok.wav" ) ;
/*			m_setString.clear();
			CInternetSession	session;
			CInternetFile* file = NULL;
			
			// get url ...
			char szIniFile[] = "ini/play.ini";
			char szTitle[] = "Link";
			char szSubtitle[]= "Credit";
			char szUrl[1024];
			if(::IniStrGet(szIniFile, szTitle, szSubtitle, szUrl))
			{
				try{file = (CInternetFile*)session.OpenURL(szUrl);}
				catch(CInternetException* pEx){file = NULL; pEx->Delete();}
				if(file)
				{
					while(true)
					{
						CString string;
						if(!file->ReadString(string))
							break;
						m_setString.push_back(string);
						string.Empty();					
					}
					file->Close();
					delete	file;
				}
			}*/
		}
	}
	m_bClick = false;
}

void CGameDlg::ShowBG()
{
	const char szAni[] = "ani/play.ani";
	const char szTitle[] = "Bg";
	CAni* pAni = g_objGameDataSet.GetDataAni(szAni, szTitle);
	static unsigned char ucCha = 0;
	if(ucCha != 255)
		ucCha += 15;
	
	if(pAni)
	{
		CMyBitmap* pBmp = pAni->GetFrame(0);
		if(pBmp)
		{
			pBmp->SetColor(255, ucCha, ucCha, ucCha);
			pBmp->Show(0, 0);
		}
	}
//	this->ShowString();
	pAni = g_objGameDataSet.GetDataAni(szAni, "Logo1");
	if(pAni)
	{
		CMyBitmap* pBmp = pAni->GetFrame(0);
		if(pBmp)
		{
			pBmp->SetColor(255, ucCha, ucCha, ucCha);
			pBmp->Show(19, 27);
		}
	}
//	CMyBitmap::ShowString(70, 454, 0xffffffff, m_szVersion);
}

void CGameDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_nMouseX = point.x;
	m_nMouseY = point.y;

	CDialog::OnMouseMove(nFlags, point);
}

void CGameDlg::ShowString()
{
	int nAmount = m_setString.size();
	if(nAmount <= 4)
	{
		for(int i = 0; i < m_setString.size(); i ++)
			CMyBitmap::ShowString(220, 52+20*i, 0xffffff00, m_setString[i]);
	}
	else
	{
		for(int i = 0; i < 5; i ++)
		{
			CMyBitmap::ShowString(220, 52+20*i-m_nOffset, 0xffffff00, m_setString[i]);
		}
	}
	static int sCounter = 0;
	sCounter ++;
	if(sCounter == 2)
	{
		m_nOffset ++;
		sCounter = 0;
	}
	if(m_nOffset > 20 && nAmount > 4)
	{
		m_nOffset = 0;
		m_setString.push_back(m_setString[0]);
		m_setString.pop_front();
	}
}


void CMyButton::Init(const char* pszAniFile, const char* pszAniIndex, int nX, int nY)
{
	strcpy(m_szAniFile, pszAniFile);
	strcpy(m_szAniIndex, pszAniIndex);
	m_nX = nX;
	m_nY = nY;
}

BOOL CMyButton::Process(int nMouseX, int nMouseY,BOOL bClick)
{
	static unsigned char ucCha = 0;
	if(ucCha < 255)
		ucCha += 3;
	if(ucCha > 255)
		ucCha = 255;
	CAni* pAni = g_objGameDataSet.GetDataAni(m_szAniFile, m_szAniIndex);
	BOOL bR = false;
	if(pAni)
	{
		CMyBitmap* pBmp = pAni->GetFrame(0);
		if(pBmp)
		{	
			CMySize sizeBmp;
			sizeBmp.iWidth = _BTN_WIDTH;
			sizeBmp.iHeight = _BTN_HEIGHT;
			if(nMouseX > m_nX && nMouseY > m_nY && 
				nMouseX < m_nX + sizeBmp.iWidth &&
				nMouseY < m_nY + sizeBmp.iHeight && 
				pBmp )
			{
				if (bClick)
					pBmp = pAni->GetFrame(1);
				bR = true;
			}
			if(pBmp)
			{
				pBmp->SetColor(ucCha, ucCha, ucCha, ucCha);
				pBmp->Show(m_nX, m_nY);
			}
		}
	}
	return bR;
}



void CGameDlg::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
//	m_bClick = true;
	CDialog::OnLButtonDblClk(nFlags, point);
}

void CGameDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_bClick = true;
	CDialog::OnLButtonDown(nFlags, point);
}

void CGameDlg::OnDestroy() 
{

#ifndef _SOUND_DISABLE
	DXDestroy() ;
#endif

	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
}

⌨️ 快捷键说明

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