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

📄 selectnumberdlg.cpp

📁 一个关于怎样模拟双色球彩票的代码 非常好的哦~~ 直接在VC++6 可编译
💻 CPP
字号:
// SelectNumberDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DoubleColorBall.h"
#include "SelectNumberDlg.h"

#include "CommDef.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSelectNumberDlg dialog

// 初始化成员变量
CSelectNumberDlg::CSelectNumberDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSelectNumberDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSelectNumberDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_nRedBall1 = 1;  // 红球1
	m_nRedBall2 = 2;  // 红球2
	m_nRedBall3 = 3;  // 红球3
	m_nRedBall4 = 4;  // 红球4
	m_nRedBall5 = 5;  // 红球5
	m_nRedBall6 = 6;  // 红球6
	m_nBlueBall1 = 8; // 蓝球1

	m_nSortStyle = 0;
	m_nLotterycopys = 1;

    m_aRedBallNumber.RemoveAll();
    m_csRedBallNumberArray.RemoveAll();
}


void CSelectNumberDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSelectNumberDlg)
	DDX_Control(pDX, IDC_STATIC_RED_BALL, m_StaticRedBall);
	DDX_Control(pDX, IDC_STATIC_REDBALL1, m_MyStaticRedBall1);
	DDX_Control(pDX, IDC_STATIC_REDBALL2, m_MyStaticRedBall2);
	DDX_Control(pDX, IDC_STATIC_REDBALL3, m_MyStaticRedBall3);
	DDX_Control(pDX, IDC_STATIC_REDBALL4, m_MyStaticRedBall4);
	DDX_Control(pDX, IDC_STATIC_REDBALL5, m_MyStaticRedBall5);
	DDX_Control(pDX, IDC_STATIC_REDBALL6, m_MyStaticRedBall6);
	DDX_Control(pDX, IDC_STATIC_BLUEBALL1, m_MyStaticBlueBall);
	DDX_Control(pDX, IDC_STATIC_BLUE_BALL, m_StaticBlueBall);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSelectNumberDlg, CDialog)
	//{{AFX_MSG_MAP(CSelectNumberDlg)
	ON_BN_CLICKED(IDC_BUTTON_START_SEL_NUM, OnButtonStartSelectNumber)
	ON_BN_CLICKED(IDC_BUTTON_QUIT, OnButtonQuit)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSelectNumberDlg message handlers
// 初始化选号对话框
BOOL CSelectNumberDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	// 为红、蓝球设定初始值
	SetInitValueForRedBlueBall();

	// 改变静态文本的字体
	ChangeFontForStaticText();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

// 为静态文本标签设置文字
void CSelectNumberDlg::SetValueForStaticText(int nStaticTextID, int nValue)
{
	CStatic *myStaticCtrl = (CStatic*)this->GetDlgItem(nStaticTextID);
    CString csValue = _T(""); // 清空
    csValue.Format(_T("%d"), nValue);
    myStaticCtrl->SetWindowText(csValue);
}

// 为红、蓝球设置初始值
void CSelectNumberDlg::SetInitValueForRedBlueBall()
{
	// 设定6个红球
	SetValueForStaticText( IDC_STATIC_REDBALL1, m_nRedBall1 );
	SetValueForStaticText( IDC_STATIC_REDBALL2, m_nRedBall2 );
	SetValueForStaticText( IDC_STATIC_REDBALL3, m_nRedBall3 );
	SetValueForStaticText( IDC_STATIC_REDBALL4, m_nRedBall4 );
	SetValueForStaticText( IDC_STATIC_REDBALL5, m_nRedBall5 );
	SetValueForStaticText( IDC_STATIC_REDBALL6, m_nRedBall6 );

	// 设定1个蓝球
	SetValueForStaticText( IDC_STATIC_BLUEBALL1, m_nBlueBall1 );
}

// 改变静态文本标签中文本的字体
void CSelectNumberDlg::ChangeFontForStaticText()
{
	LOGFONT LogFont;
	LPCTSTR lpszFaceName1 = _T("Chinese Simplified(GB2312)"); // 楷体
	GetFont()->GetLogFont(&LogFont);
	LogFont.lfHeight += LogFont.lfHeight*2;
	LogFont.lfWidth += LogFont.lfWidth*2;
	strcpy (LogFont.lfFaceName, lpszFaceName1);
	m_font1.CreateFontIndirect(&LogFont);

	GetDlgItem(IDC_STATIC_RED_BALL)->SetFont(&m_font1);  // 红球标签
	GetDlgItem(IDC_STATIC_BLUE_BALL)->SetFont(&m_font1);  // 蓝球标签

	LPCTSTR lpszFaceName2 = _T("Chinese Simplified(GB2312)");  // 楷体
	GetFont()->GetLogFont(&LogFont);
	LogFont.lfHeight += LogFont.lfHeight*4; // 字的高度
	LogFont.lfWidth += LogFont.lfWidth*4;  // 字的宽度
	strcpy (LogFont.lfFaceName, lpszFaceName2);
	m_font2.CreateFontIndirect(&LogFont);

	GetDlgItem(IDC_STATIC_REDBALL1)->SetFont(&m_font2);
	GetDlgItem(IDC_STATIC_REDBALL2)->SetFont(&m_font2);
	GetDlgItem(IDC_STATIC_REDBALL3)->SetFont(&m_font2);
	GetDlgItem(IDC_STATIC_REDBALL4)->SetFont(&m_font2);
	GetDlgItem(IDC_STATIC_REDBALL5)->SetFont(&m_font2);
	GetDlgItem(IDC_STATIC_REDBALL6)->SetFont(&m_font2);
	GetDlgItem(IDC_STATIC_BLUEBALL1)->SetFont(&m_font2);

	SetFontColorForStaticText();
}

// 设置红、蓝球的颜色
void CSelectNumberDlg::SetFontColorForStaticText()
{
	// 设定红球颜色
	m_StaticRedBall.SetBkColor( RGB(255, 191, 127) );
	m_StaticRedBall.SetForeColor( RGB(255, 0, 0) );

	m_MyStaticRedBall1.SetBkColor( RGB(255, 191, 127) );
	m_MyStaticRedBall1.SetForeColor( RGB(255, 0, 0) );

	m_MyStaticRedBall2.SetBkColor( RGB(255, 191, 127) );
	m_MyStaticRedBall2.SetForeColor( RGB(255, 0, 0) );

	m_MyStaticRedBall3.SetBkColor( RGB(255, 191, 127) );
	m_MyStaticRedBall3.SetForeColor( RGB(255, 0, 0) );

	m_MyStaticRedBall4.SetBkColor( RGB(255, 191, 127) );
	m_MyStaticRedBall4.SetForeColor( RGB(255, 0, 0) );

	m_MyStaticRedBall5.SetBkColor( RGB(255, 191, 127) );
	m_MyStaticRedBall5.SetForeColor( RGB(255, 0, 0) );

	m_MyStaticRedBall6.SetBkColor( RGB(255, 191, 127) );
	m_MyStaticRedBall6.SetForeColor( RGB(255, 0, 0) );

	// 设定蓝球颜色
	m_StaticBlueBall.SetBkColor( RGB(255, 191, 127) );
	m_StaticBlueBall.SetForeColor( RGB(0, 0, 255) );

	m_MyStaticBlueBall.SetBkColor( RGB(255, 191, 127) );
	m_MyStaticBlueBall.SetForeColor( RGB(0, 0, 255) );
}

// 开始选号
void CSelectNumberDlg::OnButtonStartSelectNumber() 
{
	// TODO: Add your control notification handler code here
	// 生成6个随机数
	GenerateRandomNumber(33, 6);
	
	// 设置定时器
	SetTimer(TIMER_FLAG_1,10,NULL);
	SetTimer(TIMER_FLAG_2,5000,NULL);
}

void CSelectNumberDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	// 显示红球
	if ( TIMER_FLAG_2 == nIDEvent )
	{
		KillTimer( TIMER_FLAG_1 ); // 停止选择

        DisplayRealRedBallNumber();        
	}
	
	// 选择红、蓝球
	if ( TIMER_FLAG_1 == nIDEvent )
    {        
        ChooseDoubleColorBall();                  								                
    }

	CDialog::OnTimer(nIDEvent);
}

// 显示红球号码
void CSelectNumberDlg::DisplayRealRedBallNumber()
{
	// 取得6个红球值
	int nRedBall1 = m_aRedBallNumber.GetAt(0);
	int nRedBall2 = m_aRedBallNumber.GetAt(1);
	int nRedBall3 = m_aRedBallNumber.GetAt(2);
	int nRedBall4 = m_aRedBallNumber.GetAt(3);
	int nRedBall5 = m_aRedBallNumber.GetAt(4);
	int nRedBall6 = m_aRedBallNumber.GetAt(5);
	
	// 设置6个红球值
	SetValueForStaticText( IDC_STATIC_REDBALL1, nRedBall1 );
	SetValueForStaticText( IDC_STATIC_REDBALL2, nRedBall2 );
	SetValueForStaticText( IDC_STATIC_REDBALL3, nRedBall3 );
	SetValueForStaticText( IDC_STATIC_REDBALL4, nRedBall4 );
	SetValueForStaticText( IDC_STATIC_REDBALL5, nRedBall5 );
	SetValueForStaticText( IDC_STATIC_REDBALL6, nRedBall6 );
}

// 选择红、蓝球
void CSelectNumberDlg::ChooseDoubleColorBall()
{
	CString csRedBall1Number1 = _T("");
    CString csRedBall1Number2 = _T("");
    CString csRedBall1Number3 = _T("");
    CString csRedBall1Number4 = _T("");
    CString csRedBall1Number5 = _T("");
    CString csRedBall1Number6 = _T("");
    CString csBlueBall1Numbe = _T("");

    // 从33个红球中选6个红球
	GenerateRandomNumber( 33, 1, IDC_STATIC_REDBALL1, 
		                  csRedBall1Number1, m_nRedBall1 );
	GenerateRandomNumber( 33, 1, IDC_STATIC_REDBALL2, 
		                  csRedBall1Number2, m_nRedBall2 );
	GenerateRandomNumber( 33, 1, IDC_STATIC_REDBALL3, 
		                  csRedBall1Number3, m_nRedBall3 );
	GenerateRandomNumber( 33, 1, IDC_STATIC_REDBALL4, 
		                  csRedBall1Number3, m_nRedBall4 );
	GenerateRandomNumber( 33, 1, IDC_STATIC_REDBALL5, 
		                  csRedBall1Number5, m_nRedBall5 );
	GenerateRandomNumber( 33, 1, IDC_STATIC_REDBALL6, 
		                  csRedBall1Number6, m_nRedBall6 );        

	// 从16个蓝球中选1个蓝球
	GenerateRandomNumber( 16, 1, IDC_STATIC_BLUEBALL1, 
		                  csBlueBall1Numbe, m_nBlueBall1 );
}

// 生成随机数
void CSelectNumberDlg::GenerateRandomNumber(int nTotalNum, int nChooseNum )
{
	Flottery flottery(nTotalNum, nChooseNum);

	static int nPrintTimes = 1;
	int nBallNumber = 0;
	m_aRedBallNumber.RemoveAll();

	for ( int nTimes = 0; nTimes < m_nLotterycopys; nTimes++ )
	{
	
		int nResult = flottery.DoSelect(m_nSortStyle); // 进行随机选择

		switch ( nResult )
		{
		
		case 0:							
			while(flottery.GetNextInt(nBallNumber))
			{					
				m_aRedBallNumber.Add( nBallNumber );  // 添加到数组
			}									
			break;
			
		default:		
			return;
		}
	}

	nPrintTimes = 1;
}

// 生成随机数
void CSelectNumberDlg::GenerateRandomNumber(int nTotal, 
											int nChoose, 
											int nStaticTextID, 
                                            CString csBallNumber, 
											int nBallNumber)
{
	
    Flottery flottery(nTotal, nChoose);

	static int nPrintTimes = 1;

	for ( int nTimes = 0; nTimes < m_nLotterycopys; nTimes++ )
	{
	
		int nResult = flottery.DoSelect(m_nSortStyle); // 进行随机选择

		switch ( nResult )
		{
		
		case 0:							
			while ( flottery.GetNextInt(nBallNumber) )
			{					
				csBallNumber.Format(_T("%d"), nBallNumber);  // 格式化
			}									
			break;
			
		default:		
			return;
		}
	}

	nPrintTimes = 1;
	
    csBallNumber.Format(_T("%d"), nBallNumber);

    CStatic *StaticBallNumber = (CStatic*)this->GetDlgItem(nStaticTextID);
    StaticBallNumber->SetWindowText(csBallNumber);

    m_csRedBallNumberArray.Add( csBallNumber );  // 添加到数组
}

// 退出本对话框
void CSelectNumberDlg::OnButtonQuit() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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