VS2013 NLPIR分词系统的使用及文本框多行显示

1.资源视图下新建资源Dialog,并为对话框添加类,设置类名为NLPIR_Dlg。


2.在对话框内拖动添加控件Edit Control,并设置其ID为IDC_EDIT_Res、IDC_EDIT_Orig、IDC_EDIT_Dic、IDC_EDIT_Key。另:Edit Control控件要实现显示多行必须修改Multiline、Want Return的属性。

VS2013 NLPIR分词系统的使用及文本框多行显示_第1张图片VS2013 NLPIR分词系统的使用及文本框多行显示_第2张图片

3.在NLPIR_Dlg.cpp中添加如下代码:

void NLPIR_Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	if (!NLPIR_Init(""))
	{
		MessageBox(_T("分词系统初始化失败。"));
	}
	CString str, str_res, str_dic, str_new, str_key ;
	unsigned int add_dic_items = NLPIR_ImportUserDict("user_dict.txt");//Import user dictionary
	const char * new_words = NLPIR_GetFileNewWords("test.txt");
	const char * key_words = NLPIR_GetFileKeyWords("test.txt");
	
	NLPIR_FileProcess("test.txt", "test_result.txt");
	CFile file(_T("test.txt"), CFile::modeRead);
	int filelen = file.GetLength();
	char *p = new char[filelen + 1];
	file.Read(p, filelen);
	p[filelen] = '\0';
	USES_CONVERSION;
	wchar_t* wp = new wchar_t[filelen + 1];
	wp = A2T(p);
	str.Format(_T("%s"), wp);
	//MessageBox(str);

	wchar_t* wp_new = A2T(new_words);
	str_new.Format(_T("%s"), wp_new);
	wchar_t* wp_key = A2T(key_words);
	str_key.Format(_T("%s"), wp_key);

	CFile file_res(_T("test_result.txt"), CFile::modeRead);
	int filelen_res = file_res.GetLength();
	char *p_res = new char[filelen_res + 1];
	file_res.Read(p_res, filelen_res);
	p_res[filelen_res] = '\0';
	wchar_t* wp_res = new wchar_t[filelen_res + 1];
	wp_res = A2T(p_res);
	str_res.Format(_T("%s"), wp_res);
	//MessageBox(str_res);

	CFile file_dic(_T("user_dict.txt"), CFile::modeRead);
	int filelen_dic = file_dic.GetLength();
	char *p_dic = new char[filelen_dic + 1];
	file_dic.Read(p_dic, filelen_dic);
	p_dic[filelen_dic] = '\0';
	wchar_t* wp_dic = new wchar_t[filelen_dic + 1];
	wp_dic = A2T(p_dic);
	str_dic.Format(_T("%s"), wp_dic);
	//MessageBox(str_dic);
	SetDlgItemText(IDC_EDIT_Res,str_res);
	SetDlgItemText(IDC_EDIT_Orig, str);
	SetDlgItemText(IDC_EDIT_Dic, str_dic);
	SetDlgItemText(IDC_EDIT_Key, str_key);

	file.Close();
	file_dic.Close();
	file_res.Close();
}
4.在WeiboView.cpp中包含头文件NLPIR_Dlg.h,并添加如下代码。

#include "NLPIR_Dlg.h"
void CWeiboView::OnBtnresult()
{
	NLPIR_Dlg NLPD;
	NLPD.DoModal();
	// TODO:  在此添加命令处理程序代码
}



你可能感兴趣的:(C++)