?? 6and1dlg.cpp
字號:
// 6and1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "6and1.h"
#include "6and1Dlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMy6and1Dlg dialog
CMy6and1Dlg::CMy6and1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy6and1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy6and1Dlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy6and1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy6and1Dlg)
DDX_Control(pDX, IDC_WINDOW, m_window);
DDX_Control(pDX, IDC_RST_EXTRA, m_rst_extra);
DDX_Control(pDX, IDC_RST_BASIC, m_rst_basic);
DDX_Control(pDX, IDC_TOTAL, m_total);
DDX_Control(pDX, IDC_TITLE, m_title);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy6and1Dlg, CDialog)
//{{AFX_MSG_MAP(CMy6and1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ACTION, OnAction)
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy6and1Dlg message handlers
//分割字符串
int CMy6and1Dlg::SplitString(CString& str,TCHAR cTok,CStringArray& aryItem)
{
TCHAR* p = str.GetBuffer(0);
TCHAR* e = p;
TCHAR cEnd = *e;
int nCount = 0;
while(cEnd)
{
if(*e==_T('\0'))
cEnd=*e;
else if(*e==cTok)
*e= _T('\0');
if(*e)
e++;
else
{
if(*p!=_T('\0'))
{
aryItem.Add(p);
nCount++;
}
p=++e;
}
}
return nCount;
}
BOOL CMy6and1Dlg::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_total.bkColor( RGB(236,5,4) );
//m_total.textColor( RGB(255,255,255) );
//m_total.setFont( -17 );
m_charTemp=' '; //數據分隔符
m_success=false;
m_start=false;
m_save=false;
//讀取配置
m_success=InitConfig();
//主標題
m_strTemp.Format("%s%d+%d兌獎",win_title,num_basic,num_extra);
m_title
.SetFontName("隸書")
.SetFontSize(40)
.SetTextColor(RGB(255,255,255))
.SetFontUnderline(TRUE)
.SetBkColor(RGB(254,0,0))
.SetFontItalic(FALSE)
.SetFontBold(TRUE)
.SetBorder(FALSE)
.SetSunken(FALSE)
.SetText(m_strTemp);
m_strTemp="";
if(m_success)
{
//初始化數據
lottery=new LOTTERY[max_total];
m_success=InitData();
//中獎結果顯示
for(int i=0;i<=num_basic+num_extra;i++)
{
if(i<num_basic)
{
m_strTemp=m_strTemp+" "+rst_basic[i];
}
else
{
if(i==num_basic)
{
m_rst_basic.SetWindowText(m_strTemp);
m_strTemp="";
}
else if(i==num_basic+num_extra)
{
m_rst_extra.SetWindowText(m_strTemp);
}
m_strTemp=m_strTemp+" "+rst_extra[i-num_basic];
}
}
m_strTemp="";
//彩票投注數據顯示
for(int j=0;j<num_total;j++)
{
CString number="";
for(int k=0;k<num_basic+num_extra;k++)
{
number+=" "+lottery[j].number[k];
}
m_strTemp.Format("第%04d注:%s",j+1,number);
int nLength=m_window.SendMessage(WM_GETTEXTLENGTH);
int nStart=nLength;
if(nLength>=30000)
{
nStart=0;
}
m_window.SetSel(nLength, nLength);
m_window.ReplaceSel(m_strTemp+"\n");
}
m_strTemp="";
//總注數
m_strTemp.Format("%d注",num_total);
m_total.SetWindowText(m_strTemp);
m_strTemp="";
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CMy6and1Dlg::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 CMy6and1Dlg::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
{
CPaintDC dc(this); // device context for painting
//Draw the background
CBitmap m_bitmap;
CDC memDC;
memDC.CreateCompatibleDC(&dc);
m_bitmap.LoadBitmap(IDB_MAINBG);
memDC.SelectObject(&m_bitmap);
BITMAP bm;
m_bitmap.GetObject(sizeof(BITMAP), &bm);
dc.BitBlt(0,0,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);
m_bitmap.DeleteObject();
memDC.DeleteDC();
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMy6and1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
bool CMy6and1Dlg::InitConfig()
{
//讀取配置文件
CString FilePath = ".\\config.ini";
CString strValue = _T("");
int lenBuf=128;
char inBuf[128];
//設置
GetPrivateProfileString ("General","title", NULL, inBuf, lenBuf, FilePath); //主標題
win_title=inBuf;
max_total=GetPrivateProfileInt("General","max",512,FilePath); //允許的最大數量
num_basic=GetPrivateProfileInt("General","basic",0,FilePath); //基本號數量
num_extra=GetPrivateProfileInt("General","extra",0,FilePath); //特別號數量
//中獎結果
GetPrivateProfileString ("General","result", NULL, inBuf, lenBuf, FilePath);
CStringArray strList;
strValue=inBuf;
int size=SplitString(strValue,m_charTemp,strList);
if(size!=num_basic+num_extra)
{
MessageBox("配置文件config.ini里基本號/特別號數量設置錯誤,或者開獎結果錯誤!");
return false;
}
for(int i=0;i<size;i++)
{
//截取空格
strList[i].TrimLeft();
strList[i].TrimRight();
//不足2位數字前面補0
while(strList[i].GetLength()<2)
{
strList[i]="0"+strList[i];
}
if(i<num_basic)
{
rst_basic[i]=strList[i];
}
else
{
rst_extra[i-num_basic]=strList[i];
}
}
return true;
}
bool CMy6and1Dlg::InitData()
{
bool flag=true;
//讀取彩票數據///////////////////////////////////////////////////////////////////////////////
FILE *fp=fopen("data.txt","r");
if (fp==NULL)
{
return 0;
}
char buf[128];
int line=0;
while(!feof(fp))
{
//逐行讀取數據存于buf中
char *p=fgets(buf,128,fp);
if (p!=NULL)
{
//允許的最大注數不足
if(line>=max_total)
{
MessageBox("配置文件中max數值比實際數據值小,請重新配置!");
flag=false;
break;
}
CString number=buf;
TRACE("第%d注:%s",number);
number.TrimLeft();
number.TrimRight();
//處理彩票數據//////
CStringArray strList;
int size=SplitString(number,m_charTemp,strList);
if(size!=num_basic+num_extra)
{
m_strTemp.Format("第%d注彩票[%s]無效!",line,number);
//MessageBox(m_strTemp);
flag=false;
break;
}
for(int i=0;i<size;i++)
{
//截取空格
strList[i].TrimLeft();
strList[i].TrimRight();
//不足2位數字前面補0
while(strList[i].GetLength()<2)
{
strList[i]="0"+strList[i];
}
//取投注號
lottery[line].number[i]=strList[i];
}
memset(buf,0,128);
line++;
}
}
fclose(fp);
num_total=line; //投注總數
if(!flag)
{
MessageBox("讀入彩票數據錯誤!");
}
return flag;
}
void CMy6and1Dlg::OnAction()
{
// TODO: Add your control notification handler code here
if(!m_success)
{
MessageBox("程序配置或數據讀取錯誤!");
return;
}
m_window.SetWindowText("");
for(int i=0;i<num_total;i++)
{
int nCount=0;
//匹配基本號
if(i==5)
int test=0;
for(int j=0;j<num_basic+num_extra;j++)
{
for(int k=0;k<num_basic;k++)
{
if(lottery[i].number[j]==rst_basic[k]) { nCount++;break; }
}
}
lottery[i].rst_basic=nCount;
nCount=0;
//匹配特別號
for(int j=0;j<+num_basic+num_extra;j++)
{
for(int k=0;k<num_extra;k++)
{
if(lottery[i].number[j]==rst_extra[k]) { nCount++;break; }
}
}
lottery[i].rst_extra=nCount;
//顯示匹配結果
CString number="";
for(int k=0;k<num_basic+num_extra;k++)
{
number+=" "+lottery[i].number[k];
}
m_strTemp.Format("第%04d注:%s,結果:%d+%d",i+1,number,lottery[i].rst_basic,lottery[i].rst_extra);
int nLength=m_window.SendMessage(WM_GETTEXTLENGTH);
int nStart=nLength;
if(nLength>=30000)
{
nStart=0;
}
m_window.SetSel(nStart, nLength);
m_window.ReplaceSel(m_strTemp+"\n");
}
m_start=true;
}
void CMy6and1Dlg::OnSave()
{
// TODO: Add your control notification handler code here
if(!m_start)
{
MessageBox("請先點擊開始按鈕!");
return;
}
FILE *fp=fopen("結果.xls","a");
if((!feof(fp)))
{
CString writeLine;
//輸出標題
for(int m=0;m<num_basic+num_extra;m++)
{
m_strTemp.Format(" 投注號%d",m+1);
writeLine+=m_strTemp;
}
writeLine+=" 基本號中獎數 特別號中獎數\n";
fputs(writeLine,fp);
//輸出結果
for(int i=0;i<num_total;i++)
{
writeLine="";
for(int j=0;j<num_basic+num_extra;j++)
{
writeLine+=" "+lottery[i].number[j];
}
m_strTemp.Format(" %d %d\n",lottery[i].rst_basic,lottery[i].rst_extra);
writeLine+=m_strTemp;
fputs(writeLine,fp);
}
}
fclose(fp);
}
BOOL CMy6and1Dlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
delete[] lottery;
return CDialog::DestroyWindow();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -