www.pudn.com > goodchessGame.zip > OptionsDialog.cpp


// OptionsDialog.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "FiveInOne.h" 
#include "OptionsDialog.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// COptionsDialog dialog 
COptionsDialog::COptionsDialog(CWnd* pParent /*=NULL*/) 
	: CDialog(COptionsDialog::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(COptionsDialog) 
	m_nPlayNetwork = -1; 
	m_nNumOfPlayers = -1; 
	m_strPlayerName = _T(""); 
	m_IsHost = FALSE; 
	m_strServerComputeName = _T(""); 
	//}}AFX_DATA_INIT 
 
	m_nGameID = GAME_MARRIAGE; 
	m_nNumOfTimesTimerCalled = 0; 
} 
 
 
void COptionsDialog::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(COptionsDialog) 
	DDX_Control(pDX, IDC_SERVERCOMPUTERNAME, m_ctrlServerComputerName); 
	DDX_Control(pDX, IDC_CALLBREAK, m_ctrlCallbreak); 
	DDX_Control(pDX, IDC_HEARTS, m_ctrlHearts); 
	DDX_Control(pDX, IDC_MARRIAGE, m_ctrlMarriage); 
	DDX_Control(pDX, IDC_POPLU, m_ctrlPoplu); 
	DDX_Control(pDX, IDC_TWENTYNINE, m_ctrlTwentyNine); 
	DDX_Control(pDX, IDC_PLAYERNAME, m_ctrlPlayerName); 
	DDX_Radio(pDX, IDC_PLAYONNETWORK, m_nPlayNetwork); 
	DDX_Radio(pDX, IDC_TWO, m_nNumOfPlayers); 
	DDX_Text(pDX, IDC_PLAYERNAME, m_strPlayerName); 
	DDV_MaxChars(pDX, m_strPlayerName, 10); 
	DDX_Check(pDX, IDC_ISHOST, m_IsHost); 
	DDX_Text(pDX, IDC_SERVERCOMPUTERNAME, m_strServerComputeName); 
	DDV_MaxChars(pDX, m_strServerComputeName, 10); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(COptionsDialog, CDialog) 
	//{{AFX_MSG_MAP(COptionsDialog) 
	ON_BN_CLICKED(IDC_CALLBREAK, OnCallbreak) 
	ON_BN_CLICKED(IDC_HEARTS, OnHearts) 
	ON_BN_CLICKED(IDC_MARRIAGE, OnMarriage) 
	ON_BN_CLICKED(IDC_POPLU, OnPoplu) 
	ON_BN_CLICKED(IDC_TWENTYNINE, OnTwentynine) 
	ON_WM_TIMER() 
	ON_BN_CLICKED(IDC_PLAYONNETWORK, OnPlayonnetwork) 
	ON_BN_CLICKED(IDC_PLAYONSINGLECOMPUTER, OnPlayonsinglecomputer) 
	ON_BN_CLICKED(IDC_ISHOST, OnIshost) 
	ON_WM_PAINT() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// COptionsDialog message handlers 
 
BOOL COptionsDialog::PreTranslateMessage(MSG* pMsg)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
 
	if(pMsg->message == WM_MOUSEMOVE ) 
	{ 
		POINT pt = pMsg->pt;     
		ScreenToClient( &pt ); 
 
		// this is the only function to call 
		m_toolTip.ShowToolTip( (CPoint)pt ); 
		int n_TimerID = SetTimer(1, 300, NULL); 
	} 
	if(pMsg->message == WM_LBUTTONDOWN) 
	{ 
		POINT pt = pMsg->pt;     
		ScreenToClient( &pt ); 
 
		// this is the only function to call 
		m_toolTip.EraseToolTipDisplay( (CPoint)pt ); 
	} 
 
	return CDialog::PreTranslateMessage(pMsg); 
} 
 
BOOL COptionsDialog::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	 
	CRect Rect; 
	GetClientRect(&Rect); 
 
	m_nNumOfPlayers = 0; 
	m_nPlayNetwork = 0; 
	m_strPlayerName = _T("xxx"); 
	m_strServerComputeName = _T("yyy"); 
 
	UpdateData(FALSE); 
 
	CButton *pButton = (CButton*)GetDlgItem(IDC_MARRIAGE); 
	pButton->SetCheck(BST_CHECKED); 
	OnMarriage(); 
 
	OnIshost(); 
	 
	m_toolTip.Create( this );    // after creating, add the information 
	UINT control_ID = IDC_MARRIAGE; 
	CStringArray information;  
	CString str = _T("Play a game of Marriage"); 
	information.Add(str); 
    m_toolTip.AddControlInfo( control_ID, information); 
    information.RemoveAll(); 
	str = _T("Play a game of Call Break"); 
	control_ID = IDC_CALLBREAK; 
	information.Add(str); 
	m_toolTip.AddControlInfo( control_ID, information); 
	information.RemoveAll(); 
	str = _T("Play a game of Hearts"); 
	control_ID = IDC_HEARTS; 
	information.Add(str); 
	m_toolTip.AddControlInfo( control_ID, information); 
	information.RemoveAll(); 
	str = _T("Play a game of Poplu"); 
	control_ID = IDC_POPLU; 
	information.Add(str); 
	m_toolTip.AddControlInfo( control_ID, information); 
	information.RemoveAll(); 
	str = _T("Play a game of Twenty Nine"); 
	control_ID = IDC_TWENTYNINE; 
	information.Add(str); 
	m_toolTip.AddControlInfo( control_ID, information); 
	information.RemoveAll(); 
	str = _T("Accept the settings"); 
	control_ID = IDOK; 
	information.Add(str); 
	m_toolTip.AddControlInfo( control_ID, information); 
	information.RemoveAll(); 
	str = _T("Reject and quit"); 
	control_ID = IDCANCEL; 
	information.Add(str); 
	m_toolTip.AddControlInfo( control_ID, information); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void COptionsDialog::OnCallbreak()  
{ 
	// TODO: Add your control notification handler code here 
	 
	m_nGameID = GAME_CALLBREAK; 
 
	CWnd *pWnd = GetDlgItem(IDC_PLAYONNETWORK); 
	pWnd->EnableWindow(TRUE); 
	pWnd = GetDlgItem(IDC_PLAYONSINGLECOMPUTER); 
	pWnd->EnableWindow(TRUE); 
 
	UpdateData(TRUE); 
 
	if(m_nPlayNetwork == 0) 
	{ 
        if(m_IsHost) 
		{ 
       		pWnd = (CWnd*) GetDlgItem(IDC_FOUR); 
			pWnd->EnableWindow(TRUE); 
		} 
		else 
		{ 
       		pWnd = (CWnd*) GetDlgItem(IDC_FOUR); 
			pWnd->EnableWindow(FALSE); 
		} 
	} 
	else 
		pWnd = (CWnd*) GetDlgItem(IDC_FOUR); 
		pWnd->EnableWindow(TRUE); 
	 
	pWnd =(CWnd*) GetDlgItem(IDC_TWO); 
	pWnd->EnableWindow(FALSE); 
	pWnd =(CWnd*) GetDlgItem(IDC_THREE); 
	pWnd->EnableWindow(FALSE); 
	pWnd =(CWnd*) GetDlgItem(IDC_FIVE); 
	pWnd->EnableWindow(FALSE); 
	pWnd =(CWnd*) GetDlgItem(IDC_SIX); 
	pWnd->EnableWindow(FALSE); 
 
	m_nNumOfPlayers = 2; 
	UpdateData(FALSE); 
} 
 
void COptionsDialog::OnHearts()  
{ 
	// TODO: Add your control notification handler code here 
	 
	m_nGameID = GAME_HEARTS; 
 
	CWnd *pWnd = GetDlgItem(IDC_PLAYONNETWORK); 
	pWnd->EnableWindow(TRUE); 
	pWnd = GetDlgItem(IDC_PLAYONSINGLECOMPUTER); 
	pWnd->EnableWindow(TRUE); 
 
	pWnd =(CWnd*) GetDlgItem(IDC_TWO); 
	pWnd->EnableWindow(FALSE); 
	pWnd =(CWnd*) GetDlgItem(IDC_THREE); 
	pWnd->EnableWindow(FALSE); 
	pWnd = (CWnd*) GetDlgItem(IDC_FOUR); 
	pWnd->EnableWindow(TRUE); 
	pWnd =(CWnd*) GetDlgItem(IDC_FIVE); 
	pWnd->EnableWindow(FALSE); 
	pWnd =(CWnd*) GetDlgItem(IDC_SIX); 
	pWnd->EnableWindow(FALSE); 
 
	UpdateData(TRUE); 
	m_nNumOfPlayers = 2; 
	UpdateData(FALSE); 
} 
 
void COptionsDialog::OnMarriage()  
{ 
	// TODO: Add your control notification handler code here 
	 
	m_nGameID = GAME_MARRIAGE; 
 
	CWnd *pWnd = GetDlgItem(IDC_PLAYONNETWORK); 
	pWnd->EnableWindow(TRUE); 
	pWnd = GetDlgItem(IDC_PLAYONSINGLECOMPUTER); 
	pWnd->EnableWindow(TRUE); 
 
	UpdateData(TRUE); 
 
	if(m_nPlayNetwork == 0) 
	{ 
        if(m_IsHost) 
		{ 
			pWnd = GetDlgItem(IDC_TWO); 
			pWnd->EnableWindow(TRUE); 
			pWnd = GetDlgItem(IDC_THREE); 
			pWnd->EnableWindow(TRUE); 
			pWnd = GetDlgItem(IDC_FOUR); 
			pWnd->EnableWindow(TRUE); 
		} 
		else 
		{	 
			pWnd = GetDlgItem(IDC_TWO); 
			pWnd->EnableWindow(FALSE); 
			pWnd = GetDlgItem(IDC_THREE); 
			pWnd->EnableWindow(FALSE); 
			pWnd = GetDlgItem(IDC_FOUR); 
			pWnd->EnableWindow(FALSE); 
		} 
	} 
	else 
	{ 
		pWnd = GetDlgItem(IDC_TWO); 
		pWnd->EnableWindow(TRUE); 
		pWnd = GetDlgItem(IDC_THREE); 
		pWnd->EnableWindow(TRUE); 
		pWnd = GetDlgItem(IDC_FOUR); 
		pWnd->EnableWindow(TRUE); 
	} 
 
 
	pWnd = GetDlgItem(IDC_FIVE); 
	pWnd->EnableWindow(FALSE); 
	pWnd = GetDlgItem(IDC_SIX); 
	pWnd->EnableWindow(FALSE); 
 
	m_nNumOfPlayers = 2; 
	UpdateData(FALSE); 
} 
 
void COptionsDialog::OnPoplu()  
{ 
	// TODO: Add your control notification handler code here 
 
	m_nGameID = GAME_POPLU; 
 
	CWnd *pWnd = GetDlgItem(IDC_PLAYONNETWORK); 
	pWnd->EnableWindow(TRUE); 
	pWnd = GetDlgItem(IDC_PLAYONSINGLECOMPUTER); 
	pWnd->EnableWindow(TRUE); 
 
 
	pWnd =(CWnd*) GetDlgItem(IDC_TWO); 
	pWnd->EnableWindow(TRUE); 
	pWnd =(CWnd*) GetDlgItem(IDC_THREE); 
	pWnd->EnableWindow(TRUE); 
	pWnd =(CWnd*) GetDlgItem(IDC_FOUR); 
	pWnd->EnableWindow(TRUE); 
	pWnd =(CWnd*) GetDlgItem(IDC_FIVE); 
	pWnd->EnableWindow(TRUE); 
	pWnd =(CWnd*) GetDlgItem(IDC_SIX); 
	pWnd->EnableWindow(TRUE); 
 
	UpdateData(TRUE); 
} 
 
void COptionsDialog::OnTwentynine()  
{ 
	// TODO: Add your control notification handler code here 
	 
	m_nGameID = GAME_TWENTYNINE; 
 
	CWnd *pWnd = GetDlgItem(IDC_PLAYONNETWORK); 
	pWnd->EnableWindow(TRUE); 
	pWnd = GetDlgItem(IDC_PLAYONSINGLECOMPUTER); 
	pWnd->EnableWindow(TRUE); 
 
 
	pWnd =(CWnd*) GetDlgItem(IDC_TWO); 
	pWnd->EnableWindow(TRUE); 
	pWnd =(CWnd*) GetDlgItem(IDC_THREE); 
	pWnd->EnableWindow(FALSE); 
	pWnd = (CWnd*) GetDlgItem(IDC_FOUR); 
	pWnd->EnableWindow(TRUE); 
	pWnd =(CWnd*) GetDlgItem(IDC_FIVE); 
	pWnd->EnableWindow(FALSE); 
	pWnd =(CWnd*) GetDlgItem(IDC_SIX); 
	pWnd->EnableWindow(FALSE); 
 
	UpdateData(TRUE); 
	m_nNumOfPlayers = 2; 
	UpdateData(FALSE); 
} 
 
void COptionsDialog::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
	m_nNumOfTimesTimerCalled++; 
	if(m_nNumOfTimesTimerCalled == 10) 
	{ 
		m_toolTip.EraseToolTipDisplay(); 
		m_nNumOfTimesTimerCalled = 0; 
		KillTimer(1); 
	} 
 
	CDialog::OnTimer(nIDEvent); 
} 
 
void COptionsDialog::OnCancel() 
{ 
	CDialog::OnCancel(); 
} 
 
void COptionsDialog::OnOK() 
{ 
	CDialog::OnOK(); 
} 
void COptionsDialog::OnPlayonnetwork()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(TRUE); 
 
	if(m_nPlayNetwork == 0) 
	{ 
		CButton *pButton = (CButton*) GetDlgItem(IDC_ISHOST); 
		pButton->EnableWindow(TRUE); 
 
		CWnd *pWnd = GetDlgItem(IDC_SERVERCOMPUTERNAME); 
		if(pButton->GetCheck() == 1) 
			pWnd->EnableWindow(FALSE); 
		else 
			pWnd->EnableWindow(TRUE); 
	}	 
	OnIshost(); 
} 
 
void COptionsDialog::OnPlayonsinglecomputer()  
{ 
	// TODO: Add your control notification handler code here 
	 
	UpdateData(TRUE); 
 
	if(m_nPlayNetwork == 1) 
	{ 
		CWnd *pWnd = GetDlgItem(IDC_ISHOST); 
		pWnd->EnableWindow(FALSE); 
 
		pWnd = GetDlgItem(IDC_SERVERCOMPUTERNAME); 
		pWnd->EnableWindow(FALSE); 
	} 
 
	switch(m_nGameID) 
	{ 
	case GAME_MARRIAGE: 
		{ 
			OnMarriage(); 
		} 
		break; 
	case GAME_TWENTYNINE: 
		{ 
			OnTwentynine(); 
		} 
		break; 
	case GAME_CALLBREAK: 
		{ 
			OnCallbreak(); 
		} 
		break; 
	case GAME_POPLU: 
		{ 
			OnPoplu(); 
		} 
		break; 
	case GAME_HEARTS: 
		{ 
			OnHearts(); 
		} 
		break; 
	} 
} 
 
void COptionsDialog::OnIshost()  
{ 
	// TODO: Add your control notification handler code here 
	 
	UpdateData(TRUE); 
 
	if(!m_IsHost) 
	{ 
		m_ctrlServerComputerName.EnableWindow(TRUE); 
		CWnd *pWnd = GetDlgItem(IDC_TWO); 
		pWnd->EnableWindow(FALSE); 
 
		pWnd = GetDlgItem(IDC_THREE); 
		pWnd->EnableWindow(FALSE); 
 
		pWnd = GetDlgItem(IDC_FOUR); 
		pWnd->EnableWindow(FALSE); 
 
		pWnd = GetDlgItem(IDC_FIVE); 
		pWnd->EnableWindow(FALSE); 
 
		pWnd = GetDlgItem(IDC_SIX); 
		pWnd->EnableWindow(FALSE); 
	} 
	else 
	{ 
		m_ctrlServerComputerName.EnableWindow(FALSE); 
	 
		switch(m_nGameID) 
		{ 
		case GAME_MARRIAGE: 
			{ 
				OnMarriage(); 
			} 
			break; 
		case GAME_TWENTYNINE: 
			{ 
				OnTwentynine(); 
			} 
			break; 
		case GAME_CALLBREAK: 
			{ 
				OnCallbreak(); 
			} 
			break; 
		case GAME_POPLU: 
			{ 
				OnPoplu(); 
			} 
			break; 
		case GAME_HEARTS: 
			{ 
				OnHearts(); 
			} 
			break; 
		} 
	} 
} 
 
void COptionsDialog::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	// TODO: Add your message handler code here 
 
	CBrush brush; 
	CBitmap bmp; 
	CRect   rcBounds; 
		 
	// Do not call CDialog::OnPaint() for painting messages 
}