www.pudn.com > TibetanWordManage.rar > TibetanWordManageDlg.cpp


// TibetanWordManageDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "TibetanWordManage.h" 
#include "TibetanWordManageDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CTibetanWordManageDlg dialog 
 
UINT  FindProcess(LPVOID lpViod); 
UINT  BrowseProcess(LPVOID lpViod); 
UINT  LoadProcess(LPVOID lpViod); 
UINT  OutProcess(LPVOID lpViod); 
 
 
CTibetanWordManageDlg::CTibetanWordManageDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CTibetanWordManageDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CTibetanWordManageDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
	Flag = FALSE; 
	bMDB = FALSE; 
} 
 
void CTibetanWordManageDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CTibetanWordManageDlg) 
	DDX_Control(pDX, IDC_STATIC_TWO, m_T2); 
	DDX_Control(pDX, IDC_STATIC_ONE, m_T1); 
	DDX_Control(pDX, IDC_STATIC_LINE2, m_Line2); 
	DDX_Control(pDX, IDC_STATIC_LINE1, m_Line1); 
	DDX_Control(pDX, IDC_STATIC_HINT, m_Hint); 
	DDX_Control(pDX, IDC_PROGRESS, m_Prog); 
	DDX_Control(pDX, IDC_LIST, m_List); 
	DDX_Control(pDX, IDC_EDIT_INPUT, m_EditInput); 
	DDX_Control(pDX, IDC_EDIT, m_EditOut); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CTibetanWordManageDlg, CDialog) 
	//{{AFX_MSG_MAP(CTibetanWordManageDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_WM_CREATE() 
	ON_WM_SIZE() 
	ON_WM_DESTROY() 
	ON_BN_CLICKED(ID_WORD_ADD,  OnAddWord) 
	ON_BN_CLICKED(ID_WORD_SAVE, OnSaveWord) 
	ON_BN_CLICKED(ID_WORD_FIND, OnFindWord) 
	ON_BN_CLICKED(ID_WORD_BROSWER, OnBroswerWord) 
	ON_BN_CLICKED(ID_WORD_DELETE,  OnDeleteWord) 
	ON_BN_CLICKED(IDM_INIT, OnInit) 
	ON_BN_CLICKED(ID_WORD_LOAD, OnLoad) 
	ON_BN_CLICKED(ID_WORD_OUTPUT, OnOutput) 
	ON_BN_CLICKED(ID_MYHELP, OnMyHelp) 
	ON_BN_CLICKED(IDM_ABOUT, OnMyHelp) 
	ON_BN_CLICKED(IDM_EXIT, OnExit) 
	ON_LBN_DBLCLK(IDC_LIST, OnDblclkList) 
	ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList) 
	 
	 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CTibetanWordManageDlg message handlers 
 
BOOL CTibetanWordManageDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// 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 
	Flag = TRUE; 
 
	//菜单	 
	m_Menu.LoadMenu(IDR_MENU); 
	SetMenu(&m_Menu); 
	m_Menu.Detach();		 
 
	ChangeSize(); 
 
 
	//设置字体 
	NONCLIENTMETRICS ncm; 
	ncm.cbSize = sizeof(NONCLIENTMETRICS); 
	SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0); 
	ncm.lfStatusFont.lfCharSet = DEFAULT_CHARSET; 
	ncm.lfStatusFont.lfHeight = 16;	 
	lstrcpy(ncm.lfStatusFont.lfFaceName, "宋体"); 
	m_TibetFont.CreateFontIndirect(&ncm.lfStatusFont);  
	 
	m_EditInput.SetFont(&m_TibetFont, TRUE); 
	m_List.SetFont(&m_TibetFont, TRUE); 
	m_EditOut.SetFont(&m_TibetFont, TRUE); 
	 
	m_Tip.Create(this); 
	m_Tip.AddTool(GetDlgItem(IDC_EDIT_INPUT), _T("请输入词汇,可以支持三种查询!"), NULL); 
//	m_Tip.AddTool(GetDlgItem(IDC_LIST), _T("藏文词条列表!"), NULL); 
//	m_Tip.AddTool(GetDlgItem(IDC_EDIT), _T("藏文解释输入、显示框!"), NULL); 
 
 
	TCHAR szFile[255] = {'\0'}; 
	GetModuleFileName(NULL, szFile, 255); 
	CString strPath(szFile); 
	int pos = strPath.ReverseFind('\\');  
	strPath = strPath.Left(pos+1);  
	strMDB  = strPath + CString("TibetWord.dat"); 
 
	CFileFind ff; 
	bMDB = ff.FindFile((LPCTSTR)strMDB, 0) ; 
	ff.Close(); 
 
 
	if( bMDB == FALSE) 
	{ 
		AfxMessageBox("没有找到数据源,需要初始化!"); 
	} 
	 
	strTable = CString("TIBETTABLE"); 
 
	ParamInfor.pProg = &m_Prog; 
	ParamInfor.pHint =  &m_Hint; 
	ParamInfor.lpString = NULL; 
	ParamInfor.pList = &m_List; 
	ParamInfor.pEdit = &m_EditOut; 
	ParamInfor.Flag  = 0; 
 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// 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 CTibetanWordManageDlg::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 CTibetanWordManageDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
 
 
//创建自己的工具栏 
BOOL CTibetanWordManageDlg::CreateExToolBar() 
{ 
 
	if(!m_wndReBar.Create(this))	return -1; 
	 
	if (!m_wndToolBar.CreateEx(this, WS_CHILD | TBSTYLE_FLAT ))//, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE| CBRS_TOP 
		//| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC)) 
	{ 
		return -1;       
	} 
	 
	//下面的代码是设置按钮的宽度和长度 
	m_wndToolBar.GetToolBarCtrl().SetButtonWidth(55, 55); 
 
	//下面的代码是设置"热"的位图 
	img.Create(30, 30, ILC_COLOR8|ILC_MASK, 2, 2); 
	img.SetBkColor(::GetSysColor(COLOR_BTNFACE)); 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_ADD));		//	0	添加新词 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_SAVE));		//	1	保存词条 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON1));			//  2 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_FIND));		//	3	选择查询 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_BROSWER));	//	4	浏览 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_DELETE));	//	5	删除 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON1));			//	6 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_LOAD));		//	7	导入 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_OUTPUT));	//	8	导出 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON1));			//	9	 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_HELP));		//	10	帮助 
	m_wndToolBar.GetToolBarCtrl().SetHotImageList (&img); //热的调用 
	img.Detach();	 
	 
	//下面的代码是设置"冷"的位图 
	img.Create(28, 28, ILC_COLOR8|ILC_MASK, 2, 2); 
	img.SetBkColor(::GetSysColor(COLOR_BTNFACE)); 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_ADD));		//	0	添加新词 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_SAVE));		//	1	保存词条 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON1));			//  2 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_FIND));		//	3	选择查询 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_BROSWER));	//	4	浏览 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_DELETE));	//	5	删除 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON1));			//	6 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_LOAD));		//	7	导入 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_OUTPUT));	//	8	导出 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON1));			//	9	 
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_HELP));		//	10	帮助 
	m_wndToolBar.GetToolBarCtrl().SetImageList(&img); 
	img.Detach(); 
 
	 
	//改变属性 
	m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT |CBRS_TOOLTIPS | TBSTYLE_TRANSPARENT|TBBS_CHECKBOX ); 
	m_wndToolBar.SetButtons(NULL,11); // 设置工具栏个数	 
 
	m_wndToolBar.SetButtonInfo(0, ID_WORD_ADD, TBSTYLE_BUTTON, 0); 
	m_wndToolBar.SetButtonText(0, "添加新词");	 
	m_wndToolBar.SetButtonInfo(1, ID_WORD_SAVE, TBSTYLE_BUTTON, 1); 
	m_wndToolBar.SetButtonText(1, "保存词条"); 
	 
	m_wndToolBar.SetButtonInfo(2, 0, TBBS_SEPARATOR, 2); 
 
	m_wndToolBar.SetButtonInfo(3, ID_WORD_FIND, TBSTYLE_BUTTON, 3); 
	m_wndToolBar.SetButtonText(3, "查询词条"); 
	m_wndToolBar.SetButtonInfo(4, ID_WORD_BROSWER, TBSTYLE_BUTTON, 4); 
	m_wndToolBar.SetButtonText(4, "浏览词条"); 
	m_wndToolBar.SetButtonInfo(5, ID_WORD_DELETE, TBSTYLE_BUTTON, 5); 
	m_wndToolBar.SetButtonText(5, "删除词条"); 
 
	m_wndToolBar.SetButtonInfo(6, 0, TBBS_SEPARATOR, 6); 
 
	m_wndToolBar.SetButtonInfo(7, ID_WORD_LOAD, TBSTYLE_BUTTON, 7); 
	m_wndToolBar.SetButtonText(7, "导入词条"); 
	m_wndToolBar.SetButtonInfo(8, ID_WORD_OUTPUT, TBSTYLE_BUTTON, 8); 
	m_wndToolBar.SetButtonText(8, "导出词条"); 
 
	m_wndToolBar.SetButtonInfo(9, 0, TBBS_SEPARATOR, 9); 
 
	m_wndToolBar.SetButtonInfo(10, ID_MYHELP, TBSTYLE_BUTTON, 10); 
	m_wndToolBar.SetButtonText(10, "关于"); 
 
	 
	CRect rectToolBar; 
	//得到按钮的大小 
	m_wndToolBar.GetItemRect(0, &rectToolBar); 
	//设置按钮的大小 
	m_wndToolBar.SetSizes(rectToolBar.Size(), CSize(30, 30)); 
	//在Rebar中加入ToolBar 
	m_wndReBar.AddBar(&m_wndToolBar); 
 
 
 	RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); 
	//改变一些属性 
 
	return TRUE; 
} 
 
int CTibetanWordManageDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CDialog::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	// TODO: Add your specialized creation code here 
	CreateExToolBar(); 
	return 0; 
} 
 
BOOL CTibetanWordManageDlg::PreTranslateMessage(MSG* pMsg)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	m_Tip.RelayEvent(pMsg);	 
	return CDialog::PreTranslateMessage(pMsg); 
} 
 
 
 
void CTibetanWordManageDlg::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
	 
	// TODO: Add your message handler code here 
	m_Menu.DestroyMenu(); 
	m_TibetFont.DeleteObject(); 
} 
 
 
void CTibetanWordManageDlg::OnSize(UINT nType, int cx, int cy)  
{ 
	CDialog::OnSize(nType, cx, cy); 
	 
	// TODO: Add your message handler code here 
	if(Flag == FALSE ) return ; 
	ChangeSize(); 
} 
 
//帮助函数 
void  CTibetanWordManageDlg::OnMyHelp() 
{ 
	CQkyAboutDlg  dlg; 
	dlg.DoModal();  
} 
 
//退出函数 
void  CTibetanWordManageDlg::OnExit() 
{ 
	SendMessage(WM_CLOSE,0,0); 
} 
//改变窗口大小 
BOOL  CTibetanWordManageDlg::ChangeSize() 
{ 
	CRect rt; 
  	this->GetClientRect (&rt); 
	m_Line1.MoveWindow(0, rt.top+50, rt.right, 2, TRUE);  
	m_Line2.MoveWindow(0, rt.top+90, rt.right, 2, TRUE);  
	m_List.MoveWindow(0, rt.top+100, rt.right/4, rt.bottom-120 , TRUE);  
	m_EditOut.MoveWindow(rt.right/4+5, rt.top+100, (rt.right-rt.right/4)-5, rt.bottom-120 , TRUE);  
	m_T1.MoveWindow(2, rt.bottom -20, 40, 20, TRUE); 
	m_Hint.MoveWindow(42, rt.bottom -20, rt.right/2-50,  20, TRUE); 
	m_T2.MoveWindow(rt.right/2-5, rt.bottom -20, 40,20, TRUE); 
	m_Prog.MoveWindow(rt.right/2+36, rt.bottom -20, rt.right/2-40, 20, TRUE); 
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); 
	return TRUE; 
} 
 
 
//初始化数据源 
void  CTibetanWordManageDlg::OnInit() 
{ 
 
	int  Ret = AfxMessageBox("是否真的初始化?", MB_YESNO|MB_ICONQUESTION); 
	if(Ret == IDNO) return ; 
 
	HINSTANCE hInst = ::AfxGetResourceHandle();	//获取资源句柄 
	HRSRC  hRsrc = ::FindResource(hInst,MAKEINTRESOURCE(IDR_MDB),"MDB");  
	ASSERT(hRsrc);		//特殊调试 
	if(hRsrc == NULL)   //如果不成功 
	{ 
		MessageBox(_T("获取资源句柄错,安装失败!"), _T("句柄"), MB_OK); 
		return; 
	} 
	DWORD  len   = SizeofResource(hInst, hRsrc);		//获取资源中长度 
	BYTE * pRsre = (BYTE*) LoadResource(hInst, hRsrc); //获取文件指针 
	ASSERT(pRsre);  
 
	CFile file; 
	if( !file.Open((LPCTSTR) strMDB,  CFile::modeCreate|CFile::modeWrite)) 
		return ; 
	file.WriteHuge((void*) pRsre, len); 
	file.Close();  
	bMDB = TRUE; 
	AfxMessageBox("初始化完成!"); 
} 
 
 
//双击列表框 
void CTibetanWordManageDlg::OnDblclkList()  
{ 
	if( bMDB == FALSE) 
	{AfxMessageBox("没有找到数据源,需要初始化!"); } 
 
	int nIndex = m_List.GetCurSel(); 
	int nCount = m_List.GetCount(); 
	if ((nIndex != LB_ERR) && (nCount != 0)) 
	{ 
		CString strWord; 
		m_List.GetText(nIndex,  strWord ); 
		CQkyAdo ado; 
		if( ado.OpenConnection(strMDB) && 
			ado.OpenRecordset(strTable)) 
		{ 
			CString strExplain; 
			if(ado.FindWord( strWord, strExplain)) 
			{ 
				SetDlgItemText(IDC_EDIT, strExplain); 
				SetDlgItemText(IDC_EDIT_INPUT, strWord); 
			} 
		} 
	} 
} 
 
 
void CTibetanWordManageDlg::OnSelchangeList()  
{ 
	int nIndex = m_List.GetCurSel(); 
	int nCount = m_List.GetCount(); 
	if ((nIndex != LB_ERR) && (nCount != 0)) 
	{ 
		CString strWord; 
		m_List.GetText(nIndex,  strWord ); 
		SetDlgItemText(IDC_EDIT_INPUT, strWord); 
	} 
} 
 
 
 
 
//输入新词 
void  CTibetanWordManageDlg::OnAddWord() 
{ 
	if( bMDB == FALSE) 
	{AfxMessageBox("没有找到数据源,需要初始化!"); } 
 
	SetDlgItemText(IDC_EDIT_INPUT, ""); 
	SetDlgItemText(IDC_EDIT, ""); 
} 
 
//保存新词 
void  CTibetanWordManageDlg::OnSaveWord() 
{ 
	if( bMDB == FALSE) 
	{AfxMessageBox("没有找到数据源,需要初始化!"); } 
 
	CString strIn, strOut; 
	GetDlgItemText(IDC_EDIT_INPUT, strIn); 
	GetDlgItemText(IDC_EDIT, strOut); 
	if( strIn.IsEmpty()) 
	{ 
		AfxMessageBox("请输入藏文词汇!"); 
		return ; 
	} 
	if( strOut.IsEmpty()) 
	{ 
		AfxMessageBox("请输入解释项内容!"); 
		return ; 
	} 
	CQkyAdo ado; 
	long pos = 0; 
	if( ado.OpenConnection(strMDB) && 
	    ado.OpenRecordset(strTable)) 
	{ 
		pos = ado.FindItem(strIn); 
		if( pos == -1) 
		{ 
			ado.AddNew(); 
			ado.SetValue(CString("TIBETWORD"), strIn); 
			ado.SetValue(CString("EXPLAIN"),   strOut); 
			ado.Update(); 
			m_List.AddString (strIn);		 
		}else 
		{ 
			int  Ret = AfxMessageBox("词条存在是否替换?", MB_YESNO|MB_ICONQUESTION); 
			if(Ret == IDYES) 
			{ 
				ado.EditItem(pos-1); 
				ado.SetValue(CString("TIBETWORD"), strIn); 
				ado.SetValue(CString("EXPLAIN"),   strOut); 
				ado.Update();			 
			} 
		} 
	} 
} 
 
 
 
//查找词汇 
void  CTibetanWordManageDlg::OnFindWord() 
{ 
	if( bMDB == FALSE) 
	{AfxMessageBox("没有找到数据源,需要初始化!"); } 
 
	CString strIn; 
	GetDlgItemText(IDC_EDIT_INPUT, strIn); 
	strIn.TrimLeft(); 
	strIn.TrimRight(); 
	int  iFlag = 0; 
	int len = strIn.GetLength();  
	int pos = strIn.Find("︽"); 
	if( len < 2) 
	{ 
		AfxMessageBox("请输入藏文词!"); 
		return ; 
	} 
	BYTE b = (BYTE) strIn.GetAt(0); 
	if(b < 0x80 ) 
	{ 
		AfxMessageBox("藏文词有错误,请重新输入!"); 
		return ;	 
	} 
	if( len > 64) 
	{ 
		AfxMessageBox("藏文词太长,请重新输入!"); 
		return ; 
	} 
	if( len > 8 && pos == -1 ) 
	{ 
		AfxMessageBox("藏文词有错误,请重新输入!"); 
		return ; 
	} 
	 
	if( len == 2 ) 
		iFlag = 1; 
	else if( len >=2 && len <= 8  && pos == -1) 
		iFlag = 2; 
	else if( len >=3 && pos > 0) 
		iFlag =3; 
	strBuff = strIn; 
	ParamInfor.lpString = (LPCTSTR) strBuff; 
	ParamInfor.Flag = iFlag; 
	// 三种查找方法  
	// 1按基字查找  
	// 2第一个音节查找  
	// 3查找指定的词汇	 
	AfxBeginThread(FindProcess,  &ParamInfor);	 
} 
 
//查找词汇的线程函数 
UINT  FindProcess(LPVOID lpViod) 
{ 
	LPPARAMETER_INFOR pInfor = (PARAMETER_INFOR *)lpViod; 
	TCHAR szFile[255] = {'\0'}; 
	GetModuleFileName(NULL, szFile, 255); 
	CString strPath(szFile); 
	int pos = strPath.ReverseFind('\\');  
	strPath = strPath.Left(pos+1);  
	CString strMDB  = strPath + CString("TibetWord.dat"); 
	CString strTable = CString("TIBETTABLE"); 
 
	CQkyAdo ado; 
	if( ado.OpenConnection(strMDB) && 
	    ado.OpenRecordset(strTable)) 
	{ 
		switch(pInfor->Flag ) 
		{ 
			case 1: 
				{ 
					 
				} 
				break; 
			case 2: 
				{ 
				 
				} 
				break; 
			case 3: 
			{ 
				CString strExplain; 
				if(ado.FindWord( CString(pInfor->lpString), strExplain)) 
					pInfor->pEdit ->SetWindowText((LPCTSTR) strExplain); 		 		 
			} 
			break; 
		} 
	} 
	return 1; 
} 
 
 
 
 
 
 
//浏览词条 
void  CTibetanWordManageDlg::OnBroswerWord() 
{ 
	if( bMDB == FALSE) 
	{AfxMessageBox("没有找到数据源,需要初始化!"); } 
	m_List.ResetContent(); 
	AfxBeginThread(BrowseProcess,  &ParamInfor);	 
} 
//浏览词条的线程函数 
UINT  BrowseProcess(LPVOID lpViod) 
{ 
	LPPARAMETER_INFOR pInfor = (PARAMETER_INFOR *)lpViod; 
	TCHAR szFile[255] = {'\0'}; 
	GetModuleFileName(NULL, szFile, 255); 
	CString strPath(szFile); 
	int pos = strPath.ReverseFind('\\');  
	strPath = strPath.Left(pos+1);  
	CString strMDB  = strPath + CString("TibetWord.dat"); 
	CString strTable = CString("TIBETTABLE"); 
	CQkyAdo ado; 
	if( ado.OpenConnection(strMDB) && 
	    ado.OpenRecordset( strTable)) 
	{ 
		ado.LoadToList( pInfor->pList );	 
	}  
	return 1; 
} 
 
 
//删除词条 
void  CTibetanWordManageDlg::OnDeleteWord() 
{ 
	if( bMDB == FALSE) 
	{AfxMessageBox("没有找到数据源,需要初始化!"); } 
	CString strIn; 
	GetDlgItemText(IDC_EDIT_INPUT, strIn); 
	if(strIn.IsEmpty()) return; 
 
	int  Ret = AfxMessageBox("你要真的删除该词吗?", MB_YESNO|MB_ICONQUESTION); 
	if(Ret == IDNO) return ; 
 
	CQkyAdo ado; 
	if( ado.OpenConnection(strMDB) && 
	    ado.OpenRecordset(strTable)) 
	{ 
		CString strExplain; 
		if(ado.DeleteWord( strIn )) 
		{ 
			SetDlgItemText(IDC_EDIT, ""); 
			SetDlgItemText(IDC_EDIT_INPUT, "");	 
			int nIndex = nIndex= m_List.FindString(nIndex, (LPCTSTR) strIn); 
			if( nIndex  != LB_ERR) 
				m_List.DeleteString( nIndex ); 
		} 
	} 
} 
 
 
 
//导入外部数据 
void  CTibetanWordManageDlg::OnLoad() 
{ 
	if( bMDB == FALSE) 
	{AfxMessageBox("没有找到数据源,需要初始化!"); } 
 
	static char BASED_CODE szFilter[] = "Qikunyu File (*.qky)|*.qky"; 
	CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL); 
	if(dlg.DoModal() == IDCANCEL) return ; 
	strFileName = dlg.GetPathName(); 
	ParamInfor.lpString = (LPCTSTR)strFileName; 
	AfxBeginThread(LoadProcess,  &ParamInfor); 
} 
//导入外部数据的线程函数 
UINT  LoadProcess(LPVOID lpViod) 
{ 
	LPPARAMETER_INFOR pInfor = (PARAMETER_INFOR *)lpViod; 
	CFile  file; 
	if(!file.Open (pInfor->lpString, CFile::modeRead)) 
	{ 
		AfxMessageBox("ERROR"); 
		return 0; 
	} 
 
	long i=0, count=0, len = file.GetLength(); 
	LPTSTR lpBuff = new TCHAR [len ] ; 
	file.Read((void*) lpBuff, sizeof(TCHAR) * len); 
	file.Close(); 
 
	if( (BYTE)*(lpBuff)   != '#' && (BYTE)*(lpBuff+1) != '#' ) 
	{ 
		AfxMessageBox("文件格式错误,不能导入数据!!"); 
		if(lpBuff) delete [] lpBuff; 
	} 
	for(i=2; i 0x80) { i++; continue; } 
           else if( b == 0x23) count++; 
	} 
 
	pInfor->pProg->SetRange32(0, count); 
	pInfor->pProg->SetStep(1); 
	pInfor->pProg->SetPos(0); 
 
 
	TCHAR szFile[255] = {'\0'}; 
	GetModuleFileName(NULL, szFile, 255); 
	CString strPath(szFile); 
	int pos = strPath.ReverseFind('\\');  
	strPath = strPath.Left(pos+1);  
	CString strMDB  = strPath + CString("TibetWord.dat"); 
	CString strTable = CString("TIBETTABLE"); 
 
	CQkyAdo ado; 
	long num = 0; 
	if( ado.OpenConnection( strMDB ) && 
		ado.OpenRecordset( strTable) ) 
	{ 
		num = ado.LoadWord( lpBuff, pInfor->pProg); //返回收录的词条数 
	} 
	if(lpBuff) delete [] lpBuff;	 
	pInfor->pProg->SetPos(0); 
 
	CString strHint; 
	strHint.Format("词条总数%d, 重复%d,  收录%d", count, count-num, num) ; 
	pInfor->pHint->SetWindowText((LPCTSTR) strHint);  
	AfxMessageBox("导入完成!"); 
	return 1; 
} 
 
 
 
 
//导出数据 
void  CTibetanWordManageDlg::OnOutput() 
{ 
	if( bMDB == FALSE) 
	{AfxMessageBox("没有找到数据源,需要初始化!"); } 
 
	static char BASED_CODE szFilter[] = "Qikunyu File (*.qky)|*.qky"; 
	CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL); 
	if(dlg.DoModal() == IDCANCEL) return ; 
	strFileName = dlg.GetPathName(); 
	ParamInfor.lpString = (LPCTSTR)strFileName; 
	AfxBeginThread(OutProcess, &ParamInfor); 
} 
 
 
//导出数据的线程函数 
UINT  OutProcess(LPVOID lpViod) 
{ 
	LPPARAMETER_INFOR pInfor = (PARAMETER_INFOR *)lpViod;	 
	CString strFile( pInfor->lpString); 
	strFile = strFile + CString(".qky"); 
	CFile  file((LPCTSTR)strFile, CFile::modeCreate|CFile::modeWrite); 
	file.Write((void*) "##", sizeof(TCHAR)*2); 
	 
	TCHAR szFile[255] = {'\0'}; 
	GetModuleFileName(NULL, szFile, 255); 
	CString strPath(szFile); 
	int pos = strPath.ReverseFind('\\');  
	strPath = strPath.Left(pos+1);  
	CString strMDB  = strPath + CString("TibetWord.dat"); 
	CString strTable = CString("TIBETTABLE"); 
 
	CQkyAdo ado; 
	if( ado.OpenConnection(strMDB) && 
		ado.OpenRecordset(strTable)) 
	{ 
			//数据库类的应用 
			ado.OutWord( &file, pInfor->pProg); 
	} 
	file.Close();  
	return 1; 
}