仿输入法

同学要求帮忙的作业。

作业要求:利用老师提供的词库实现简单的类似输入法的功能。

     可是本人能力有限,只实现了以下简单的功能,界面如下:

操作过程简要介绍:

1、启动程序后,首先“加载词库”

2、第一个编辑框用于输入拼音(还得用 ' 隔开)

3、点击查询在下拉列表中生成与之匹配的汉字

4、下拉列表中选择候选字词,在第二个编辑框中显示

部分代码:

变量声明:

1 typedef struct danciNode{
2 CString pinyin;
3 CString hanzi;
4 struct danciNode *next;
5 }danciNode, LinkList;
6 danciNode *danciku;
7 danciNode *lastEmpty;
8 BOOL FirstFlag = TRUE;

加载词库:

 1 void CShurufaDlg::OnButtonLoad() 
2 {
3 // TODO: Add your control notification handler code here
4 fstream fin;
5 //fin.open("111.txt",ios::in);
6 fin.open("lexicon.dic",ios::in);
7 char line[80];
8 char except[]="";
9 char *ptoken=NULL;
10
11 while(fin.getline(line,80))
12 {
13 ptoken = strtok(line,except);
14 danciNode *danci;
15 danci = new danciNode;
16 danci->next = NULL;
17 while(NULL!=ptoken)
18 {
19 danci->pinyin=ptoken;
20 ptoken = strtok(NULL,except);
21 danci->hanzi=ptoken;
22 ptoken = strtok(NULL,except);
23 }
24 danci->next = danciku->next;
25 danciku->next = danci;
26 }
27 lastEmpty = new danciNode;
28 lastEmpty->pinyin = "pinyin";
29 lastEmpty->hanzi = "拼音";
30 lastEmpty->next = NULL;
31 MessageBox("词库加载完成");
32 }

字词查询:

 1 void CShurufaDlg::OnButtonQuey() 
2 {
3 // TODO: Add your control notification handler code here
4 int i = 0;
5 danciNode *temp;
6 temp = danciku->next;
7 CString strInput;
8 CString strNew;
9 CComboBox* combo=NULL;
10 combo = (CComboBox*)GetDlgItem(IDC_COMBO_CAND);
11 combo->ResetContent();
12 GetDlgItem(IDC_EDIT_INPUT)->GetWindowText(strInput);
13 while (temp->next != NULL)
14 {
15 if (strInput == temp->pinyin)
16 {
17 i++;
18 strNew.Format("%d",i);
19 strNew = temp->hanzi;
20 combo->AddString(strNew);
21 combo->SetCurSel(0);
22 }
23 temp = temp->next;
24 //Sleep(100);
25 }
26 }

候选选择:

 1 void CShurufaDlg::OnSelchangeComboCand() 
2 {
3 // TODO: Add your control notification handler code here
4 CString strTemp;
5 GetDlgItem(IDC_EDIT_OUTPUT)->GetWindowText(strTemp);
6 if (!FirstFlag)
7 {
8 strTemp+="\r\n";
9 }
10 FirstFlag = FALSE;
11 CComboBox *combo;
12 combo = (CComboBox*)GetDlgItem(IDC_COMBO_CAND);
13 CString str;
14 int nSel;
15 nSel = combo->GetCurSel();
16 combo->GetLBText(nSel,str);
17 str = strTemp + str;
18 GetDlgItem(IDC_EDIT_OUTPUT)->SetWindowText(str);
19 }

词库下载:

lexicon.rar

改进:输入框中不用人工输入分隔符

   候选词使用浮动控件现实,接收键盘数字选择。

转载于:https://www.cnblogs.com/wikity/archive/2011/12/22/2297381.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值