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


// CallBreakSocreDialog.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "FiveInOne.h" 
#include "CallBreakSocreDialog.h" 
#include "CallBreak.h" 
 
// CCallBreakSocreDialog dialog 
 
IMPLEMENT_DYNAMIC(CCallBreakSocreDialog, CDialog) 
CCallBreakSocreDialog::CCallBreakSocreDialog(CWnd* pParent /*=NULL*/) 
	: CDialog(CCallBreakSocreDialog::IDD, pParent) 
{ 
} 
 
CCallBreakSocreDialog::CCallBreakSocreDialog(CTypedPtrList *pList, int GameCounter, CWnd* pParent /*=NULL*/) 
	: CDialog(CCallBreakSocreDialog::IDD, pParent) 
{ 
	m_pPlayerList = pList; 
	m_Font.CreateFont(0, 0, 0, 0, 0, FALSE, FALSE, 0, 1, OUT_DEFAULT_PRECIS, 
		CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_SCRIPT, _T("Monotype Corsiva")); 
 
	m_GameCounter = GameCounter; 
} 
 
 
CCallBreakSocreDialog::~CCallBreakSocreDialog() 
{ 
	DeleteObject(m_Font); 
} 
 
void CCallBreakSocreDialog::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
} 
 
 
BEGIN_MESSAGE_MAP(CCallBreakSocreDialog, CDialog) 
	ON_WM_DESTROY() 
	ON_WM_PAINT() 
END_MESSAGE_MAP() 
 
 
// CCallBreakSocreDialog message handlers 
 
BOOL CCallBreakSocreDialog::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// TODO:  Add extra initialization here 
 
	CSize SizeRect; 
	CSize PrevSize(0,0); 
	CSize WindowSize; 
	CString str; 
	CString temp; 
	BOOL varBool; 
	 
	CDC *pDC = GetDC(); 
	CFont *oldFont = pDC->SelectObject(&m_Font); 
 
	POSITION pos = m_pPlayerList->GetHeadPosition(); 
			 
	while (pos != NULL) 
	{ 
		CCallBreakPlayer *pPlayer = m_pPlayerList->GetNext(pos); 
		str = pPlayer->m_strPlayerName;		 
		str += _T(":"); 
		m_strList.AddHead(str); 
		SizeRect = pDC->GetTextExtent(str); 
		CRect Rect(100+PrevSize.cx, 10, 100 + PrevSize.cx + SizeRect.cx, 10+SizeRect.cy); 
		m_rectList.AddHead(Rect); 
		varBool = FALSE; 
		m_boolList.AddHead(varBool); 
		PrevSize.cx = PrevSize.cx+SizeRect.cx+20; 
		double Total = 0; 
 
		for(int i = 0; i <= m_GameCounter; ++i) 
		{ 
            double db; 
			int diff = pPlayer->m_nHandsWon[i] - pPlayer->m_nStake[i];  
			if( diff >= 0) 
			{ 
				double temp1 = (double)pPlayer->m_nStake[i]; 
				double temp2 = (double)diff/10.0; 
				db = temp1 + temp2; 
				varBool = FALSE; 
				m_boolList.AddHead(varBool); 
				Total += db; 
			} 
			else 
			{ 
				db = (double)pPlayer->m_nStake[i]; 
				varBool = TRUE; 
				m_boolList.AddHead(varBool); 
				Total -= db; 
			} 
			 
		 
			CString temp2; 
			temp.Format("%.1f", db); 
			str = temp; 
			if(varBool) 
			{ 
				temp2.Format("%d", pPlayer->m_nHandsWon[i]); 
				str += _T("(") + temp2 + _T(")"); 
			} 
			m_strList.AddHead(str); 
			SizeRect = pDC->GetTextExtent(str); 
			Rect.top = Rect.bottom + 5; 
			Rect.bottom = Rect.top + SizeRect.cy; 
			m_rectList.AddHead(Rect); 
			if( i == 3 || i == 4) 
			{ 
				CString temp; 
				temp.Format("%.1f", Total); 
				SizeRect = pDC->GetTextExtent(temp); 
				Rect.top = Rect.bottom + 5; 
				Rect.bottom = Rect.top + SizeRect.cy; 
				TotalStruct ts; 
				ts.s_strTotal = temp; 
				ts.s_TotalRect = Rect; 
				m_TotalStructList.AddHead(ts); 
			} 
 
			WindowSize = Rect.BottomRight(); 
		} 
	} 
 
	MoveWindow(0, 0, WindowSize.cx+10, WindowSize.cy+100); 
	CWnd *pWnd = GetDlgItem(IDOK); 
	CRect RectCltIDOK; 
	pWnd->GetClientRect(&RectCltIDOK); 
	CRect RectClient; 
	GetClientRect(&RectClient); 
	CRect RectIDOK; 
	RectIDOK.left = RectClient.Width()/2 - RectCltIDOK.Width()/2; 
	RectIDOK.top = RectClient.Height() - 25 - RectCltIDOK.Height(); 
	RectIDOK.right = RectIDOK.left + RectCltIDOK.Width(); 
	RectIDOK.bottom = RectIDOK.top + RectCltIDOK.Height(); 
	pWnd->MoveWindow(&RectIDOK); 
 
	pDC->SelectObject(oldFont); 
	ReleaseDC(pDC); 
 
	CenterWindow(); 
	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	// EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CCallBreakSocreDialog::OnDestroy() 
{ 
	CDialog::OnDestroy(); 
 
	// TODO: Add your message handler code here 
	m_strList.RemoveAll(); 
	m_rectList.RemoveAll(); 
	m_boolList.RemoveAll(); 
	m_TotalStructList.RemoveAll(); 
} 
 
void CCallBreakSocreDialog::OnPaint() 
{ 
	CPaintDC dc(this); // device context for painting 
	// TODO: Add your message handler code here 
	// Do not call CDialog::OnPaint() for painting messages 
 
    CFont *oldFont = dc.SelectObject(&m_Font); 
	dc.SetBkMode(TRANSPARENT); 
 
	POSITION posstr = m_strList.GetHeadPosition(); 
	POSITION posrect = m_rectList.GetHeadPosition(); 
	POSITION posbool = m_boolList.GetHeadPosition(); 
	while(posstr != NULL || posrect != NULL || posbool != NULL) 
	{ 
		CString str = m_strList.GetNext(posstr); 
		CRect Rect = m_rectList.GetNext(posrect); 
		BOOL ibool = m_boolList.GetNext(posbool); 
 
		if(ibool) 
			dc.SetTextColor(RGB(255, 0, 0)); 
		else 
			dc.SetTextColor(RGB(0,0,0)); 
 
		dc.DrawText(str, Rect, DT_CENTER); 
	} 
 
	POSITION posTS = m_TotalStructList.GetHeadPosition(); 
	while(posTS != NULL) 
	{ 
		TotalStruct ts = m_TotalStructList.GetNext(posTS); 
		COLORREF colref = dc.SetTextColor(RGB(0, 0, 255)); 
		dc.DrawText(ts.s_strTotal, &ts.s_TotalRect, DT_CENTER); 
		dc.SetTextColor(colref); 
	} 
 
	CRect Rect(10, 30, 0, 30); 
 
	for(int i = 0; i <= m_GameCounter; ++i) 
	{ 
        CString temp, temp2; 
		temp.Format("%d", i+1); 
		CSize SizeRect; 
		temp2 = _T("Game "); 
		temp2 += temp; 
		temp2 += _T(":"); 
		SizeRect = dc.GetTextExtent(temp2); 
		Rect.top = Rect.bottom + 5; 
		Rect.bottom = Rect.top + SizeRect.cy; 
		Rect.right = Rect.left + SizeRect.cx; 
		dc.DrawText(temp2, Rect, DT_CENTER);		 
		if(i == 3) 
		{ 
			CString str(_T("Sub Total")); 
			SizeRect = dc.GetTextExtent(str); 
			dc.MoveTo(Rect.left, Rect.bottom + 2); 
			CRect rect; 
			GetClientRect(&rect); 
			dc.LineTo(rect.right, Rect.bottom + 2);  
			Rect.top = Rect.bottom + 5; 
			Rect.bottom = Rect.top + SizeRect.cy; 
			Rect.right = Rect.left + SizeRect.cx; 
			COLORREF colref = dc.SetTextColor(RGB(0, 0, 255)); 
			dc.DrawText(str, Rect, DT_CENTER); 
			dc.SetTextColor(colref); 
		} 
		else if( i == 4) 
		{ 
			CString str(_T("Grand Total")); 
			SizeRect = dc.GetTextExtent(str); 
			dc.MoveTo(Rect.left, Rect.bottom + 2); 
			CRect rect; 
			GetClientRect(&rect); 
			dc.LineTo(rect.right, Rect.bottom + 2);  
			Rect.top = Rect.bottom + 5; 
			Rect.bottom = Rect.top + SizeRect.cy; 
			Rect.right = Rect.left + SizeRect.cx; 
			COLORREF colref = dc.SetTextColor(RGB(0, 0, 255)); 
			dc.DrawText(str, Rect, DT_CENTER); 
			dc.SetTextColor(colref); 
		} 
	} 
	 
	dc.SelectObject(oldFont); 
}