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

📄 dlglottery.cpp

📁 一个完整的彩票软件的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DlgLottery.cpp : implementation file
//

#include "stdafx.h"
#include "Lottery.h"
#include "DlgLottery.h"
#include "childview.h"
#include "Collection.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CListCtrl * g_pList;
extern CChildView *pCV;
/////////////////////////////////////////////////////////////////////////////
// CDlgLottery dialog

CDlgLottery::CDlgLottery(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgLottery::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgLottery)
	m_szProbility = _T("");
	m_uSum1 = 0;
	m_uSum2 = 0;
	m_uAc1 = 0;
	m_uAc2 = 0;
	m_fDiff = 0.0f;
	m_fRelation = 0.0f;
	m_dFS2 = 0.0;
	m_dFilterFactor = 0.0;
	m_dFS1 = 0.0;
	//}}AFX_DATA_INIT
}


void CDlgLottery::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgLottery)
	DDX_Control(pDX, IDC_PROGRESS_COLOR2, m_progress2);
	DDX_Control(pDX, IDC_LIST_PERMUTATION2, m_list_permu2);
	DDX_Control(pDX, IDC_LIST_PERMUTATION, m_list_permu);
	DDX_Control(pDX, IDC_EDIT_NUM6, m_edit6);
	DDX_Control(pDX, IDC_EDIT_NUM5, m_edit5);
	DDX_Control(pDX, IDC_EDIT_NUM4, m_edit4);
	DDX_Control(pDX, IDC_EDIT_NUM3, m_edit3);
	DDX_Control(pDX, IDC_EDIT_NUM2, m_edit2);
	DDX_Control(pDX, IDC_EDIT_NUM1, m_edit1);
	DDX_Control(pDX, IDC_EDIT_NUM0, m_edit0);
	DDX_Control(pDX, IDC_PROGRESS_COLOR, m_progress);
	DDX_Control(pDX, IDC_SPIN_FILTER, m_spinFilter);
	DDX_Control(pDX, IDC_STATIC0, m_graph0);
	DDX_Control(pDX, IDC_STATIC4, m_graph4);
	DDX_Control(pDX, IDC_STATIC3, m_graph3);
	DDX_Control(pDX, IDC_STATIC2, m_graph2);
	DDX_Control(pDX, IDC_STATIC1, m_graph1);
	DDX_Control(pDX, IDC_LIST_LOTTERY_NUMBER, m_lott_list);
	DDX_Control(pDX, IDC_LIST_HIT_PROPORTION, m_hit_list);
	DDX_Control(pDX, IDC_COMBO_LOTTERY_NUMBER, m_combo);
	DDX_Text(pDX, IDC_EDIT_PROBILITY_CACULATE, m_szProbility);
	DDX_Text(pDX, IDC_EDIT_SUM1, m_uSum1);
	DDV_MinMaxUInt(pDX, m_uSum1, 28, 170);
	DDX_Text(pDX, IDC_EDIT_SUM2, m_uSum2);
	DDV_MinMaxUInt(pDX, m_uSum2, 50, 189);
	DDX_Text(pDX, IDC_EDIT_AC1, m_uAc1);
	DDV_MinMaxUInt(pDX, m_uAc1, 0, 14);
	DDX_Text(pDX, IDC_EDIT_AC2, m_uAc2);
	DDV_MinMaxUInt(pDX, m_uAc2, 6, 15);
	DDX_Text(pDX, IDC_EDIT_DIFF, m_fDiff);
	DDV_MinMaxFloat(pDX, m_fDiff, 0.2f, 1.f);
	DDX_Text(pDX, IDC_EDIT_RELATION, m_fRelation);
	DDX_Text(pDX, IDC_EDIT_FS2, m_dFS2);
	DDV_MinMaxDouble(pDX, m_dFS2, 0.1, 0.3);
	DDX_Text(pDX, IDC_EDIT_FILTER_FACTOR, m_dFilterFactor);
	DDV_MinMaxDouble(pDX, m_dFilterFactor, 1., 6.);
	DDX_Text(pDX, IDC_EDIT_FS1, m_dFS1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgLottery, CDialog)
	//{{AFX_MSG_MAP(CDlgLottery)
	ON_BN_CLICKED(IDC_BUTTON_GENERATE, OnButtonGenerate)
	ON_BN_CLICKED(IDC_BUTTON_RECON, OnButtonRecon)
	ON_LBN_SELCHANGE(IDC_LIST_LOTTERY_NUMBER, OnSelchangeListLotteryNumber)
	ON_BN_CLICKED(IDC_CHECK1, OnRelationCheck1)
	ON_BN_CLICKED(IDC_CHECK2, OnACCheck2)
	ON_BN_CLICKED(IDC_CHECK3, OnSumCheck3)
	ON_MESSAGE(WM_NOTIFY_GRAPH_ACTION, OnNotifyGraphAction)
	ON_BN_CLICKED(IDC_CHECK7, OnCheck7Of_FS)
	ON_BN_CLICKED(IDC_CHECK8, OnCheck8Of_FilterFactor)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_FILTER, OnDeltaposSpinFilter)
	ON_WM_TIMER()
	ON_CONTROL_RANGE(BN_CLICKED,IDC_RADIO1,IDC_RADIO5,OnNotifyOfRadio)
	ON_BN_CLICKED(IDC_BUTTON_PERMUTATION, OnButtonPermutation)
	ON_BN_CLICKED(IDC_BUTTON_GENERATE2, OnButtonGenerate2)
	ON_LBN_SELCHANGE(IDC_LIST_PERMUTATION2, OnSelchangeListPermutation2)
	ON_BN_CLICKED(IDC_BUTTON_COPY, OnButtonCopy)
	ON_BN_CLICKED(IDC_BUTTON_FUSHI, OnButtonFushi)
	ON_BN_CLICKED(IDC_BUTTON_FUSHI2, OnButtonFushi2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgLottery message handlers

BOOL CDlgLottery::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_szProbility=ProbilityCaculate();
	UpdateData(FALSE);
	// TODO: Add extra initialization here
	m_combo.SetCurSel(4);
	m_combo.SetFocus();
	SetDlgItemInt(IDC_EDIT_AC1,8);
	SetDlgItemInt(IDC_EDIT_AC2,12);
	SetDlgItemInt(IDC_EDIT_SUM1,80);
	SetDlgItemInt(IDC_EDIT_SUM2,135);
	CString str;
	str.Format("%3.2f",0.78);
	SetDlgItemText(IDC_EDIT_DIFF,str);
	str.Format("%3.2f",0.22);
	SetDlgItemText(IDC_EDIT_FS2,str);
	str.Format("%3.2f",2.0);
	SetDlgItemText(IDC_EDIT_FILTER_FACTOR,str);
	((CButton*)(GetDlgItem(IDC_CHECK1)))->SetCheck(1);
	((CButton*)(GetDlgItem(IDC_CHECK2)))->SetCheck(1);
	((CButton*)(GetDlgItem(IDC_CHECK3)))->SetCheck(1);
	((CButton*)(GetDlgItem(IDC_CHECK4)))->SetCheck(1);
	((CButton*)(GetDlgItem(IDC_CHECK5)))->SetCheck(1);
	((CButton*)(GetDlgItem(IDC_CHECK7)))->SetCheck(1);
	((CButton*)(GetDlgItem(IDC_CHECK8)))->SetCheck(1);
	m_spinFilter.SetBase(10);
	m_spinFilter.SetRange(1,12);
	m_spinFilter.SetPos(4);

	m_progress.SetRange(0,50);
	m_progress.SetPos(0);
	m_progress2.SetRange(0,30);
	m_progress2.SetPos(0);

	m_edit0.m_nEdit_ID=IDC_EDIT_DIFF0;
	m_edit1.m_nEdit_ID=IDC_EDIT_DIFF1;
	m_edit2.m_nEdit_ID=IDC_EDIT_DIFF2;
	m_edit3.m_nEdit_ID=IDC_EDIT_DIFF3;
	m_edit4.m_nEdit_ID=IDC_EDIT_DIFF4;
	m_edit5.m_nEdit_ID=IDC_EDIT_DIFF5;
	m_edit6.m_nEdit_ID=IDC_EDIT_DIFF6;
	//-----------initialize graph1 2 3 4 5 6 7-----------//
	m_graph0.FillArray(&(pCV->m_array),3);
	m_graph1.FillArray(&(pCV->m_array),4);
	m_graph2.FillArray(&(pCV->m_array),5);
	m_graph3.FillArray(&(pCV->m_array),6);
	m_graph4.FillArray(&(pCV->m_array),7);
	return FALSE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
//-----------产生号码-----------//
void CDlgLottery::OnButtonGenerate() 
{
	m_combo.SetFocus();
	CString strText;
	GetDlgItemText(IDC_BUTTON_GENERATE,strText);
	if (strText=="产生号码")
	{
		m_bStop = FALSE;
		SetDlgItemText(IDC_BUTTON_GENERATE,"停止搜索");
		SetTimer(0,100,NULL);
		if (!UpdateData(TRUE)) return ;
		if (GetDlgItemInt(IDC_EDIT_AC1) > GetDlgItemInt(IDC_EDIT_AC2))
		{
			MessageBox("AC 条件非法");
			return;
		}
		if (GetDlgItemInt(IDC_EDIT_SUM1) > GetDlgItemInt(IDC_EDIT_SUM2))
		{
			MessageBox("号码总和条件非法");
			return;
		}
		srand(GetTickCount());
		int nNum=GetDlgItemInt(IDC_COMBO_LOTTERY_NUMBER);
		if (nNum < 1) return;
		m_lott_list.ResetContent();
		m_lott_list.AddString("----------------------");
		LOTTERY lty;
		CString str;
		int nTotal=0;
		m_time1=CTime::GetCurrentTime();
		m_boolContinue=TRUE;
		for (int i=0; i<nNum; i++)
		{
			nTotal+=GenerateOneLottery(&lty);
			if (lty.i[1]==0) 
			{
				break;
			}
			str.Format("%2d,%2d,%2d,%2d,%2d,%2d,%2d",lty.i[1],lty.i[2],lty.i[3],lty.i[4],lty.i[5],lty.i[6],lty.i[7]);
			m_lott_list.AddString(str);
		}
		str.Format("------搜索%04d注------",nTotal);
		m_lott_list.AddString(str);
		KillTimer(0);
		SetDlgItemText(IDC_BUTTON_GENERATE,"产生号码");
	}
	else
	{
		m_bStop=TRUE;
	}
}
void CDlgLottery::DoEvents()
{
    MSG msg;
    if (::PeekMessage(&msg,NULL,0,0,PM_REMOVE)) 
    {
        if (msg.message== WM_QUIT)
        { 
            ::PostQuitMessage(-1);
        }
        if (!AfxGetApp()->PreTranslateMessage(&msg))
        {
            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);    
        }
    }
    AfxGetApp()->OnIdle(0);    // Update the applications user interface
    AfxGetApp()->OnIdle(1);    // Perform normal idle operations (free resources etc)
}

//-----------产生符合要求的一注号码-----------//
int CDlgLottery::GenerateOneLottery(LOTTERY *plot)
{
	m_pArray=&(pCV->m_array);
	int nCount=m_pArray->GetSize();
	int nTotal=8*nCount-1;
	int nNum=0;
	do {
		if (m_bStop)
		{
			ZeroMemory(plot,sizeof(LOTTERY));
			return nNum;
		}
		DoEvents();
		nNum++;
		for (int i=1; i<8; i++)
		{
			UINT d1;
			Regenerate:
			int d=rand();
			d1=(int)((float)d/RAND_MAX * (float)nTotal);
			LOTTERY lty=m_pArray->GetAt(d1/8);
			d1=lty.i[d1%8+1];
			for (int j=1; j<i; j++)
			{
				if (plot->i[j]==d1) goto Regenerate;
			}
			plot->i[i]=d1;
		}
		if (m_boolContinue)
		{
			CTime time2=CTime::GetCurrentTime();
			CTimeSpan timeSpan=time2 - m_time1;
			if (timeSpan.GetTotalSeconds() > 10)
			{
				if (IDCANCEL==MessageBox("您所选定的条件过于苛刻或者不合理.\r\n要继续吗?","长时间操作",MB_OKCANCEL|MB_ICONEXCLAMATION|MB_DEFBUTTON2))
				{
					ZeroMemory(plot,sizeof(LOTTERY));
					return nNum;
				}
				m_boolContinue=FALSE;
			}
		}
	}while ( !VerifyLotteryKillerFilter(plot) || !VerifyLotteryNumber(plot));
	//sort the generated lottery number
	for (int i=1; i<8; i++)
		for (int j=i+1; j<8; j++)
		{
			if (plot->i[i]>plot->i[j])
			{
				int temp=plot->i[i];
				plot->i[i]=plot->i[j];
				plot->i[j]=temp;
			}
		}
	return nNum;
}
//-----------人工选号的预测处理-----------//
void CDlgLottery::OnButtonRecon() 
{
	m_combo.SetFocus();
	CString strBuf,strNum;
	GetDlgItemText(IDC_EDIT_MANUAL_SELECT,strBuf);
	UINT lty[7];
	int k=0;
	int len=strBuf.GetLength();
	int i=0;
	refill:
		while(i<len && (strBuf.GetAt(i) < 48 || strBuf.GetAt(i) > 57)) i++;

		int j=i;
		while(i<len && strBuf.GetAt(i) > 47 && strBuf.GetAt(i) < 58) i++;
		strNum=strBuf.Mid(j,i-j);
		lty[k]=atoi(strNum.GetBuffer(strNum.GetLength()));
		if (lty[k]>30) 
		{
			MessageBox("please input a number between 1-30");
			return;
		}
		k++;
		if (k==7)
		{
			LOTTERY ll={0,lty[0],lty[1],lty[2],lty[3],lty[4],lty[5],lty[6],0};
			GetAllKindOfValueAndFillTheListBox(&ll);
			return;
		}
		if (i>=len)return;
		if (k<7) goto refill;
	return;
}
//-----------概率计算-----------//
CString CDlgLottery::ProbilityCaculate()
{
	double base1=1.0/(30.0*29*28*27*26*25*24/7/6/5/4/3/2);//C(30,7)
	CString strPro1;
	strPro1.Format("单注中一等奖的概率: %.18f%%\r\n",base1*100);
	double base2=base1*7;
	CString strPro2;
	strPro2.Format("单注中二等奖的概率: %.18f%%\r\n",base2*100);
	double base3=base1*7*22;
	CString strPro3;
	strPro3.Format("单注中三等奖的概率: %.18f%%\r\n",base3*100);
	double base4=base1*7*3*22;
	CString strPro4;
	strPro4.Format("单注中四等奖的概率: %.18f%%\r\n",base4*100);
	double base5=base1*7*3*21*11;
	CString strPro5;
	strPro5.Format("单注中五等奖的概率: %.18f%%\r\n",base5*100);
	double base6=base1*7*5*21*11;
	CString strPro6;
	strPro6.Format("单注中六等奖的概率: %.18f%%\r\n",base6*100);
	double base7=base1*7*5*23*11*7;
	CString strPro7;
	strPro7.Format("单注中七等奖的概率: %.18f%%\r\n",base7*100);

	return (strPro1+strPro2+strPro3+strPro4+strPro5+strPro6+strPro7);
}

//-----------号码列表选择改变处理-----------//
void CDlgLottery::OnSelchangeListLotteryNumber() 
{
	int sel=m_lott_list.GetCurSel();	
	if (sel >= 0)
	{
		CString strText;
		m_lott_list.GetText(sel,strText);
		if (strText.GetAt(0) != '-')
		{
			LOTTERY lot;
			lot.GetLotteryFromStr(strText);
			GetAllKindOfValueAndFillTheListBox(&lot);
		}
	}
}
//-----------计算号码的相关系数-----------//
UINT LOTTERY::RelationAnalysis()
{
	char buf[4];
	LVITEM lv;
	lv.mask=LVIF_TEXT;
	lv.cchTextMax=4;
	lv.pszText=buf;
	int total=0;
	for (int i=1; i<8; i++)
	{
		lv.iItem=this->i[i]-1;
		for (int j=i+1; j<8; j++)
		{
			lv.iSubItem=this->i[j];
			g_pList->GetItem(&lv);
			total+=atoi(lv.pszText);
		}
	}
	return total;
}

void CDlgLottery::OnRelationCheck1() 
{
	GetDlgItem(IDC_EDIT_RELATION)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK1)))->GetCheck());
	GetDlgItem(IDC_EDIT_DIFF)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK1)))->GetCheck());
}

void CDlgLottery::OnACCheck2() 
{
	GetDlgItem(IDC_EDIT_AC1)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK2)))->GetCheck());
	GetDlgItem(IDC_EDIT_AC2)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK2)))->GetCheck());
}

void CDlgLottery::OnSumCheck3() 
{
	GetDlgItem(IDC_EDIT_SUM1)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK3)))->GetCheck());
	GetDlgItem(IDC_EDIT_SUM2)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK3)))->GetCheck());
}

void CDlgLottery::OnCheck7Of_FS() 
{
	GetDlgItem(IDC_EDIT_FS1)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK7)))->GetCheck());
	GetDlgItem(IDC_EDIT_FS2)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK7)))->GetCheck());
}

void CDlgLottery::OnCheck8Of_FilterFactor() 
{
	GetDlgItem(IDC_EDIT_FILTER_FACTOR)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK8)))->GetCheck());
	GetDlgItem(IDC_SPIN_FILTER)->EnableWindow(((CButton*)(GetDlgItem(IDC_CHECK8)))->GetCheck());
}

BOOL CDlgLottery::ForceVerifyLotteryNumber(LOTTERY *plot)
{
	{//Verify Relation 
		UINT rel=plot->RelationAnalysis();
		if (((m_fRelation+m_fDiff) < rel/28) || ((m_fRelation-m_fDiff) > rel/28))
			return FALSE;
	}
	{//Verify AC
		unsigned int ac=plot->GetAC();
		if (ac < m_uAc1 || ac > m_uAc2)
			return FALSE;
	}
	{//Verify FS
		double fsSum=plot->GetFS();
		if (((m_dFS1+m_dFS2) < fsSum) || ((m_dFS1-m_dFS2) > fsSum))
			return FALSE;
	}
	{//Verify Sum
		unsigned int sum=plot->GetSum();
		if (sum < m_uSum1 || sum > m_uSum2)
			return FALSE;
	}
	int even=plot->GetEvenNumber(FALSE);
	if (((even==0) || (even==7)))
	{//Verify 0 even,7 odd
			return FALSE;
	}
	if (((even==1) || (even==6)))
	{//Verify 1 even,6 odd
			return FALSE;
	}
	return TRUE;
}

//-----------判断产生的号码是否符合要求-----------//
BOOL CDlgLottery::VerifyLotteryNumber(LOTTERY *plot)
{
	if (((CButton*)(GetDlgItem(IDC_CHECK1)))->GetCheck())
	{//Verify Relation 
		UINT rel=plot->RelationAnalysis();
		if (((m_fRelation+m_fDiff) < rel/28) || ((m_fRelation-m_fDiff) > rel/28))
			return FALSE;
	}
	if (((CButton*)(GetDlgItem(IDC_CHECK2)))->GetCheck())
	{//Verify AC
		unsigned int ac=plot->GetAC();
		if (ac < m_uAc1 || ac > m_uAc2)
			return FALSE;
	}
	if (((CButton*)(GetDlgItem(IDC_CHECK3)))->GetCheck())
	{//Verify Sum
		unsigned int sum=plot->GetSum();
		if (sum < m_uSum1 || sum > m_uSum2)
			return FALSE;
	}
	if (((CButton*)(GetDlgItem(IDC_CHECK7)))->GetCheck())
	{//Verify FS
		double fsSum=plot->GetFS();
		if (((m_dFS1+m_dFS2) < fsSum) || ((m_dFS1-m_dFS2) > fsSum))
			return FALSE;
	}
	int even=plot->GetEvenNumber(FALSE);
	if (((CButton*)(GetDlgItem(IDC_CHECK4)))->GetCheck() && ((even==0) || (even==7)))
	{//Verify 0 even,7 odd
			return FALSE;
	}
	if (((CButton*)(GetDlgItem(IDC_CHECK5)))->GetCheck() && ((even==1) || (even==6)))
	{//Verify 1 even,6 odd
			return FALSE;
	}
	if (((CButton*)(GetDlgItem(IDC_CHECK6)))->GetCheck() && ((even==2) || (even==5)))
	{//Verify 2 even,5 odd
			return FALSE;
	}
	return TRUE;
}

BOOL CDlgLottery::VerifyLotteryKillerFilter(LOTTERY *plot,BOOL bCheck)
{
	if (bCheck)
	{
		if (((CButton*)(GetDlgItem(IDC_CHECK8)))->GetCheck())

⌨️ 快捷键说明

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