MFC控件之——双色球模拟器源码篇

主界面
在这里插入图片描述

#pragma once
#include "afxdialogex.h"


// DoubleBallrandNumber 对话框

class DoubleBallrandNumber : public CDialogEx
{
	DECLARE_DYNAMIC(DoubleBallrandNumber)

public:
	DoubleBallrandNumber(CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~DoubleBallrandNumber();

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_DoubleBall_Dlg };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	CStatic Redball1;
	CStatic Redball2;
	CStatic Redball3;
	CStatic Redball4;
	CStatic Redball5;
	CStatic Redball6;
	CStatic Redball7;
	afx_msg void OnBnClickedButton1();
	CListBox NumberList1;
	CListBox NumberList2;
	CListBox NumberList3;
	virtual BOOL OnInitDialog();
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);

	CBrush mybrush;//定义一个刷子
	int redarray1[30];
//	CEdit Edit_red1;
	CFont myFont;
	afx_msg void OnBnClickedButtonRed();
	afx_msg void OnBnClickedButtonBlue();
	afx_msg void OnBnClickedButtonAllball();
};

// DoubleBallrandNumber.cpp: 实现文件
//

#include "pch.h"
#include "MFCApp.h"
#include "afxdialogex.h"
#include "DoubleBallrandNumber.h"
#include "DatarulesDlg.h"
#include <vector>

// DoubleBallrandNumber 对话框
using namespace std;
IMPLEMENT_DYNAMIC(DoubleBallrandNumber, CDialogEx)

DoubleBallrandNumber::DoubleBallrandNumber(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DoubleBall_Dlg, pParent)
{

}

DoubleBallrandNumber::~DoubleBallrandNumber()
{
}

void DoubleBallrandNumber::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_1, Redball1);
	DDX_Control(pDX, IDC_STATIC_2, Redball2);
	DDX_Control(pDX, IDC_STATIC_3, Redball3);
	DDX_Control(pDX, IDC_STATIC_4, Redball4);
	DDX_Control(pDX, IDC_STATIC_5, Redball5);
	DDX_Control(pDX, IDC_STATIC_6, Redball6);
	DDX_Control(pDX, IDC_STATIC_7, Redball7);
	DDX_Control(pDX, IDC_LIST1, NumberList1);
	DDX_Control(pDX, IDC_LIST2, NumberList2);
	DDX_Control(pDX, IDC_LIST3, NumberList3);
}


BEGIN_MESSAGE_MAP(DoubleBallrandNumber, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &DoubleBallrandNumber::OnBnClickedButton1)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON_Red, &DoubleBallrandNumber::OnBnClickedButtonRed)
	ON_BN_CLICKED(IDC_BUTTON_Blue, &DoubleBallrandNumber::OnBnClickedButtonBlue)
	ON_BN_CLICKED(IDC_BUTTON_Allball, &DoubleBallrandNumber::OnBnClickedButtonAllball)
END_MESSAGE_MAP()


// DoubleBallrandNumber 消息处理程序


BOOL DoubleBallrandNumber::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	mybrush.CreateSolidBrush(RGB(87, 192, 255));
	//Edit_red1.SetBkColor(RGB(255, 0, 0));
	myFont.CreatePointFont(150, _T("宋体"));
	Redball1.SetFont(&myFont);
	Redball2.SetFont(&myFont);
	Redball3.SetFont(&myFont);
	Redball4.SetFont(&myFont);
	Redball5.SetFont(&myFont);
	Redball6.SetFont(&myFont);
	Redball7.SetFont(&myFont);
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}


void DoubleBallrandNumber::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	int red1 = rand() % (33 - 1 + 1) + 1;
	SetDlgItemInt(IDC_STATIC_1, red1);
	int red2 = rand() % (33 - 1 + 1) + 1;
	CString strred2; strred2.Format(_T("%d"), red2);
	SetDlgItemTextW(IDC_STATIC_2, strred2);
	int red3 = rand() % (33 - 1 + 1) + 1;
	SetDlgItemInt(IDC_STATIC_3, red3);
	int red4 = rand() % (33 - 1 + 1) + 1;
	SetDlgItemInt(IDC_STATIC_4, red4);
	int red5 = rand() % (33 - 1 + 1) + 1;
	SetDlgItemInt(IDC_STATIC_5, red5);
	int red6 = rand() % (33 - 1 + 1) + 1;
	SetDlgItemInt(IDC_STATIC_6, red6);
	int blue1 = rand() % (16 - 1 + 1) + 1;
	SetDlgItemInt(IDC_STATIC_7, blue1);
}


HBRUSH DoubleBallrandNumber::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何特性

		// 返回新画刷的句柄
	hbr = (HBRUSH)mybrush;

	if (pWnd->GetDlgCtrlID() == IDC_STATIC_1 ||
		pWnd->GetDlgCtrlID() == IDC_STATIC_2 ||
		pWnd->GetDlgCtrlID() == IDC_STATIC_3 ||
		pWnd->GetDlgCtrlID() == IDC_STATIC_4 ||
		pWnd->GetDlgCtrlID() == IDC_STATIC_5 ||
		pWnd->GetDlgCtrlID() == IDC_STATIC_6)
	{
		//设置文本框背景色
		//pDC->SetBkMode(TRANSPARENT);
		////设置文本框文字颜色
		pDC->SetTextColor(RGB(255, 255, 255));

		////设置文本框字体背景颜色
		pDC->SetBkColor(RGB(255, 0, 0));
	}
	if (pWnd->GetDlgCtrlID() == IDC_STATIC_7)
	{
		////设置文本框字体背景颜色
		pDC->SetTextColor(RGB(255, 255, 255));
		pDC->SetBkColor(RGB(0, 0, 255));
	}
	if (pWnd->GetDlgCtrlID() == IDC_STATIC_8)
	{
		pDC->SetTextColor(RGB(0, 0, 0));
		pDC->SetBkColor(RGB(87, 192, 255));
	}
	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
	return hbr;
}

//红球复式
//从红球号码中选择7-20个号码,从蓝色球号码里选择一个号码,组合成多注投注号码
void DoubleBallrandNumber::OnBnClickedButtonRed()
{
	// TODO: 在此添加控件通知处理程序代码
	DatarulesDlg dlg;
	dlg.flag = 1;
	dlg.DoModal();
	if (6 > dlg.redballnum)
	{
		MessageBox(L"红球数量选择异常,请重新选择");
		return;
	}
	CString strredball, strblueball, strshow;
	int _blue = rand() % (16 - 1 + 1) + 1;
	strblueball.Format(_T("%d"), _blue);
	vector<CString>vecredball;
	for (int i = 0; i < dlg.redballnum; i++)
	{
		int _red = rand() % (33 - 1 + 1) + 1;
		strredball.Format(_T("%d"), _red);
		vecredball.push_back(strredball);
	}
	NumberList1.ResetContent();
	for (int i = 0; i < dlg.redballnum - 5; i++)
		for (int j = i + 1; j < dlg.redballnum - 4; j++)
			for (int k = j + 1; k < dlg.redballnum - 3; k++)
				for (int m = k + 1; m < dlg.redballnum - 2; m++)
					for (int n = m + 1; n < dlg.redballnum - 1; n++)
						for (int L = m + 1; L < dlg.redballnum; L++)
						{
							strshow = vecredball[i] + _T(" ") + vecredball[j] + _T(" ") + vecredball[k] + _T(" ")
								+ vecredball[m] + _T(" ") + vecredball[n] + _T(" ") + vecredball[L] + _T(" ") + strblueball;
							NumberList1.AddString(strshow);
							strshow = vecredball[j] + _T(" ") + vecredball[k] + _T(" ") + vecredball[m] + _T(" ")
								+ vecredball[n] + _T(" ") + vecredball[L] + _T(" ") + vecredball[i] + _T(" ") + strblueball;
							NumberList1.AddString(strshow);
							strshow = vecredball[k] + _T(" ") + vecredball[m] + _T(" ") + vecredball[n] + _T(" ")
								+ vecredball[L] + _T(" ") + vecredball[i] + _T(" ") + vecredball[j] + _T(" ") + strblueball;
							NumberList1.AddString(strshow);
							strshow = vecredball[m] + _T(" ") + vecredball[n] + _T(" ") + vecredball[L] + _T(" ")
								+ vecredball[i] + _T(" ") + vecredball[j] + _T(" ") + vecredball[k] + _T(" ") + strblueball;
							NumberList1.AddString(strshow);
							strshow = vecredball[n] + _T(" ") + vecredball[L] + _T(" ") + vecredball[i] + _T(" ")
								+ vecredball[j] + _T(" ") + vecredball[k] + _T(" ") + vecredball[m] + _T(" ") + strblueball;
							NumberList1.AddString(strshow);
							strshow = vecredball[L] + _T(" ") + vecredball[i] + _T(" ") + vecredball[j] + _T(" ")
								+ vecredball[k] + _T(" ") + vecredball[m] + _T(" ") + vecredball[n] + _T(" ") + strblueball;
							NumberList1.AddString(strshow);
						}

}

//蓝球复式
//从红球号码中选择6个号码,从蓝色球号码里选择2-16号码,组合成多注投注号码
void DoubleBallrandNumber::OnBnClickedButtonBlue()
{
	// TODO: 在此添加控件通知处理程序代码
	DatarulesDlg dlg;
	dlg.flag = 2;
	dlg.DoModal();
	if (1 > dlg.blueballnum)
	{
		MessageBox(L"蓝球数量选择异常,请重新选择");
		return;
	}
	CString strredball, strblueball, strshow;
	for (int i = 0; i < 6; i++)
	{
		int _red = rand() % (33 - 1 + 1) + 1;
		CString str; str.Format(_T("%d "), _red);
		strredball += str;
	}
	vector<CString>vecblueball;
	for (int i = 0; i < dlg.blueballnum; i++)
	{
		int _blue = rand() % (16 - 1 + 1) + 1;
		strblueball.Format(_T("%d "), _blue);
		vecblueball.push_back(strblueball);
	}
	NumberList2.ResetContent();
	for (int i = 0; i < vecblueball.size(); i++)
	{
		strshow = strredball + vecblueball[i];
		NumberList2.AddString(strshow);
	}

}

//全复式
//从红球号码中选择7-20个号码,从蓝色球号码里选择2-16号码,组合成多注投注号码
void DoubleBallrandNumber::OnBnClickedButtonAllball()
{
	// TODO: 在此添加控件通知处理程序代码
	DatarulesDlg dlg;
	dlg.flag = 3;
	dlg.DoModal();
	if (6 > dlg.redballnum)
	{
		MessageBox(L"红球数量选择异常,请重新选择");
		return;
	}
	if (1 > dlg.blueballnum)
	{
		MessageBox(L"蓝球数量选择异常,请重新选择");
		return;
	}
	CString strredball, strblueball, strshow;
	vector<CString>vecredball;
	for (int i = 0; i < dlg.redballnum; i++)
	{
		int _red = rand() % (33 - 1 + 1) + 1;
		strredball.Format(_T("%d "), _red);
		vecredball.push_back(strredball);
	}
	vector<CString>vecblueball;
	for (int i = 0; i < dlg.blueballnum; i++)
	{
		int _blue = rand() % (16 - 1 + 1) + 1;
		strblueball.Format(_T("%d "), _blue);
		vecblueball.push_back(strblueball);
	}

	NumberList3.ResetContent();
	for (int i = 0; i < dlg.redballnum - 5; i++)
		for (int j = i + 1; j < dlg.redballnum - 4; j++)
			for (int k = j + 1; k < dlg.redballnum - 3; k++)
				for (int m = k + 1; m < dlg.redballnum - 2; m++)
					for (int n = m + 1; n < dlg.redballnum - 1; n++)
						for (int L = m + 1; L < dlg.redballnum; L++)
							for (int i_blue = 0; i_blue < vecblueball.size(); i_blue++)
							{
								strshow = vecredball[i] + vecredball[j] + vecredball[k]
									+ vecredball[m] + vecredball[n] + vecredball[L] + vecblueball[i_blue];
								NumberList3.AddString(strshow);
								strshow = vecredball[j] + vecredball[k] + vecredball[m]
									+ vecredball[n] + vecredball[L] + vecredball[i] + vecblueball[i_blue];
								NumberList3.AddString(strshow);
								strshow = vecredball[k] + vecredball[m] + vecredball[n]
									+ vecredball[L] + vecredball[i] + vecredball[j] + vecblueball[i_blue];
								NumberList3.AddString(strshow);
								strshow = vecredball[m] + vecredball[n] + vecredball[L]
									+ vecredball[i] + vecredball[j] + vecredball[k] + vecblueball[i_blue];
								NumberList3.AddString(strshow);
								strshow = vecredball[n] + vecredball[L] + vecredball[i]
									+ vecredball[j] + vecredball[k] + vecredball[m] + vecblueball[i_blue];
								NumberList3.AddString(strshow);
								strshow = vecredball[L] + vecredball[i] + vecredball[j]
									+ vecredball[k] + vecredball[m] + vecredball[n] + vecblueball[i_blue];
								NumberList3.AddString(strshow);
							}


}

模式选择界面
在这里插入图片描述

#pragma once
#include "afxdialogex.h"


// DatarulesDlg 对话框

class DatarulesDlg : public CDialogEx
{
	DECLARE_DYNAMIC(DatarulesDlg)

public:
	DatarulesDlg(CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~DatarulesDlg();

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_DIALOG2 };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	CComboBox Combo_Red;
	CComboBox Combo_Blue;
	afx_msg void OnBnClickedOk();
	virtual BOOL OnInitDialog();
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	CBrush datarulebrush;//定义一个刷子
	int flag = 0;//选择的模式
	int redballnum = 6;
	int blueballnum = 1;
};

// DatarulesDlg.cpp: 实现文件
//

#include "pch.h"
#include "MFCApp.h"
#include "afxdialogex.h"
#include "DatarulesDlg.h"


// DatarulesDlg 对话框

IMPLEMENT_DYNAMIC(DatarulesDlg, CDialogEx)

DatarulesDlg::DatarulesDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG2, pParent)
{

}

DatarulesDlg::~DatarulesDlg()
{
}

void DatarulesDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO_red, Combo_Red);
	DDX_Control(pDX, IDC_COMBO_blue, Combo_Blue);
}


BEGIN_MESSAGE_MAP(DatarulesDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &DatarulesDlg::OnBnClickedOk)
	ON_WM_CTLCOLOR()
END_MESSAGE_MAP()


// DatarulesDlg 消息处理程序


void DatarulesDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(FALSE);
	switch (flag)
	{
	case 1:
	{
		redballnum = Combo_Red.GetCurSel() + 7;
		blueballnum = Combo_Blue.GetCurSel();
	}
	break;
	case 2:
	{
		redballnum = Combo_Red.GetCurSel();
		blueballnum = Combo_Blue.GetCurSel() + 2;
	}
	break;
	case 3:
	{
		redballnum = Combo_Red.GetCurSel() + 7;
		blueballnum = Combo_Blue.GetCurSel() + 2;
	}
	break;

	default:
		break;
	}

	CDialogEx::OnOK();
}


BOOL DatarulesDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	datarulebrush.CreateSolidBrush(RGB(87, 152, 255));
	switch (flag)
	{
	case 1:
	{
		SetDlgItemText(IDC_STATIC_log, _T("您选择的是红球复式模式,请选择红球号码基准数量【7-20】"));
		Combo_Red.Clear();
		for (int i = 0; i < 14; i++)
		{
			CString str; str.Format(_T("%d"), i + 7);
			Combo_Red.AddString(str);
		}
		Combo_Red.SetCurSel(0);
		//蓝球数量
		Combo_Blue.Clear();
		Combo_Blue.AddString(L"1");
		Combo_Blue.SetCurSel(0);
	}break;
	case 2:
	{
		SetDlgItemText(IDC_STATIC_log, _T("您选择的是蓝球复式模式,请选择蓝球号码基准数量【2-16】"));
		Combo_Red.Clear();
		Combo_Red.AddString(L"6");
		Combo_Red.SetCurSel(0);
		//蓝球数量
		Combo_Blue.Clear();
		for (int i = 0; i < 15; i++)
		{
			CString str; str.Format(_T("%d"), i + 2);
			Combo_Blue.AddString(str);
		}
		Combo_Blue.SetCurSel(0);
	}break;
	case 3:
	{
		SetDlgItemText(IDC_STATIC_log, _T("您选择的是全复式模式,请选择红球号码基准数量【7-20】,请选择蓝球号码基准数量【2-16】"));
		Combo_Red.Clear();
		for (int i = 0; i < 14; i++)
		{
			CString str; str.Format(_T("%d"), i + 7);
			Combo_Red.AddString(str);
		}
		Combo_Red.SetCurSel(0);
		//蓝球数量
		Combo_Blue.Clear();
		for (int i = 0; i < 15; i++)
		{
			CString str; str.Format(_T("%d"), i + 2);
			Combo_Blue.AddString(str);
		}
		Combo_Blue.SetCurSel(0);
	}break;
	default:
		break;
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}


HBRUSH DatarulesDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
	if (nCtlColor == CTLCOLOR_DLG)
	{
		hbr = (HBRUSH)datarulebrush;
	}
	// TODO:  在此更改 DC 的任何特性
	if (pWnd->GetDlgCtrlID() == IDC_STATIC_log)
	{
		pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(RGB(0, 25, 25));
	}
	if (pWnd->GetDlgCtrlID() == IDC_STATIC_rednum || pWnd->GetDlgCtrlID() == IDC_STATIC_bluenum)
	{
		//设置文本框背景色
		//pDC->SetBkMode(TRANSPARENT);
		//设置文本框文字颜色
		pDC->SetTextColor(RGB(0, 25, 25));
		//设置文本框字体背景颜色
		pDC->SetBkColor(RGB(87, 152, 255));
	}
	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
	return hbr;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值