wordlist.cpp

来自「一个用ODBC访问Access的实例」· C++ 代码 · 共 103 行

CPP
103
字号
// WordList.cpp : implementation file
//

#include "stdafx.h"
#include "vocabulory.h"
#include "WordList.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWordList dialog


CWordList::CWordList(CWnd* pParent /*=NULL*/)
	: CDialog(CWordList::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWordList)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CWordList::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWordList)
	DDX_Control(pDX, IDC_LIST1, m_List);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWordList, CDialog)
	//{{AFX_MSG_MAP(CWordList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWordList message handlers
BOOL CWordList::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_List.InsertColumn(0,"英文");
	m_List.InsertColumn(1,"中文");
	m_List.InsertColumn(2,"备注");
	RECT rect;
	m_List.GetWindowRect(&rect);
	int wid=rect.right-rect.left;
	m_List.SetColumnWidth(0,3*wid/10);
	m_List.SetColumnWidth(1,3*wid/10);
	m_List.SetColumnWidth(2,4*wid/10);
	m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	if(wordset.IsOpen())
	{
		wordset.Close();
	}
	UpdateData(true);
	CString sqlStr;
	sqlStr="SELECT * FROM VOCABULORY";
	if(!wordset.Open(AFX_DB_USE_DEFAULT_TYPE,sqlStr))
	{
		MessageBox("单词表打开失败!");
	}
	DisplayRecord();
	return TRUE;
}

bool CWordList::DisplayRecord()
{
	CString Eword;
	CString Cword;
	CString Addition;
	int i=0;
		
	while(!wordset.IsEOF())
	{
		Eword = wordset.m_Eword;
		Cword = wordset.m_Cword;
		Addition = wordset.m_Addition;
//		AfxMessageBox(Eword+Cword+Addition);
		m_List.InsertItem(i,Eword);
		m_List.SetItemText(i,1,Cword);
		m_List.SetItemText(i,2,Addition);
		wordset.MoveNext();
		i++;
	}
	UpdateData(false);
	return true;
}

void CWordList::OnCancel() 
{
	// TODO: Add extra cleanup here
	if(wordset.IsOpen())
	{
		wordset.Close();
	}
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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