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

📄 caipiaodlg.cpp

📁 简单的彩票选号系统
💻 CPP
字号:
// caipiaoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "caipiao.h"
#include "caipiaoDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCaipiaoDlg dialog

CCaipiaoDlg::CCaipiaoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCaipiaoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCaipiaoDlg)
	m_num1 = 0;
	m_num2 = 0;
	m_num3 = 0;
	m_num4 = 0;
	m_num5 = 0;
	m_num6 = 0;
	m_num7 = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCaipiaoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCaipiaoDlg)
	DDX_Text(pDX, IDC_EDIT1, m_num1);
	DDX_Text(pDX, IDC_EDIT2, m_num2);
	DDX_Text(pDX, IDC_EDIT3, m_num3);
	DDX_Text(pDX, IDC_EDIT4, m_num4);
	DDX_Text(pDX, IDC_EDIT5, m_num5);
	DDX_Text(pDX, IDC_EDIT6, m_num6);
	DDX_Text(pDX, IDC_EDIT7, m_num7);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCaipiaoDlg, CDialog)
	//{{AFX_MSG_MAP(CCaipiaoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_xuanhao, Onxuanhao)
	ON_BN_CLICKED(IDC_teshu, Onteshu)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCaipiaoDlg message handlers

BOOL CCaipiaoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCaipiaoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CCaipiaoDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCaipiaoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCaipiaoDlg::Onxuanhao() 
{
	// TODO: Add your control notification handler code here
 ((CWnd *)GetDlgItem(IDC_STATIC))->SetWindowText("状态:选号中....");
    int temp,pnum[35],num[6]; //临时变量,临时数组
    for(int i=0;i<35;i++)    //共有34个数组元素
        pnum[i]=i+1;
//***选号***//
    for(i=0;i<6;i++)
    {
        srand( (unsigned)time( NULL ) );
        temp=rand(); 
        temp=temp%34+1; //得到一个1-34的数
        while(pnum[temp]==0)//如果此元素以被选过则重选
        {
            srand( (unsigned)time( NULL ) );
            temp=rand();
            temp=temp%34+1;
        }
        num[i]=temp; //选定一个号码

        pnum[temp]=0; //给该元素置0,表示已被选过,如再有视为无效。
    }

//***排序***//
    for(int chance=1;chance<6;chance++)
    {
        int position=chance; //元素排序用到的游标
        for(i=0;i<6;i++){
            if(num[position]>num[i]) //如果后面的元素大于前面的,就交换位置
                {
                temp=num[position];
                num[position]=num[i];
                num[i]=temp; 
                }
        }
    }
//***显示***//
    m_num1=num[0];
    m_num2=num[1];
    m_num3=num[2];
    m_num4=num[3];
    m_num5=num[4];
    m_num6=num[5];
    UpdateData(FALSE); //通过变量刷新Edit控件的显示 
}

void CCaipiaoDlg::Onteshu() 
{
	// TODO: Add your control notification handler code here
   int temp2,num7; 
   srand( (unsigned)time( NULL ) );
   temp2=rand(); 
   temp2=temp2%16+1; //得到一个1-16的数
   num7=temp2;
//***显示***//
    m_num7=num7;
 UpdateData(FALSE); //通过变量刷新Edit控件的显示 
((CWnd *)GetDlgItem(IDC_STATIC))->SetWindowText("矬皮恭喜你中奖!矬皮恭喜你中奖!矬皮恭喜你中奖!\n请记住今天这个伟大的日子!");
}

⌨️ 快捷键说明

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