www.gusucode.com > 一个VC++随机选号程序源码程序 > 一个VC++随机选号程序/Caipiao/Caipiao/彩票Dlg.cpp
// 彩票Dlg.cpp : implementation file //Download by http://www.codesc.net #include "stdafx.h" #include "彩票.h" #include "彩票Dlg.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 }; CHyperLink m_Mail; //}}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 m_Mail.SetURL("mailto:peijikui@sd365.com"); // m_linkTry.SetURL("http://www.sina.com.cn"); } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) DDX_Control(pDX, IDC_MAIL, m_Mail); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyDlg dialog CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMyDlg) m_iFlotteryCopys = 1; m_strMust = _T(""); m_strMustNot = _T(""); m_iSortStyle = 0; m_iMaxNum = 5; m_iMinNum = 1; m_bOdd = FALSE; m_bMin = FALSE; m_bMax = FALSE; m_iOddNum = 3; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMyDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyDlg) DDX_Control(pDX, IDC_MAIL, m_linkMail); DDX_Control(pDX, IDC_RESULT, m_ctlResult); DDX_Control(pDX, IDC_TYPE, m_ctlFlotteryType); DDX_Text(pDX, IDC_TIMES, m_iFlotteryCopys); DDX_Control(pDX, IDC_ADDRESS, m_linkAddress); DDX_Text(pDX, IDC_MUSTSELECT, m_strMust); DDX_Text(pDX, IDC_MUSTNOTSELECT, m_strMustNot); DDX_Radio(pDX, IDC_SORT1, m_iSortStyle); DDX_Text(pDX, IDC_MAXNUM, m_iMaxNum); DDV_MinMaxInt(pDX, m_iMaxNum, 5, 36); DDX_Text(pDX, IDC_MINNUM, m_iMinNum); DDV_MinMaxInt(pDX, m_iMinNum, 1, 40); DDX_Check(pDX, IDC_SETODD, m_bOdd); DDX_Check(pDX, IDC_SETMIN, m_bMin); DDX_Check(pDX, IDC_SETMAX, m_bMax); DDX_Text(pDX, IDC_ODDNUM, m_iOddNum); DDV_MinMaxInt(pDX, m_iOddNum, 0, 7); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMyDlg, CDialog) //{{AFX_MSG_MAP(CMyDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_ADVANCESETTING, OnAdvancesetting) ON_BN_CLICKED(IDC_BEGIN, OnBegin) ON_BN_CLICKED(IDC_SEEHISTORY, OnSeehistory) ON_BN_CLICKED(IDC_SETMAX, OnSetmax) ON_BN_CLICKED(IDC_SETMIN, OnSetmin) ON_BN_CLICKED(IDC_SETODD, OnSetodd) ON_WM_DESTROY() ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyDlg message handlers BOOL CMyDlg::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 m_ctlFlotteryType.SetCurSel(0); CRect rcDlg; GetWindowRect(&rcDlg); CWnd * pSmall = GetDlgItem(IDC_SMALL); CRect rcSmall; pSmall->GetWindowRect(&rcSmall); rcDlg.bottom = rcSmall.bottom; MoveWindow(rcDlg); m_linkAddress.SetURL("www.lottery.gov.cn"); m_linkMail.SetURL(_T("mailto:peijikui@sd365.com")); pLabelDlg = new CLabelDlg; pLabelDlg->Create(IDD_LABEL); pLabelDlg->ShowWindow(SW_SHOW); return TRUE; // return TRUE unless you set the focus to a control } void CMyDlg::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 CMyDlg::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(); /*CPaintDC dcClient(this); //dcClient.CreateCompatibleDC(pDC); CBitmap bitmap; if( bitmap.LoadBitmap(IDB_BACK)) { CDC memDC; memDC.CreateCompatibleDC(&dcClient); memDC.SelectObject(&bitmap); BITMAP bmpInfo; bitmap.GetBitmap(&bmpInfo); CRect rcClient; GetClientRect(&rcClient); dcClient.StretchBlt(rcClient.left,rcClient.top,rcClient.right,rcClient.bottom,&memDC,0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,SRCCOPY); memDC.DeleteDC(); } //*/ } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CMyDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CMyDlg::OnAdvancesetting() { // TODO: Add your control notification handler code here CWnd * pButton = GetDlgItem(IDC_ADVANCESETTING); ASSERT_VALID(pButton); CString strButton; pButton->GetWindowText(strButton); CString strTitle; strTitle.LoadString(IDS_ADVANCELARGER); BOOL bExpand =( strButton == strTitle); CRect rcDlg; GetWindowRect(&rcDlg); if(bExpand)//enlarger the dialog { strTitle.LoadString(IDS_ADVANCESMALL); pButton ->SetWindowText(strTitle); CWnd * pLarger = GetDlgItem(IDC_LARGER); CRect rcLarger; pLarger->GetWindowRect(&rcLarger); rcDlg.bottom = rcLarger.bottom; CWnd * pMust = GetDlgItem(IDC_MUSTSELECT); pMust ->SetFocus(); MoveWindow(rcDlg,TRUE);//*/ } else//收缩 { strTitle.LoadString(IDS_ADVANCELARGER); pButton ->SetWindowText(strTitle); CWnd * pLarger = GetDlgItem(IDC_SMALL); CRect rcSmall; pLarger->GetWindowRect(&rcSmall); rcDlg.bottom = rcSmall.bottom; CWnd * pTemp; if(m_ctlFlotteryType.GetCurSel() == 0) pTemp = GetDlgItem(IDC_TYPE); else pTemp = GetDlgItem(IDC_BEGIN); pTemp ->SetFocus(); MoveWindow(rcDlg,TRUE); } } BOOL CMyDlg::CheckValid(int iNum) { if(listOk.GetCount() == 0 && listFade.GetCount() == 0) return TRUE; int iCount = listOk.GetCount(); POSITION pos = listOk.GetHeadPosition(); for(int i = 0 ; i < iCount; i++) { int iTemp = listOk.GetAt(pos); if(iTemp == iNum) return FALSE; } iCount = listFade.GetCount(); pos = listFade.GetHeadPosition(); for(i = 0; i< iCount; i ++) { int iTemp = listFade.GetAt(pos); if(iTemp == iNum) return FALSE; } return TRUE; } void CMyDlg::OnBegin() { // TODO: Add your control notification handler code here UpdateData(); int iTotalSel; int iToSel; int iType = m_ctlFlotteryType.GetCurSel(); switch(iType) { case 0: AfxMessageBox("请选择彩票类型"); return; case 1: case 4: iTotalSel = 23; iToSel = 5; break; case 2: iTotalSel = 29; iToSel = 7; break; case 3: iTotalSel = 35; iToSel = 7; break; case 5: iTotalSel = 30; iToSel = 7; break; case 6: iTotalSel = 36; iToSel = 7; break; default: break; } Flottery flottery(iTotalSel,iToSel); flottery.SetCareMax(m_bMax);//设定是否指定最大数 flottery.SetCareMin(m_bMin);//设定是否指定最小数 flottery.SetCareOdd(m_bOdd);//设定是否指定奇数个数 flottery.SetMaxNum(m_iMaxNum);//设置最大数 flottery.SetMinNum(m_iMinNum);//设置最小数 flottery.SetOddNum(m_iOddNum);//设置奇数个数 CString strTemp; m_strMust.TrimLeft(); m_strMust.TrimRight(); //创建必选链表 while(strTemp != m_strMust) { int iTemp = m_strMust.FindOneOf(" ,;:#@*&%$"); if(iTemp < 0) strTemp = m_strMust; else { strTemp = m_strMust.Left(iTemp+1); m_strMust = m_strMust.Right(m_strMust.GetLength() - iTemp-1); m_strMust.TrimLeft(); } int iMustItem = atoi(strTemp.GetBuffer(strTemp.GetLength())); strTemp.ReleaseBuffer(); flottery.BuildMustList(iMustItem); } //创建必不选链表 strTemp.Empty(); m_strMustNot.TrimLeft(); m_strMustNot.TrimRight(); while(strTemp != m_strMustNot) { int iTemp = m_strMustNot.FindOneOf(" ,;:#@*&%$"); if(iTemp < 0) strTemp = m_strMustNot; else { strTemp = m_strMustNot.Left(iTemp+1); m_strMustNot = m_strMustNot.Right(m_strMustNot.GetLength() - iTemp-1); m_strMustNot.TrimLeft(); } int iMustItem = atoi(strTemp.GetBuffer(strTemp.GetLength())); strTemp.ReleaseBuffer(); // if(iMustItem != 0) flottery.BuildMustNotList(iMustItem); } static int iPrintTimes = 1; for(int iTimes = 0; iTimes < m_iFlotteryCopys; iTimes++) { int iResult = flottery.DoSelect(m_iSortStyle);//进行随机选择 CWnd * pMust; // int iHead; int iCurSel = m_ctlFlotteryType.GetCurSel(); int iPos ; switch(iResult) { case 0: if(iPrintTimes == 1)//只有在第一次才打印 { CString strCurType; iCurSel = m_ctlFlotteryType.GetCurSel(); strTemp.Format(" 共%d注",m_iFlotteryCopys); m_ctlFlotteryType.GetLBText(iCurSel,strCurType); strCurType = strCurType +strTemp+ "\n"; iPos = m_ctlResult.GetTextLength(); m_ctlResult.SetSel(iPos,iPos); m_ctlResult.ReplaceSel(strCurType); iPrintTimes ++; } iPos = m_ctlResult.GetTextLength(); m_ctlResult.SetSel(iPos,iPos); while(flottery.GetNextInt(iHead)) { CString strResult; strResult.Format("%d ",iHead); m_ctlResult.ReplaceSel(strResult); } m_ctlResult.ReplaceSel("\n"); break; case MUSTTOOMANY: AfxMessageBox("输入的必选项太多"); pMust = GetDlgItem(IDC_MUSTSELECT); pMust ->SetFocus(); return; case TWOLISTCOLLIPSE: AfxMessageBox("必选项和必不选项存在相同数"); pMust = GetDlgItem(IDC_MUSTSELECT); pMust ->SetFocus(); return; case ITEMERROR: AfxMessageBox("必选项输入错误"); pMust = GetDlgItem(IDC_MUSTSELECT); pMust ->SetFocus(); return; case MAXERROR: AfxMessageBox("输入的最大数错误"); pMust = GetDlgItem(IDC_MAXNUM); pMust ->SetFocus(); return; case MINERROR: AfxMessageBox("输入的最小数错误"); pMust = GetDlgItem(IDC_MINNUM); pMust ->SetFocus(); return; case ODDTOOMANY: AfxMessageBox("输入的奇数个数太多"); pMust = GetDlgItem(IDC_ODDNUM); pMust ->SetFocus(); return; case MINBIGGERMAX: AfxMessageBox("最大数比最小数小"); pMust = GetDlgItem(IDC_MAXNUM); pMust ->SetFocus(); return; case ERRANTOOLITTLE: AfxMessageBox("最大数和最小数区间太小"); pMust = GetDlgItem(IDC_MAXNUM); pMust ->SetFocus(); return; case EVENTOOLITTLE: AfxMessageBox("最大数和最小数区间的偶数不足"); pMust = GetDlgItem(IDC_ODDNUM); pMust ->SetFocus(); return; case ODDTOOLITTLE: AfxMessageBox("最大数和最小数区间的奇数不足"); pMust = GetDlgItem(IDC_ODDNUM); pMust ->SetFocus(); return; case MUSTBIGGERMAX: AfxMessageBox("必选项中的数字大于规定的最大数"); pMust = GetDlgItem(IDC_MUSTSELECT); pMust ->SetFocus(); return; case MUSTLESSMIN : AfxMessageBox("必选项中的数字小于规定的最小数"); pMust = GetDlgItem(IDC_MUSTSELECT); pMust ->SetFocus(); return; case MUSTNOTTOOMANY: AfxMessageBox("必不选项中选项太多"); pMust = GetDlgItem(IDC_MUSTNOTSELECT); pMust ->SetFocus(); return; case MUSTODDTOOMANY: AfxMessageBox("必选项中项太多"); pMust = GetDlgItem(IDC_MUSTSELECT); pMust ->SetFocus(); return; default: AfxMessageBox("输入存在错误"); return; } } iPrintTimes = 1; } BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message == WM_KEYDOWN) { switch(pMsg->wParam) { case VK_RETURN://屏蔽回车 return TRUE; case VK_ESCAPE://屏蔽Esc return TRUE; } } return CDialog::PreTranslateMessage(pMsg); } extern CMyApp theApp; void CMyDlg::OnSeehistory() { // TODO: Add your control notification handler code here HWND pWnd = ::FindWindow(NULL,"阿皮小精灵"); if(pWnd != NULL) { GetDlgItem(IDC_SEEHISTORY) ->SetWindowText("开启小精灵"); delete pLabelDlg; } else { GetDlgItem(IDC_SEEHISTORY) ->SetWindowText("关闭小精灵"); pLabelDlg = new CLabelDlg; pLabelDlg->Create(IDD_LABEL); pLabelDlg->ShowWindow(SW_SHOW); } return; } void CMyDlg::OnSetmax() { // TODO: Add your control notification handler code here UpdateData(); CEdit * pItem = static_cast<CEdit *>(GetDlgItem(IDC_MAXNUM)); pItem->EnableWindow(m_bMax); if(m_bMax) { pItem->SetFocus(); pItem->SetSel(0,-1); } } void CMyDlg::OnSetmin() { // TODO: Add your control notification handler code here UpdateData(); CEdit * pItem = static_cast<CEdit *>(GetDlgItem(IDC_MINNUM)); pItem->EnableWindow(m_bMin); if(m_bMin) { pItem ->SetFocus(); pItem ->SetSel(0,-1); } } void CMyDlg::OnSetodd() { // TODO: Add your control notification handler code here UpdateData(); CEdit * pItem =static_cast<CEdit *>(GetDlgItem(IDC_ODDNUM)); pItem->EnableWindow(m_bOdd); if(m_bOdd) { pItem ->SetFocus(); pItem ->SetSel(0,-1); } } void CMyDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here HWND hWnd = ::FindWindow(NULL,"阿皮小精灵"); if(hWnd != NULL) delete pLabelDlg; } void CMyDlg::OnClose() { // TODO: Add your message handler code here and/or call default if(MessageBox("真的要退出?","警告!",MB_YESNO) == IDYES) CDialog::OnClose(); }