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

📄 defdialog.cpp

📁 用Visual C++实现的扫雷程序。基本功能都已实现。用到了很多VC的控件知识。
💻 CPP
字号:
// DEFDIALOG.cpp : implementation file
//

#include "stdafx.h"
#include "扫雷.h"
#include "DEFDIALOG.h"

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

/////////////////////////////////////////////////////////////////////////////
// DEFDIALOG dialog


DEFDIALOG::DEFDIALOG(CWnd* pParent /*=NULL*/)
	: CDialog(DEFDIALOG::IDD, pParent)
{
	//{{AFX_DATA_INIT(DEFDIALOG)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	Width.Empty();
	Heigh.Empty();
	BombNum.Empty();
}


void DEFDIALOG::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DEFDIALOG)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(DEFDIALOG, CDialog)
	//{{AFX_MSG_MAP(DEFDIALOG)
	ON_BN_CLICKED(IDC_OK, OnOk)
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	ON_BN_CLICKED(IDC_CANCEL, OnCancel)
	ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
	ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DEFDIALOG message handlers

BOOL DEFDIALOG::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	WindowWidth.SubclassDlgItem(IDC_EDIT1,this);
	WindowHeigh.SubclassDlgItem(IDC_EDIT2,this);
	WindowBombNum.SubclassDlgItem(IDC_EDIT3,this);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}



void DEFDIALOG::OnCancel() 
{
	// TODO: Add your control notification handler code here
	CDialog::EndDialog(0);
}

void DEFDIALOG::OnOk() 
{
	// TODO: Add your control notification handler code here
	CMyApp *App=(CMyApp *)AfxGetApp();
	App->Afx_Game.Width=atoi(Width);
	App->Afx_Game.Heigh=atoi(Heigh);
	App->Afx_Game.BombNum=atoi(BombNum);
	if (App->Afx_Game.Width<12) App->Afx_Game.Width=12;
	if (App->Afx_Game.Heigh<12) App->Afx_Game.Heigh=12;
	if (App->Afx_Game.BombNum<4) App->Afx_Game.BombNum=4;
	if (App->Afx_Game.Width>24) App->Afx_Game.Width=24;
	if (App->Afx_Game.Heigh>24) App->Afx_Game.Heigh=24;
	if (App->Afx_Game.BombNum>255) App->Afx_Game.BombNum=255;
	if (App->Afx_Game.BombNum>(App->Afx_Game.Width*App->Afx_Game.Heigh)/2) 
		App->Afx_Game.BombNum=(App->Afx_Game.Width*App->Afx_Game.Heigh)/2;

	CDialog::EndDialog(0);
}


void DEFDIALOG::OnChangeEdit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	  WindowWidth.GetWindowText(Width);
	// TODO: Add your control notification handler code here
	
}	

	

void DEFDIALOG::OnChangeEdit2() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	WindowHeigh.GetWindowText(Heigh);
	// TODO: Add your control notification handler code here
	
}

void DEFDIALOG::OnChangeEdit3() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	WindowBombNum.GetWindowText(BombNum);
	// TODO: Add your control notification handler code here
	
}

BOOL DEFDIALOG::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN)
	if(pMsg->hwnd==WindowWidth.m_hWnd || pMsg->hwnd==WindowHeigh.m_hWnd || pMsg->hwnd==WindowBombNum.m_hWnd)
		if(!(pMsg->wParam<='9' && pMsg->wParam>='0' || pMsg->wParam==8)) return 1;

	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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