www.pudn.com > LotterySrc > DlgFrequency.cpp, change:2000-12-20,size:4073b


// DlgFrequency.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Lottery.h" 
#include "DlgFrequency.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CDlgFrequency dialog 
 
 
CDlgFrequency::CDlgFrequency(CWnd* pParent /*=NULL*/) 
	: CDialog(CDlgFrequency::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CDlgFrequency) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	m_isFilled=FALSE; 
	m_pBuf=NULL; 
	m_pBuf2=NULL; 
	m_dMax=m_dAve=m_dStd=0; 
	m_dMin=INT_MAX; 
} 
 
 
void CDlgFrequency::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CDlgFrequency) 
	DDX_Control(pDX, IDC_LIST2, m_list2); 
	DDX_Control(pDX, IDC_LIST1, m_list); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CDlgFrequency, CDialog) 
	//{{AFX_MSG_MAP(CDlgFrequency) 
	ON_WM_PAINT() 
	ON_WM_DESTROY() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDlgFrequency message handlers 
 
BOOL CDlgFrequency::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	DWORD style=m_list.GetExtendedStyle(); 
	style |=(LVS_EX_FLATSB|LVS_EX_GRIDLINES|LVS_EX_ONECLICKACTIVATE|LVS_EX_FULLROWSELECT); 
	m_list.SetExtendedStyle(style); 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CDlgFrequency::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	int count=m_list2.GetCount(); 
	CRect rect; 
	GetDlgItem(IDC_STATIC1)->GetClientRect(&rect); 
	GetDlgItem(IDC_STATIC1)->ClientToScreen(&rect); 
	ScreenToClient(&rect); 
	CBrush bkBrush(RGB(64,64,64)); 
	dc.FillRect(&rect,&bkBrush); 
	CPen penCord(PS_SOLID,1,RGB(255,255,0)),penLine(PS_SOLID,1,RGB(0,255,0)),*pOldPen; 
	pOldPen=(CPen *)dc.SelectObject(&penCord); 
	dc.MoveTo(rect.left+50, rect.top+20); 
	dc.LineTo(rect.left+50, rect.bottom-10); 
	if (!m_pBuf)  
	{ 
		m_pBuf=new double[count]; 
		for (int i=0; i<count; i++) 
		{ 
			CString str; 
			m_list2.GetText(i,str); 
			int j=0; 
			while (str.GetAt(j++) != ' '); 
			CString str2=str.Mid(j); 
			double fs=atof((char*)(const char*)str2); 
			m_pBuf[i]=fs; 
		} 
		m_pBuf2=new UINT[count]; 
		double dSum=0; 
		for (i=0; i<count; i++) 
		{ 
			double temp=(m_pBuf[i] * 100.0 - 150.0) * 3.0; 
			m_pBuf2[i]=(UINT)(temp); 
 
			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/count; 
		double dStd=0; 
		for (i=0; i<count; i++) 
		{ 
			dStd+=(m_pBuf[i] - m_dAve)*(m_pBuf[i] - m_dAve); 
		} 
		m_dStd=sqrt(dStd); 
		for (i=0; i<count; i++) 
		{ 
			for (int j=i+1; j<count; j++) 
			{ 
				if (m_pBuf2[i] < m_pBuf2[j]) 
				{ 
					UINT temp=m_pBuf2[j]; 
					m_pBuf2[j]=m_pBuf2[i]; 
					m_pBuf2[i]=temp; 
				} 
			} 
		} 
	} 
	dc.SetBkColor(RGB(64,64,64)); 
	dc.SetTextColor(RGB(255,255,0)); 
	for (double x=1.600; x<2.500; x+=0.10) 
	{ 
		CString str; 
		str.Format("%5.2f",x); 
		double t1=3.0*(x*100-150); 
		CRect rect2(rect.left,(int)(t1-10),rect.left+50,(int)(t1+10)); 
		dc.DrawText(str,&rect2,DT_VCENTER|DT_CENTER); 
		dc.MoveTo(rect.left+45,(int)t1); 
		dc.LineTo(rect.left+50,(int)t1); 
	} 
	CRect rect3(rect.right-80,rect.bottom-80,rect.right-5,rect.bottom); 
	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); 
	dc.SelectObject(&penLine); 
	for (int i=0; i<count; i++) 
	{ 
		UINT temp=m_pBuf2[i]; 
		int j=1; 
		while (temp==m_pBuf2[i+j]) j++; 
		dc.MoveTo(rect.left+51, temp); 
		dc.LineTo(rect.left+51 + j * 10, temp); 
		i+=j; 
	} 
	dc.SelectObject(pOldPen); 
	penCord.DeleteObject(); 
	bkBrush.DeleteObject(); 
} 
 
void CDlgFrequency::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
	 
	if (m_pBuf) delete [] m_pBuf;	 
	if (m_pBuf2) delete [] m_pBuf2;	 
} 
void CDlgFrequency::ForceInvalidate() 
{ 
	OnPaint(); 
}