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

📄 randomphonedlg.cpp

📁 手机选中奖号器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// RandomPhoneDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RandomPhone.h"
#include "RandomPhoneDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CRandomPhoneDlg dialog

CRandomPhoneDlg::CRandomPhoneDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRandomPhoneDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRandomPhoneDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_bSelect = FALSE;
	m_genonce  = 1;
	randIndex = 0;
	m_lastSelectPhone = 0;
	m_fileformat = 2	;
}

void CRandomPhoneDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRandomPhoneDlg)
	DDX_Control(pDX, IDC_RANDOM, m_random);
	//}}AFX_DATA_MAP
	DDX_GridControl(pDX, IDC_GRID, m_Grid);
}

BEGIN_MESSAGE_MAP(CRandomPhoneDlg, CDialog)
	//{{AFX_MSG_MAP(CRandomPhoneDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_MENULOAD, OnMenuload)
	ON_COMMAND(ID_MENURESTART, OnMenurestart)
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_COMMAND(ID_MENUOUTPUT, OnMenuoutput)
	ON_COMMAND(IDCLOSE, OnClose)
	ON_COMMAND(ID_MENUITEM32776, OnMenuitem32776)
	ON_COMMAND(ID_MENUITEMFILE_FORMAT, OnMenuitemfileFormat)
	ON_COMMAND(IDC_MENUITEMABOUTBOX, OnMenuitemaboutbox)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRandomPhoneDlg message handlers

BOOL CRandomPhoneDlg::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_hlr.LoadFromFile("hlr.dat");
	m_hlrCode.LoadFromFile("hlrcode.dat");

	//m_random.GetDC()->SetTextColor(RGB(0,255,0));
	m_Font.CreateFont(-50, 0, 0, 0, FW_BOLD, FALSE, FALSE,0,0,0,0,0,0, "Verdana");
	m_gridfont.CreateFont(-15, 0, 0, 0, FW_NORMAL, FALSE, FALSE,0,0,0,0,0,0, "Verdana");

	m_random.SubclassDlgItem(IDC_RANDOM, this);
	m_random.SetFont(&m_Font);
	m_random.SetTextColor( RGB(0,0,255) );
	m_random.SetBkColor( RGB(0,0,0) );

	m_Grid.SetFont(&m_gridfont);
	m_Grid.SetEditable(FALSE);
	m_Grid.SetListMode(FALSE);
	m_Grid.SetTextBkColor(RGB(0xFF, 0xFF, 0xE0));
	m_Grid.SetListMode(TRUE);
	m_Grid.SetHeaderSort(TRUE);

	TRY {
		//id , phone, city, long_code
		m_Grid.SetRowCount(1);
		m_Grid.SetColumnCount(4);
		m_Grid.SetFixedRowCount(1);
		m_Grid.SetFixedColumnCount(1);
	}
	CATCH (CMemoryException, e)
	{
		e->ReportError();
		e->Delete();
		return FALSE;
	}
    END_CATCH

    DWORD dwTextStyle = DT_RIGHT|DT_VCENTER|DT_SINGLELINE;
#ifndef _WIN32_WCE
    dwTextStyle |= DT_END_ELLIPSIS;
#endif

	GV_ITEM Item;

	//序号
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.row = 0;
	Item.col = 0;			
	Item.nFormat = DT_LEFT|DT_WORDBREAK;
	Item.szText.Format(_T("序号"));
	m_Grid.SetItem(&Item);
    m_Grid.SetItemState(0,0, m_Grid.GetItemState(0,0) | GVIS_READONLY);
	m_Grid.AutoSizeColumn(0);

	//手机
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.row = 0;
	Item.col = 1;			
	Item.nFormat = DT_LEFT|DT_WORDBREAK;
	Item.szText.Format(_T("手机"));
	m_Grid.SetItem(&Item);
    m_Grid.SetItemState(0,1, m_Grid.GetItemState(0,1) | GVIS_READONLY);
    m_Grid.SetColumnWidth(1, 50*m_Grid.GetColumnWidth(0)/2);
	m_Grid.AutoSizeColumn(1);

	//地区
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.row = 0;
	Item.col = 2;			
	Item.nFormat = DT_LEFT|DT_WORDBREAK;
	Item.szText.Format(_T("地区"));
	m_Grid.SetItem(&Item);
    m_Grid.SetItemState(0,2, m_Grid.GetItemState(0,2) | GVIS_READONLY);
    m_Grid.SetColumnWidth(2, 4*m_Grid.GetColumnWidth(0)/2);
	m_Grid.AutoSizeColumn(2);

	//区号
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.row = 0;
	Item.col = 3;			
	Item.nFormat = DT_LEFT|DT_WORDBREAK;
	Item.szText.Format(_T("区号"));
	m_Grid.SetItem(&Item);
    m_Grid.SetItemState(0,3, m_Grid.GetItemState(0,3) | GVIS_READONLY);
    m_Grid.SetColumnWidth(3, 3*m_Grid.GetColumnWidth(0)/2);
	m_Grid.AutoSizeColumn(3);

	//------------------------------------
	m_Grid.EnableSelection(FALSE);
	m_Grid.SetRowResize(FALSE);
	m_Grid.SetColumnResize(TRUE);
	m_Grid.SetGridLines(GVL_HORZ);
	m_Grid.SetRowHeight(0, 3*m_Grid.GetRowHeight(0)/2);
	m_Grid.AutoSize();

	m_Grid.AutoSize();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CRandomPhoneDlg::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 CRandomPhoneDlg::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 CRandomPhoneDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

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

	if ( dlg.DoModal() != IDOK  )
	{
		return;
	}
    
	m_input.RemoveAll();
	m_output.RemoveAll();
	
    m_Grid.DeleteNonFixedRows();
	m_Grid.AutoSize();

    CButton * pstart, *pstop;

	pstart = (CButton*) GetDlgItem(IDC_START);
	pstop  = (CButton*) GetDlgItem(IDC_STOP);
	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);

	// TODO: Add your command handler code here
    m_input.LoadFromFile(dlg.GetPathName(), m_fileformat );

	updateTitle();
}

void CRandomPhoneDlg::OnMenurestart() 
{
	// TODO: Add your command handler code here
	if ( AfxMessageBox("确实要重新初始化所有数据吗? 所有数据都将被清除!",MB_YESNO) == IDYES )
	{
        m_input.RemoveAll();
	    m_output.RemoveAll();
		
        m_Grid.DeleteNonFixedRows();
		
		m_Grid.AutoSize();

	    //m_outputlist.ResetContent();
    
        //SetDlgItemText(IDC_RANDOMSHOW,"随机区(0个数据)");
		updateTitle();
	}
}

void CRandomPhoneDlg::OnStart() 
{
	// TODO: Add your control notification handler code here

	if ( m_input.GetSize() <= 0 )
	{
		AfxMessageBox("目前没有数据,无法使用随机选择功能!");
		return ;
	}

	//------------------------------------------------------
    CButton * pstart, *pstop;

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

	pstart->EnableWindow ( FALSE );
	pstop ->EnableWindow ( TRUE );
	pstop->SetFocus();

⌨️ 快捷键说明

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