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

📄 dlggameparameter.cpp

📁 ◆◆◆ 《投掷飞镖记分工具》◆◆◆ 操作系统 : Windows Mobile 5.0 说明 : 中秋节和家人赏月
💻 CPP
字号:
// DlgGameParameter.cpp : 实现文件
//

#include "stdafx.h"
#include "DartScore.h"
#include "DlgGameParameter.h"


// CDlgGameParameter 对话框

IMPLEMENT_DYNAMIC(CDlgGameParameter, CDialogWM)

CDlgGameParameter::CDlgGameParameter(CWnd* pParent /*=NULL*/)
	: CDialogWM(CDlgGameParameter::IDD, IDR_MENU_OKCANCEL, pParent)
	, m_nCycleTimes ( 0 )
	, m_nDartNum ( 0 )
{

}

CDlgGameParameter::~CDlgGameParameter()
{
}

void CDlgGameParameter::DoDataExchange(CDataExchange* pDX)
{
	CDialogWM::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDlgGameParameter, CDialogWM)
	ON_BN_CLICKED(IDC_BUTTON_Add, &CDlgGameParameter::OnBnClickedButtonAdd)
	ON_BN_CLICKED(IDC_BUTTON_Del, &CDlgGameParameter::OnBnClickedButtonDel)
	ON_WM_TIMER()
	ON_LBN_SETFOCUS(IDC_LIST1, &CDlgGameParameter::OnLbnSetfocusList1)
	ON_WM_DESTROY()
END_MESSAGE_MAP()


// CDlgGameParameter 消息处理程序

void CDlgGameParameter::OnBnClickedButtonAdd()
{
	CString csName;
	GetDlgItemText ( IDC_EDIT_Name, csName );
	csName.TrimLeft(); csName.TrimRight ();
	if ( !csName.IsEmpty() )
	{
		CListBox *pListBox = (CListBox*)GetDlgItem(IDC_LIST1);
		ASSERT ( pListBox );
		if ( pListBox->FindString ( 0, csName ) >= 0 )
		{
			AfxMessageBox ( FormatString ( _T("Player [%s] is exist"), csName ) );
		}
		else
		{
			int nItem = pListBox->AddString ( csName );
			if ( nItem > 0 ) pListBox->SetCurSel ( nItem );
			SetDlgItemText ( IDC_EDIT_Name, _T("") );
		}
	}
	

	SetTimer ( TIMERID_SETFOCUS_TO_NAME_EDIT, 10, NULL );
}

void CDlgGameParameter::OnBnClickedButtonDel()
{
	CListBox *pListBox = (CListBox*)GetDlgItem(IDC_LIST1);
	ASSERT ( pListBox );
	int nCurSel = pListBox->GetCurSel ();
	if ( nCurSel >= 0 )
		pListBox->DeleteString ( nCurSel );
}

void CDlgGameParameter::OnOK(void)
{
	m_StrAry_PlayersName.RemoveAll ();
	CListBox *pListBox = (CListBox*)GetDlgItem(IDC_LIST1);
	ASSERT ( pListBox );
	if ( pListBox->GetCount() < 1 )
	{
		AfxMessageBox ( _T("Players too little") );
		return;
	}
	for ( int i=0; i<pListBox->GetCount(); i++ )
	{
		CString csText;
		pListBox->GetText ( i, csText );
		m_StrAry_PlayersName.Add ( csText );
	}

	m_nCycleTimes = GetDlgItemInt ( IDC_EDIT_CycleTimes, NULL, FALSE );
	if ( m_nCycleTimes < 1 )
	{
		AfxMessageBox ( _T("Cycle times too little") );
		return;
	}

	m_nDartNum = GetDlgItemInt ( IDC_EDIT_DartNum, NULL, FALSE );
	if ( m_nDartNum < 1 )
	{
		AfxMessageBox ( _T("Dart too little") );
		return;
	}

	CDialog::OnOK ();
}

void CDlgGameParameter::OnTimer(UINT_PTR nIDEvent)
{
	if ( nIDEvent == TIMERID_SETFOCUS_TO_NAME_EDIT )
	{
		KillTimer ( nIDEvent );
		GetDlgItem(IDC_EDIT_Name)->SetFocus();
	}

	CDialogWM::OnTimer(nIDEvent);
}

void CDlgGameParameter::OnInit(void)
{
	SetCtrlValueFromReg ();
	CDialogWM::OnInit ();
}

void CDlgGameParameter::OnLbnSetfocusList1()
{
	CListBox *pListBox = (CListBox*)GetDlgItem(IDC_LIST1);
	ASSERT ( pListBox );
	if ( pListBox->GetCurSel () < 0 && pListBox->GetCount () > 0 )
	{
		pListBox->SetCurSel ( 0 );
	}
}

void CDlgGameParameter::SetCtrlValueFromReg ()
{
	SetDlgItemText ( IDC_EDIT_CycleTimes, AfxGetApp()->GetProfileString ( _T("Setting"), IntToString(IDC_EDIT_CycleTimes), _T("50") ) );
	SetDlgItemText ( IDC_EDIT_DartNum, AfxGetApp()->GetProfileString ( _T("Setting"), IntToString(IDC_EDIT_DartNum), _T("3") ) );

	int nPlayerNum = AfxGetApp()->GetProfileInt ( _T("Setting"), _T("PlayerNum"), 0 );
	CListBox *pListBox = (CListBox*)GetDlgItem(IDC_LIST1);
	ASSERT ( pListBox );
	for ( int i=0; i<nPlayerNum; i++ )
	{
		CString csText = AfxGetApp()->GetProfileString ( _T("Setting"), IntToString(i) );
		csText.TrimLeft(); csText.TrimRight();
		if ( csText.IsEmpty() ) continue;
		pListBox->AddString ( csText );
	}
}

void CDlgGameParameter::SaveCtrlValueToReg ()
{
	CString csText;
	
	GetDlgItemText ( IDC_EDIT_CycleTimes, csText );
	AfxGetApp()->WriteProfileString ( _T("Setting"), IntToString(IDC_EDIT_CycleTimes), csText );

	GetDlgItemText ( IDC_EDIT_DartNum, csText );
	AfxGetApp()->WriteProfileString ( _T("Setting"), IntToString(IDC_EDIT_DartNum), csText );

	CListBox *pListBox = (CListBox*)GetDlgItem(IDC_LIST1);
	ASSERT ( pListBox );
	int nPlayerNum = pListBox->GetCount();
	AfxGetApp()->WriteProfileInt ( _T("Setting"), _T("PlayerNum"), nPlayerNum );
	for ( int i=0; i<nPlayerNum; i++ )
	{
		CString csText;
		pListBox->GetText ( i, csText );
		csText.TrimLeft(); csText.TrimRight();
		if ( csText.IsEmpty() ) continue;
		AfxGetApp()->WriteProfileString ( _T("Setting"), IntToString(i), csText );
	}
}

void CDlgGameParameter::OnDestroy()
{
	SaveCtrlValueToReg ();

	CDialogWM::OnDestroy();
}

⌨️ 快捷键说明

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