同学要求帮忙的作业。

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

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

仿输入法

操作过程简要介绍:

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

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

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

相关文章:

  • 2021-08-23
  • 2021-07-30
  • 2021-07-30
  • 2021-10-25
  • 2021-07-19
猜你喜欢
  • 2022-12-23
  • 2021-05-14
  • 2022-12-23
  • 2021-10-22
  • 2021-04-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案