MFC学习笔记一 对话框程序编程
MFC学习笔记一 对话框程序编程
#include "StdAfx.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#include "Dictsearch.h"
//////////////////////////////////////
// global funcitions
///////////////////////////////////////
int CompareItem( const void *arg1, const void *arg2 )
{
CDictItem *pItem;
char *pTmp;
pTmp = (char *)arg1;
pItem = ( CDictItem *)arg2;
return strcmp( pTmp, pItem->GetKeyword() );
}
int SortItem( const void *arg1, const void *arg2 )
{
CDictItem* pItem1;
CDictItem* pItem2;
pItem1 = (CDictItem *)arg1 ;
pItem2 = (CDictItem *)arg2 ;
return strcmp(pItem1->GetKeyword(), pItem2->GetKeyword());
}
//////////////////////////////////////
// class Implementation : CDictItem
///////////////////////////////////////
char* CDictItem::GetKeyword()
{
return m_psKeyWord;
}
void CDictItem::SetTrans(char* psTransLine)
{
char* psTmp;
psTmp=psTransLine;
m_nTransNum=1;
while ( *psTmp != 0 ){
if ( *psTmp == '@' )
m_nTransNum++;
psTmp++;
}
m_psTrans=new char*[m_nTransNum];
memset(m_psTrans,0,sizeof(char*)*m_nTransNum);
int nNo;
nNo=0;
psTmp=strtok(psTransLine,"@");
while( psTmp != NULL ){
m_psTrans[nNo]=new char[strlen(psTmp)+1];
strcpy(m_psTrans[nNo++],psTmp);
psTmp=strtok(NULL,"@");
}
}
void CDictItem::SetKeyword(char* psKeyword)
{
if ( m_psKeyWord != NULL )
delete m_psKeyWord;
m_psKeyWord=new char[strlen(psKeyword)+1];
strcpy(m_psKeyWord,psKeyword);
}
bool CDictItem::SetDictItem(char* psKeyword,char* psTransLine)
{
if ( psKeyword == NULL || psTransLine == NULL )
return false;
SetKeyword(psKeyword);
SetTrans(psTransLine);
return true;
}
CDictItem::CDictItem()
{
m_psKeyWord=NULL;
m_psTrans=NULL;
m_nTransNum=0;
}
CDictItem::~CDictItem()
{
FreeDictItem();
}
void CDictItem::FreeDictItem()
{
if ( m_psKeyWord != NULL ){
delete m_psKeyWord;
m_psKeyWord=NULL;
}
if ( m_psTrans != NULL ){
for ( int i=0;iDictSearch(psKeyword,pDictItem) ){
return true;
}
}
if ( m_pDictItem == NULL )
return false;
pDictItem=(CDictItem *)bsearch( psKeyword, m_pDictItem, m_nDictItemNum, sizeof(CDictItem), CompareItem);
if ( pDictItem == NULL )
return false;
return true;
}
void CDictSearch::DictSearchExit()
{
FreeDictSearch();
if ( m_pUserDictSearch != NULL ){
m_pUserDictSearch->DictSearchExit();
delete m_pUserDictSearch;
m_pUserDictSearch=NULL;
}
}
CDictSearch::CDictSearch()
{
m_pDictItem=NULL;
m_nDictItemNum=0;
m_pUserDictSearch=NULL;
}
CDictSearch::~CDictSearch()
{
FreeDictSearch();
}
void CDictSearch::FreeDictSearch()
{
if ( m_pDictItem != NULL ){
for ( int i=0;iDictSearchInit(psUserDict) ){
DictSearchExit();
return false;
}
}
return true;
};
0 评论 :
发表评论