MFC源代码:
// DlgCustom.cpp : implementation file
//
#include "stdafx.h"
#include "mine.h"
#include "DlgCustom.h"
#include "MineWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgCustom dialog
CDlgCustom::CDlgCustom(CWnd* pParent /*=NULL*/)
: CDialog(CDlgCustom::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgCustom)
m_uyNum = 0;
m_uxNum = 0;
m_uMineNum = 0;
//}}AFX_DATA_INIT
}
void CDlgCustom::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgCustom)
DDX_Text(pDX, IDC_EDIT1, m_uyNum);
DDV_MinMaxUInt(pDX, m_uyNum, 8, 100);
DDX_Text(pDX, IDC_EDIT2, m_uxNum);
DDV_MinMaxUInt(pDX, m_uxNum, 8, 100);
DDX_Text(pDX, IDC_EDIT3, m_uMineNum);
DDV_MinMaxUInt(pDX, m_uMineNum, 1, 1000);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgCustom, CDialog)
//{{AFX_MSG_MAP(CDlgCustom)
ON_BN_CLICKED(IDC_OK, OnOk)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgCustom message handlers
void CDlgCustom::OnOk()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_uMineNum > m_uxNum*m_uyNum)
{
MessageBox("神坑", "-.-", MB_OK);
return;
}
CMineWnd* pMineWnd = (CMineWnd*)AfxGetMainWnd();
pMineWnd->SetDataFromCustom(m_uxNum, m_uyNum, m_uMineNum);
CDialog::OnOK();
}
void CDlgCustom::InitialData(UINT uxNum, UINT uyNum, UINT uMineNum)
{
m_uxNum = uxNum;
m_uyNum = uyNum;
m_uMineNum = uMineNum;
}
// DlgNewRec.cpp : implementation file
//
#include "stdafx.h"
#include "mine.h"
#include "DlgNewRec.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgNewRec dialog
CDlgNewRec::CDlgNewRec(CWnd* pParent /*=NULL*/)
: CDialog(CDlgNewRec::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgNewRec)
m_strCamp = _T("");
m_strHolder = _T("");
m_strLevel = _T("");
//}}AFX_DATA_INIT
}
void CDlgNewRec::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgNewRec)
DDX_Text(pDX, IDC_EDIT_CAMP, m_strCamp);
DDX_Text(pDX, IDC_EDIT_HOLDER, m_strHolder);
DDX_Text(pDX, IDC_LEVEL, m_strLevel);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgNewRec, CDialog)
//{{AFX_MSG_MAP(CDlgNewRec)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgNewRec message handlers
void CDlgNewRec::SetLevel(UINT uLevel)
{
switch(uLevel)
{
case LEVEL_PRIMARY:
m_strLevel = "初级记录:";
break;
case LEVEL_SECONDARY:
m_strLevel = "中级记录:";
break;
case LEVEL_ADVANCE:
m_strLevel = "高级记录:";
break;
default:
break;
}
}
CString CDlgNewRec::GetRecCamp()
{
return m_strCamp;
}
CString CDlgNewRec::GetRecHolder()
{
return m_strHolder;
}
// DlgRank.cpp : implementation file
//
#include "stdafx.h"
#include "mine.h"
#include "DlgRank.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgRank dialog
CDlgRank::CDlgRank(CWnd* pParent /*=NULL*/)
: CDialog(CDlgRank::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgRank)
m_strAdvCamp = _T("");
m_strAdvHolder = _T("");
m_strPriCamp = _T("");
m_strPriHolder = _T("");
m_strAdvScore = _T("");
m_strPriScore = _T("");
m_strSecScore = _T("");
m_strSecCamp = _T("");
m_strSecHolder = _T("");
//}}AFX_DATA_INIT
}
void CDlgRank::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgRank)
DDX_Text(pDX, IDC_ADV_CAMP, m_strAdvCamp);
DDX_Text(pDX, IDC_ADV_HOLDER, m_strAdvHolder);
DDX_Text(pDX, IDC_PRI_CAMP, m_strPriCamp);
DDX_Text(pDX, IDC_PRI_HOLDER, m_strPriHolder);
DDX_Text(pDX, IDC_ADV_BEST, m_strAdvScore);
DDX_Text(pDX, IDC_PRI_BEST, m_strPriScore);
DDX_Text(pDX, IDC_SEC_BEST, m_strSecScore);
DDX_Text(pDX, IDC_SEC_CAMP, m_strSecCamp);
DDX_Text(pDX, IDC_SEC_HOLDER, m_strSecHolder);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgRank, CDialog)
//{{AFX_MSG_MAP(CDlgRank)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgRank message handlers
void CDlgRank::SetPriRecord(CString camp, CString holder, UINT score)
{
m_strPriCamp = camp;
m_strPriHolder = holder;
m_strPriScore.Format("%d%s", score, "秒");
}
void CDlgRank::SetSecRecord(CString camp, CString holder, UINT score)
{
m_strSecCamp = camp;
m_strSecHolder = holder;
m_strSecScore.Format("%d%s", score, "秒");
}
void CDlgRank::SetAdvRecord(CString camp, CString holder, UINT score)
{
m_strAdvCamp = camp;
m_strAdvHolder = holder;
m_strAdvScore.Format("%d%s", score, "秒");
}
// Mine.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Mine.h"
#include "MineWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMineApp
BEGIN_MESSAGE_MAP(CMineApp, CWinApp)
//{{AFX_MSG_MAP(CMineApp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMineApp construction
CMineApp::CMineApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMineApp object
CMineApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMineApp initialization
const CString classname = _T("MineClass");
BOOL CMineApp::InitInstance()
{
//读取保存的设置
char exeFullPath[MAX_PATH];
GetModuleFileName(NULL, exeFullPath, MAX_PATH);
CString strPath(exeFullPath);
CString configPath =strPath.Left(strPath.ReverseFind('\\'));
configPath += "\\config.ini";
m_xMineNum = GetPrivateProfileInt("MINE", "XNUM", 9, configPath);
m_yMineNum = GetPrivateProfileInt("MINE", "YNUM", 9, configPath);
m_pMineWnd = new CMineWnd();
WNDCLASS wc;
ZeroMemory(&wc, sizeof(WNDCLASS));
wc.hInstance = AfxGetInstanceHandle();
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpfnWndProc = ::DefWindowProc;
wc.hCursor = LoadCursor(IDC_ARROW);
wc.hIcon = LoadIcon(IDR_MAINFRAME);
wc.lpszClassName = classname;
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
if(!AfxRegisterClass(&wc))
{
AfxMessageBox("注册窗口失败!");
return FALSE;
}
UINT uWidth = DEFAULT_FRAME_X + m_xMineNum*MINE_WIDTH + LINE_WIDTH_0*3 +
SIDE_WIDTH_0 + SIDE_WIDTH_1;
UINT uHeight = DEFAULT_FRAME_Y + m_yMineNum*MINE_HEIGHT + LINE_WIDTH_0*3 +
SIDE_WIDTH_0*2 + SIDE_WIDTH_1 + SHELL_S_H;
UINT uxPos = GetSystemMetrics(SM_CXSCREEN)/2 - uWidth/2;
UINT uyPos = GetSystemMetrics(SM_CYSCREEN)/2 - uHeight/2;
if(!m_pMineWnd->CreateEx(NULL, classname, _T("扫雷"), WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
uxPos, uyPos, uWidth, uHeight, NULL, NULL))
{
AfxMessageBox("创建主窗口失败!");
return FALSE;
}
m_pMainWnd = m_pMineWnd;
m_pMineWnd->ShowWindow(SW_SHOW);
m_pMineWnd->UpdateWindow();
return TRUE;
}
主程序:
// Mine.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Mine.h"
#include "MineWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMineApp
BEGIN_MESSAGE_MAP(CMineApp, CWinApp)
//{{AFX_MSG_MAP(CMineApp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMineApp construction
CMineApp::CMineApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMineApp object
CMineApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMineApp initialization
const CString classname = _T("MineClass");
BOOL CMineApp::InitInstance()
{
//读取保存的设置
char exeFullPath[MAX_PATH];
GetModuleFileName(NULL, exeFullPath, MAX_PATH);
CString strPath(exeFullPath);
CString configPath =strPath.Left(strPath.ReverseFind('\\'));
configPath += "\\config.ini";
m_xMineNum = GetPrivateProfileInt("MINE", "XNUM", 9, configPath);
m_yMineNum = GetPrivateProfileInt("MINE", "YNUM", 9, configPath);
m_pMineWnd = new CMineWnd();
WNDCLASS wc;
ZeroMemory(&wc, sizeof(WNDCLASS));
wc.hInstance = AfxGetInstanceHandle();
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpfnWndProc = ::DefWindowProc;
wc.hCursor = LoadCursor(IDC_ARROW);
wc.hIcon = LoadIcon(IDR_MAINFRAME);
wc.lpszClassName = classname;
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
if(!AfxRegisterClass(&wc))
{
AfxMessageBox("注册窗口失败!");
return FALSE;
}
UINT uWidth = DEFAULT_FRAME_X + m_xMineNum*MINE_WIDTH + LINE_WIDTH_0*3 +
SIDE_WIDTH_0 + SIDE_WIDTH_1;
UINT uHeight = DEFAULT_FRAME_Y + m_yMineNum*MINE_HEIGHT + LINE_WIDTH_0*3 +
SIDE_WIDTH_0*2 + SIDE_WIDTH_1 + SHELL_S_H;
UINT uxPos = GetSystemMetrics(SM_CXSCREEN)/2 - uWidth/2;
UINT uyPos = GetSystemMetrics(SM_CYSCREEN)/2 - uHeight/2;
if(!m_pMineWnd->CreateEx(NULL, classname, _T("扫雷"), WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
uxPos, uyPos, uWidth, uHeight, NULL, NULL))
{
AfxMessageBox("创建主窗口失败!");
return FALSE;
}
m_pMainWnd = m_pMineWnd;
m_pMineWnd->ShowWindow(SW_SHOW);
m_pMineWnd->UpdateWindow();
return TRUE;
}