📄 playerhistorydlg.cpp
字号:
// PlayerHistoryDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Snake.h"
#include "PlayerHistoryDlg.h"
#include "SnakeView.h"
#include "SnakeModel.h"
#include "wcedb.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CCeDBDatabase m_DBPlayer;
extern CCeDBProp m_pSortProp[2];
extern const WORD PROP_NAME=100,
PROP_SCORE=101;
/////////////////////////////////////////////////////////////////////////////
// CPlayerHistoryDlg dialog
CPlayerHistoryDlg::CPlayerHistoryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPlayerHistoryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPlayerHistoryDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_name=_T("");
m_score=0;
}
void CPlayerHistoryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPlayerHistoryDlg)
DDX_Control(pDX, IDC_LIST_PLAYER, m_ListHistory);
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPlayerHistoryDlg, CDialog)
//{{AFX_MSG_MAP(CPlayerHistoryDlg)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPlayerHistoryDlg message handlers
BOOL CPlayerHistoryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_ListHistory.InsertColumn(0,_T("Name"),LVCFMT_LEFT,100,-1);
m_ListHistory.InsertColumn(1,_T("Score"),LVCFMT_LEFT,100,-1);
//填充列表控制:
TCHAR a[20];
if(!(m_DBPlayer.SeekFirst()))
{
return true;
}
m_DBPlayer.m_bAutoSeekNext=true;
while(!m_DBPlayer.m_bEOF)
{
for(int iItem=0;iItem<m_DBPlayer.GetNumRecords();iItem++)
{
ReadRecord();
m_ListHistory.InsertItem(iItem,(LPCTSTR)m_name);
wsprintf(a,_T("%d"),m_score);
m_ListHistory.SetItemText(iItem,1,a);
}
}
m_DBPlayer.m_bAutoSeekNext=false;
m_DBPlayer.SeekFirst();
return TRUE;
}
void CPlayerHistoryDlg::ReadRecord()
{
CString str;
CCeDBRecord m_DBRecord;
CCeDBProp* m_pValProperty[2];
if(!m_DBPlayer.ReadCurrRecord(&m_DBRecord))
{
AfxMessageBox(_T("Cann't read current record!"));
return;
}
m_pValProperty[0]=m_DBRecord.GetPropFromIdent(100);
m_pValProperty[1]=m_DBRecord.GetPropFromIdent(101);
m_name = m_pValProperty[0]->GetString();
m_score= m_pValProperty[1]->GetULong();
}
void CPlayerHistoryDlg::OnButtonDelete()
{
// TODO: Add your control notification handler code here
m_DBPlayer.Delete();
m_pSortProp[0]=CCeDBProp(CCeDBProp::Type_String,PROP_NAME, CCeDBProp::Sort_Descending);
m_pSortProp[1]=CCeDBProp(CCeDBProp::Type_ULong ,PROP_SCORE,CCeDBProp::Sort_Descending);
//打开游戏数据库:
if(!CCeDBDatabase::Exists(_T("\\Snake_Player.cd")))
{
m_DBPlayer.Create(_T("\\Snake_Player.cd"),19830213,2,m_pSortProp);
}
if(!m_DBPlayer.Open(_T("\\Snake_Player.cd"),&m_pSortProp[1],NULL))
if(AfxMessageBox(_T("open database error,\ncontinue?"),MB_YESNO)==IDNO)
SendMessage(WM_QUIT);
SendMessage(WM_CLOSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -