gusucode.com > 连连看游戏VC++源代码-源码程序 > 连连看游戏VC++源代码-源码程序\code\RecordDlg.cpp
// RecordDlg.cpp : implementation file // Download by http://www.NewXing.com /* Made by zhouyuhui in 2005.8.25 mail: xuchangyuhui@sohu.com It was made for my girl friend. Thank for your download. 2006.09.09 */ #include "stdafx.h" #include "ZLLK.h" #include "RecordDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRecordDlg dialog CRecordDlg::CRecordDlg(CWnd* pParent /*=NULL*/) : CDialog(CRecordDlg::IDD, pParent) { //{{AFX_DATA_INIT(CRecordDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CRecordDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRecordDlg) DDX_Control(pDX, IDC_LIST_USER, m_list); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CRecordDlg, CDialog) //{{AFX_MSG_MAP(CRecordDlg) ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRecordDlg message handlers void CRecordDlg::OnOK() { // TODO: Add extra validation here CDialog::OnOK(); } void CRecordDlg::OnButtonClear() { // TODO: Add your control notification handler code here if(AfxMessageBox("确定删除历史纪录",MB_OKCANCEL)==IDOK) { m_list.DeleteAllItems(); //清除文件纪录(重新创建一个同名文件) CFile mFile; CFileException mExcept; mFile.Open("user.txt",CFile::modeCreate,&mExcept); } } BOOL CRecordDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_list.InsertColumn(0,"",LVCFMT_LEFT,30); m_list.InsertColumn(1,"分数",LVCFMT_LEFT,50); m_list.InsertColumn(2,"姓名",LVCFMT_LEFT,60); m_list.InsertColumn(3,"级别",LVCFMT_LEFT,50); m_list.InsertColumn(4,"关卡",LVCFMT_LEFT,50); //给列表加上表格 LONG lStyle = m_list.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE); lStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |LVS_EX_HEADERDRAGDROP; m_list.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0,(LPARAM)lStyle); ReadRecord(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CRecordDlg::ReadRecord() { //读出纪录 CStdioFile mFile; CFileException mExcept; CString readstr; CString IDstr; int i=0; if(!mFile.Open("user.txt",CFile::modeRead,&mExcept)) mFile.Open("user.txt",CFile::modeCreate|CFile::modeRead,&mExcept); while(mFile.ReadString(readstr)) { IDstr.Format("%d",(i+1)); m_list.InsertItem(i,IDstr); m_list.SetItemText(i,1,readstr); mFile.ReadString(readstr); m_list.SetItemText(i,2,readstr); mFile.ReadString(readstr); m_list.SetItemText(i,3,readstr); mFile.ReadString(readstr); m_list.SetItemText(i,4,readstr); i++; } }