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

📄 randomphonedlg.cpp

📁 手机选中奖号器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	UINT a;
	a = pstart->GetButtonStyle();
	a = a & ( 0xffffffff ^ BS_DEFPUSHBUTTON );
	pstart->SetButtonStyle(a);

	a = pstop->GetButtonStyle();
	a = a & ( 0xffffffff | BS_DEFPUSHBUTTON );
	pstop->SetButtonStyle(a);

	//----------------------------------------

    m_bSelect = TRUE;
    srand( (unsigned)time( NULL ) );
	CString s;

	RandomPhone();

	for ( int i = 0; i < m_genonce; i++)
	{
        AddOnePhone();
		if ( m_input.GetSize() > 0 )
			randIndex = rand() % m_input.GetSize();
		else
			randIndex = 0;
	}

    updateTitle();
}

void CRandomPhoneDlg::OnStop() 
{
	// TODO: Add your control notification handler code here
    CButton * pstart, *pstop;

	pstart = (CButton*) GetDlgItem(IDC_START);
	pstop   = (CButton*) GetDlgItem(IDC_STOP);

	pstart->EnableWindow ( TRUE );
	pstop ->EnableWindow ( FALSE );
	pstart->SetFocus();
	
	UINT a;
	a = pstart->GetButtonStyle();
	a = a & ( 0xffffffff | BS_DEFPUSHBUTTON );
	pstart->SetButtonStyle(a);

	a = pstop->GetButtonStyle();
	a = a & ( 0xffffffff ^ BS_DEFPUSHBUTTON );
	pstop->SetButtonStyle(a);
	
	m_bSelect = FALSE;
}


void CRandomPhoneDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CString s;
	int index;
	int dindex =0;
	int ii = 0;

	index = m_Grid.GetFocusCell().row;
	dindex = atol(m_Grid.GetItemText(index,0) );

	dindex = dindex - 1;
    if ( dindex >= 0 && dindex < m_output.GetSize() )
	{
		unsigned int selectPhone;
		unsigned int selectCity;
		COutputItem *pp;
		pp = m_output.At(dindex);
		if ( pp == NULL )
			return;
		
		selectPhone = pp->phone;
		selectCity  = pp->city;

		CString p,c,l,temp;

		temp.Format("%d",selectPhone);
		m_hlr.GetHlr( temp,p,c,l);

		s.Format("确实要删除\"第%d名 13%d %s(%s)\"用户吗?",dindex+1, selectPhone,c,l);
	    if ( AfxMessageBox(s,MB_YESNO) == IDYES )
		{        
 		    m_input.Add( selectCity,selectPhone );

		    m_output.Del(dindex);
			m_Grid.DeleteRow( index );
			m_Grid.AutoSize();
		    //m_outputlist.DeleteString ( index );

            //----------
 	        for ( int i= 0 ;i < m_Grid.GetRowCount(); i++)
			{
				  ii = atol(m_Grid.GetItemText(i+1,0) );
				  ii = ii - 1; // ii 是被删除的记录
				  if ( ii >= dindex )
				  {
					  s.Format("%d",ii);
					  m_Grid.SetItemText(i+1,0,s);
				  }
			}
		}
	}	

	updateTitle();
}

void CRandomPhoneDlg::updateTitle()
{
	CString s;

	//----------
	s.Format("随机号码(%d个数据)",m_input.GetSize());
	SetDlgItemText(IDC_RANDOMSHOW,s);
	
	//----------
	s.Format("中奖号码(%d个数据)",m_output.GetSize());
    SetDlgItemText(IDC_BONUS,s);

	//----------
	if ( m_input.GetSize() > 0 )
	{
		if ( m_lastSelectPhone == 0  )
		{
			if ( m_input.At(0) != NULL )
			{
		        s.Format("13%d",m_input.At(0)->phone);
			}
			else
			{
				s = "";
			}
		}
		else
		{
			s.Format("13%d", m_lastSelectPhone );
		}
		//SetDlgItemText(IDC_RANDOM,s);
		m_random.SetWindowText(s);
	}
	else
	{
        //SetDlgItemText(IDC_RANDOM,"");
		m_random.SetWindowText("");
	}    
}



void CRandomPhoneDlg::OnMenuoutput() 
{
    CFileDialog dlg(FALSE,"txt",
		            NULL,
					OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		            "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|");

	if ( dlg.DoModal() != IDOK  )
	{
		return;
	}
    CString temp;
    CStdioFile f1;
    if( !f1.Open( dlg.GetPathName(), CFile::modeCreate | CFile::modeWrite | CFile::typeText ) ) 
	{
		temp.Format("%s文件创建失败",dlg.GetPathName());
		AfxMessageBox(temp);
        return;
	}

	for ( int i = 0; i < m_Grid.GetRowCount(); i ++ )
	{
	    temp.Format("%s\t%s\t%s\t%s\n",
			        m_Grid.GetItemText(i+1,0),
					m_Grid.GetItemText(i+1,1),
					m_Grid.GetItemText(i+1,2),
					m_Grid.GetItemText(i+1,3));

	    f1.WriteString(temp);
	}	
}

void CRandomPhoneDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	
	//CDialog::OnClose();
	EndDialog(0);
}

#include "Option1.h"
void CRandomPhoneDlg::OnMenuitem32776() 
{
	// TODO: Add your command handler code here
	COption1 dlg;
	dlg.m_genonce = m_genonce;
	if ( dlg.DoModal() == IDOK )
	{
        UpdateData(TRUE);

		m_genonce = dlg.m_genonce;
	}
}

void CRandomPhoneDlg::RandomPhone()
{
	m_random.SetTextColor( RGB(0,0,255) );

	MSG msg;
    CString s;
	unsigned int i = randIndex;
	while ( m_bSelect )
	{
            i = rand() % m_input.GetSize();

            if(PeekMessage(&msg, 0, NULL, NULL, PM_REMOVE))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
                if(msg.message ==WM_QUIT)
                {
                    //WSASetLastError(WSAETIMEOUT);
                    goto output;
                }
            }

			//-----------------------------------------------------------------
            i += rand() % 5;
			Sleep(rand()% 5);
		
			if ( i>= ((unsigned int )m_input.GetSize()) )
			{
			    i = 0;
			}

			CInputItem * p;
			p = m_input.At( i );
			if ( p!= NULL )
			{
			    s.Format("13%d", p->phone );
   			    m_random.SetWindowText(s);
			}
			//-----------------------------------------------------------------

		i ++;
		if ( i>= ((unsigned int )m_input.GetSize()) )
		{
			i = 0;
		}
	}

	m_random.SetTextColor( RGB(255,0,0) );
output:
    randIndex = i;
}

void CRandomPhoneDlg::AddOnePhone()
{
	CString s;

	CInputItem *pp = NULL;
	pp = m_input.At( randIndex );
	if ( pp == NULL )
		return ;

	unsigned int phone;
	unsigned int city;
	phone = pp->phone;
	city  = pp->city;

	m_lastSelectPhone = phone;
    m_uSelectPhone = m_lastSelectPhone;
	m_output.Add(city,phone);
	m_input.Del(randIndex);
 
	CString p,c,l;
	if ( m_input.m_fileformat == 1 )
	{
		s.Format("%d",phone);
	    m_hlr.GetHlr( s,p,c,l);
	}
	else
	{
		s.Format("%d",city);
		m_hlrCode.GetHlrCode(s,c,l);
		p = "";
	}

    s.Format("%d",m_output.GetSize());
	m_Grid.InsertRow(_T(s), -1);	
    
	DWORD dwTextStyle = DT_RIGHT|DT_VCENTER|DT_SINGLELINE;
#ifndef _WIN32_WCE
    dwTextStyle |= DT_END_ELLIPSIS;
#endif

    GV_ITEM Item;

	//-------- phone ------------
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.row = m_output.GetSize();
	Item.col = 1;

	Item.nFormat = dwTextStyle;
	s.Format("13%d",m_uSelectPhone);
	Item.szText.Format(_T("%s"),s);
	m_Grid.SetItem(&Item);

	//-------- city ------------
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.row = m_output.GetSize();
	Item.col = 2;

	Item.nFormat = dwTextStyle;
	s.Format("%s",c);
	Item.szText.Format(_T("%s"),s);
	m_Grid.SetItem(&Item);

	//-------- long-code ------------
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.row = m_output.GetSize();
	Item.col = 3;

	Item.nFormat = dwTextStyle;
	s.Format("%s",l);
	Item.szText.Format(_T("%s"),s);
	m_Grid.SetItem(&Item);

	//------------------------------
	m_Grid.Invalidate();
	m_Grid.AutoSize();
}

#include "Option2.h"
void CRandomPhoneDlg::OnMenuitemfileFormat() 
{
	// TODO: Add your command handler code here
	COption2 dlg;
	
	dlg.SetOption(m_fileformat);

	if ( dlg.DoModal() == IDOK )
	{
		m_fileformat = dlg.GetOption();
	}
}

void CRandomPhoneDlg::OnMenuitemaboutbox() 
{
	// TODO: Add your command handler code here
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();	
}

⌨️ 快捷键说明

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