www.pudn.com > LotterySrc > DlgRelation.cpp, change:2000-12-14,size:4824b


// DlgRelation.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Lottery.h" 
#include "DlgRelation.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CDlgRelation dialog 
 
 
CDlgRelation::CDlgRelation(CWnd* pParent /*=NULL*/) 
	: CDialog(CDlgRelation::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CDlgRelation) 
	//}}AFX_DATA_INIT 
	m_isFilled=FALSE; 
	m_nFactor=1; 
	m_dMax=m_dAve=m_dStd=0; 
	m_dMin=INT_MAX; 
} 
 
 
void CDlgRelation::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CDlgRelation) 
	DDX_Control(pDX, IDC_LIST1, m_list); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CDlgRelation, CDialog) 
	//{{AFX_MSG_MAP(CDlgRelation) 
	ON_WM_SIZE() 
	ON_WM_PAINT() 
	ON_WM_DESTROY() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDlgRelation message handlers 
 
void CDlgRelation::OnSize(UINT nType, int cx, int cy)  
{ 
	CDialog::OnSize(nType, cx, cy); 
	 
	if (m_list.m_hWnd) 
	{ 
		m_list.MoveWindow(0,0,cx,cy/2); 
	} 
	m_nWidth=cx; 
	m_nHeight=cy; 
} 
 
BOOL CDlgRelation::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	m_pBuf=NULL; 
 
	DWORD style=m_list.GetExtendedStyle(); 
	style |=(LVS_EX_FLATSB|LVS_EX_GRIDLINES|LVS_EX_ONECLICKACTIVATE|LVS_EX_FULLROWSELECT); 
	m_list.SetExtendedStyle(style); 
	m_list.SetBkColor(RGB(64,64,64)); 
	m_list.SetTextBkColor(RGB(64,64,64)); 
	m_list.SetTextColor(RGB(255,255,0)); 
 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CDlgRelation::OnPaint()  
{ 
	int nBase=50; 
	CPaintDC dc(this); // device context for painting 
	CBrush bkBrush(RGB(64,64,64)); 
	dc.FillRect(CRect(0,m_nHeight/2+2,m_nWidth,m_nHeight),&bkBrush); 
	bkBrush.DeleteObject(); 
	CPen penCord(PS_SOLID,1,RGB(255,255,0)),penLine(PS_SOLID,1,RGB(0,255,0)),*pOldPen; 
	pOldPen=dc.SelectObject(&penCord); 
	dc.MoveTo(1,m_nHeight-nBase); 
	dc.LineTo(m_nWidth,m_nHeight-nBase); 
	 
	if (!m_isFilled) 
	{ 
		GetRelationData(); 
		m_isFilled=TRUE; 
	} 
 
	CString strText; 
	dc.SetTextColor(RGB(255,255,255)); 
	dc.SetBkColor(RGB(64,64,64)); 
	pOldPen=dc.SelectObject(&penCord); 
	for (int i=0; i<50; i+=1) 
	{ 
		strText.Format("%d",i); 
		CRect rect=CRect(i*28*m_nFactor-10,m_nHeight-nBase+7,i*28*m_nFactor+10,m_nHeight-nBase+27); 
		dc.DrawText(strText,&rect,DT_CENTER); 
		dc.MoveTo(i*28*m_nFactor,m_nHeight-nBase); 
		dc.LineTo(i*28*m_nFactor,m_nHeight-nBase+9); 
	} 
	CRect rect3(m_nWidth-80,m_nHeight/2+5,m_nWidth-10,m_nHeight/2+80); 
	CString str; 
	str.Format("Max=%5.3f\r\nMin=%5.3f\r\nAve=%5.3f\r\nStd=%5.3f",m_dMax,m_dMin,m_dAve,m_dStd); 
	dc.DrawText(str,&rect3,DT_RIGHT|DT_NOCLIP); 
	dc.SelectObject(&penLine); 
	for (i=0; i<m_nSize; i++) 
	{ 
		UINT temp=m_pBuf[i]; 
		int nOrder=1; 
		for (int j=i+1; j<m_nSize; j++) 
		{ 
			if (temp != m_pBuf[j]) break; 
			nOrder++; 
		} 
		dc.MoveTo(m_pBuf[i]*m_nFactor,m_nHeight-nBase-1); 
		dc.LineTo(m_pBuf[i]*m_nFactor,m_nHeight-nBase-20*nOrder-1); 
		i+=nOrder-1; 
	} 
	dc.SelectObject(pOldPen); 
	penCord.DeleteObject(); 
	penLine.DeleteObject(); 
} 
 
void CDlgRelation::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
	 
	if (m_pBuf) delete[] m_pBuf; 
	 
} 
 
BOOL CDlgRelation::PreTranslateMessage(MSG* pMsg)  
{ 
	if (pMsg->message==WM_KEYDOWN) 
	{ 
		int nChar=pMsg->wParam; 
		BOOL bShouldRedraw=FALSE; 
		switch (nChar) 
		{ 
			case VK_SUBTRACT: 
				if (m_nFactor > 1) 
				{ 
					m_nFactor--; 
					bShouldRedraw=TRUE; 
				} 
				break; 
			case VK_ADD: 
				if (m_nFactor < 10) 
				{ 
					m_nFactor++; 
					bShouldRedraw=TRUE; 
				} 
				break; 
		} 
		if (bShouldRedraw) 
		{ 
			CRect rect(0,m_nHeight/2,m_nWidth,m_nHeight); 
			InvalidateRect(&rect); 
		} 
	} 
	return CDialog::PreTranslateMessage(pMsg); 
} 
 
void CDlgRelation::GetRelationData() 
{ 
	int count=m_pArray->GetSize(); 
	m_nSize=count; 
	if (!m_pBuf) m_pBuf=new UINT[count]; 
	LOTTERY lty; 
	for (int i=0; i<count; i++) 
	{ 
		lty=m_pArray->GetAt(i); 
		m_pBuf[i]=lty.RelationAnalysis(); 
	} 
	for (i=0; i<count; i++) 
	{ 
		for (int j=i+1; j<count; j++) 
		{ 
			if (m_pBuf[i] < m_pBuf[j]) 
			{ 
				UINT temp=m_pBuf[i]; 
				m_pBuf[i]=m_pBuf[j]; 
				m_pBuf[j]=temp; 
			} 
		} 
	} 
	if (m_dMin==INT_MAX) 
	{ 
		double dSum=0; 
		for (int i=0; i<m_nSize; i++) 
		{ 
			dSum+=m_pBuf[i]; 
			if (m_pBuf[i] > m_dMax) m_dMax=m_pBuf[i]; 
			if (m_pBuf[i] < m_dMin) m_dMin=m_pBuf[i]; 
		} 
		m_dAve=dSum/m_nSize; 
		m_dAve/=28.0; 
		m_dMax/=28.0; 
		m_dMin/=28.0; 
		double dStd=0; 
		for (i=0; i<m_nSize; i++) 
		{ 
			dStd+=(m_pBuf[i]/28.0 - m_dAve)*(m_pBuf[i]/28.0 - m_dAve); 
		} 
		m_dStd=sqrt(dStd); 
	} 
}