📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "TestLexicon.h"
#include "MainFrm.h"
#include "GetDataDlg.h"
#include "MyDictionary.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
// void LoadHZFreq(), StoreHZFreq();
BOOL GetData(const char * Prompt, CString & Data); // 从对话框获取用户输入的数据
BOOL GetData(const char * Prompt, int & Data);
BOOL GetData(const char * Prompt, double & Data);
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_BindSnapshot, OnBindSnapshot)
ON_COMMAND(ID_Bind_Dynamic, OnBindDynamic)
ON_COMMAND(ID_BindDynamic2, OnBindDynamic2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
CMyDictionary pDict;
void CMainFrame::OnBindSnapshot()
{// 在词库中查找一个词的所有词性及词性标记,测试CWordTagSet类的GetFreqs函数
// TODO: Add your command handler code here
CWordTagSet * pSet=new CWordTagSet;
pSet->Open();
if(!pSet->IsOpen()){
AfxMessageBox("can not open database");
delete pSet;
return;
}
CString w,msg;
CObArray a;
if(!GetData("请输入要查找的词串",w))
return;
int i,n=pSet->GetFreqs(w,a);
if(n==0)
AfxMessageBox("词库中无此词语");
else {
msg=w+":\n";
CTagFreq * pt;
for(i=0;i<n;i++) {
pt=(CTagFreq *)a.GetAt(i);
w.Format("词性标记: %s\n出现的次数: %d\n",pt->Tag,pt->Freq);
msg+=w;
}
AfxMessageBox(msg);
}
delete pSet;
}
void CMainFrame::OnBindDynamic()
{ // 测试CMyDicionary类的成员函数GetFreq(CString w, CObArray a)版本
// TODO: Add your command handler code here
CString w, msg;
CObArray a;
if(!GetData("请输入要查找的词:",w))
return;
w.TrimLeft();
w.TrimRight();
if (w=="") {
AfxMessageBox("您没有输入词语");
return;
}
int i;
int n=pDict.GetFreq(w,a);
if(n==0)
AfxMessageBox("词库中无此词!!!");
else {
msg =w+":\n";
CTagFreq *pt;
for(i=0;i<n;i++) {
pt=(CTagFreq *) a.GetAt(i);
w.Format("标记:%s;出现次数:%d\n",pt->Tag,pt->Freq);
msg+=w;
}
AfxMessageBox(msg);
}
}
void CMainFrame::OnBindDynamic2()
{ // 测试CMyDicionary类的成员函数GetFreq(CString w, CString t)版本
// TODO: Add your command handler code here
CString w, msg, t;
if(!GetData("请输入要查找的词:",w))
return;
w.TrimLeft();
w.TrimRight();
if (w=="") {
AfxMessageBox("您没有输入词语");
return;
}
if(!GetData("请输入要查找词的词性:",t))
return;
int n=pDict.GetFreq(w,t);
if(n==0)
AfxMessageBox("词库中无此词!!!");
if(n==-1)
AfxMessageBox("词库中有这个词,但词性与您输入的词性不符!!!");
else {
msg.Format("词语: %s;\n词性标记: %s;\n该词出现次数: %d\n",w,t,n);
AfxMessageBox(msg);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -