⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dictdlg.cpp

📁 1、对于凯撒密文
💻 CPP
字号:
// DictDlg.cpp : implementation file
//

#include "stdafx.h"
#include "030300816.h"
#include "DictDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDictDlg dialog


CDictDlg::CDictDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDictDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDictDlg)
	m_check = _T("");
	m_delete = _T("");
	m_insert = _T("");
	m_output = _T("");
	//}}AFX_DATA_INIT
}


void CDictDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDictDlg)
	DDX_Text(pDX, IDC_CHECK_WORD, m_check);
	DDX_Text(pDX, IDC_DELETE_WORD, m_delete);
	DDX_Text(pDX, IDC_INSERT_WORD, m_insert);
	DDX_Text(pDX, IDC_OUTPUT, m_output);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDictDlg, CDialog)
	//{{AFX_MSG_MAP(CDictDlg)
	ON_BN_CLICKED(IDC_CHECK, OnCheck)
	ON_BN_CLICKED(IDC_INSERT, OnInsert)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_INSERT_WORDLIST, OnInsertWordlist)
	ON_WM_CLOSE()
	ON_WM_SETCURSOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDictDlg message handlers

void CDictDlg::OnCheck() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	WordMatch match = m_pDictionary->IsWordListed(m_check);
	switch (match)
	{
	case eMatchPerfect:
		m_output = m_check + " 已存在词库中。";
		break;
		
	case eMatchCapitalisedFirst:
		m_output = m_check + " 已存在词库中, 但首字母为大写。";
		break;
		
	case eMatchMixedCase:
		m_output = m_check + " 形式上有误. 建议采用 :" + BuildSuggestions(m_check, true);
		break;
		
	case eMatchNone:
		m_output = m_check + " 不存在词库中. 找到相近的词为 :" + BuildSuggestions(m_check, false);
		break;
		
	case eMatchInternalError:
		m_output = m_check + " 导致内部错误。";
		break;
	}
	UpdateData(false);
}

void CDictDlg::OnInsert() 
{
	// TODO: Add your control notification handler code here
	changed = true;
	UpdateData();
	m_pDictionary->InsertWord(m_insert);
	CString num;
	int nWords = m_pDictionary->GetWordCount();
	num.Format("目前词库共有单词%d个。",nWords);
    m_output = m_insert + " 插入完成。" + "\r\n" + num;
	UpdateData(false);
}

void CDictDlg::OnDelete() 
{
	// TODO: Add your control notification handler code here
	changed = true;
	UpdateData();
	if (m_pDictionary->RemoveWord(m_delete))
	{
		m_output = m_delete + " 删除完成。";
	}
	else
	{
		m_output = m_delete + " 删除失败。";
	}
	CString num;
	int nWords = m_pDictionary->GetWordCount();
	num.Format("目前词库共有单词%d个。",nWords);
	m_output = m_output + "\r\n" + num;
	UpdateData(false);
}

CString CDictDlg::BuildSuggestions(const CString &strWord, bool bCaseOnly)
{
	// Get the suggestions
    CStringArray straSuggestions;
    CString strSuggestions;
    m_pDictionary->GetSuggestions(strWord, straSuggestions, bCaseOnly);
	
    for (int nCount = 0; nCount < straSuggestions.GetSize(); nCount++)
    {
        if (nCount)
        {
            strSuggestions += ", ";
        }
        strSuggestions += straSuggestions[nCount];
    }
	
    return strSuggestions;
}

void CDictDlg::OnInsertWordlist() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, "Text files (*.txt)|*.txt|All files (*.*)|*.*||");
    if (dlgFile.DoModal() == IDOK)
    {
        m_pDictionary->CreateFromList(dlgFile.GetPathName(), true);
		int nWords = m_pDictionary->GetWordCount();
		m_output.Format("目前词库共有单词%d个。",nWords);
		SetDlgItemText(IDC_OUTPUT,m_output);
    }
}

void CDictDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	bool bAppend = false;
	if ( changed == true )
		bAppend = AfxMessageBox("词典经过修改\n\n是否需要保存?", MB_ICONQUESTION | MB_YESNO) == IDYES;
	if ( bAppend == true )
		m_pDictionary->SaveDictionary("my.dic");
	CDialog::OnClose();
}

BOOL CDictDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_hArrow = AfxGetApp()->LoadCursor(IDC_MYARROW);
	m_hHand = AfxGetApp()->LoadCursor(IDC_MYHAND);
	m_hBeam = AfxGetApp()->LoadCursor(IDC_MYBEAM);
	m_hPen = AfxGetApp()->LoadCursor(IDC_MYPEN);
	m_hMove = AfxGetApp()->LoadCursor(IDC_MYMOVE);
	changed = false;
	int nWords = m_pDictionary->GetWordCount();
	m_output.Format("目前词库共有单词%d个。",nWords);
	SetDlgItemText(IDC_OUTPUT,m_output);
	m_wndTaskbarNotifier->Show("欢迎进入词典工具窗口!\r\n在这您可以对本系统的词库进行一系列的修改!");
//	pSkin2->ApplySkin((long)m_hWnd);
	// CG: The following block was added by the ToolTips component.	{		// Create the ToolTip control.		m_tooltip.Create(this);		m_tooltip.Activate(TRUE);		m_tooltip.AddTool(GetDlgItem(IDC_CHECK), "检查词库中是否存在这个词");
		m_tooltip.AddTool(GetDlgItem(IDC_INSERT), "插入一个单词");
		m_tooltip.AddTool(GetDlgItem(IDC_DELETE), "删除一个已有单词");
		m_tooltip.AddTool(GetDlgItem(IDC_INSERT_WORDLIST), "插入一个词库列表");
		m_tooltip.AddTool(GetDlgItem(IDC_CHECK_WORD), "请输入要检查的单词");
		m_tooltip.AddTool(GetDlgItem(IDC_INSERT_WORD), "请输入要插入的单词");
		m_tooltip.AddTool(GetDlgItem(IDC_DELETE_WORD), "请输入要删除的单词");
		m_tooltip.AddTool(GetDlgItem(IDC_OUTPUT), "输出窗口");		// TODO: Use one of the following forms to add controls:		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), <string-table-id>);		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), "<text>");	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CDictDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	// TODO: Add your message handler code here and/or call default
	if ( pWnd == GetDlgItem(IDC_CHECK) 
		|| pWnd == GetDlgItem(IDC_INSERT)
		|| pWnd == GetDlgItem(IDC_DELETE)
		|| pWnd == GetDlgItem(IDC_INSERT_WORDLIST)
		)
		::SetCursor(m_hHand);
	else if ( pWnd == GetDlgItem(IDC_CHECK_WORD)
		|| pWnd == GetDlgItem(IDC_OUTPUT)
		|| pWnd == GetDlgItem(IDC_INSERT_WORD)
		|| pWnd == GetDlgItem(IDC_DELETE_WORD)
		)
		::SetCursor(m_hBeam);
	else if ( nHitTest == HTCAPTION )
		::SetCursor(m_hMove);
	else
		::SetCursor(m_hArrow);
	return true;
	//return CDialog::OnSetCursor(pWnd, nHitTest, message);
}

BOOL CDictDlg::PreTranslateMessage(MSG* pMsg)
{
	// CG: The following block was added by the ToolTips component.	{		// Let the ToolTip process this message.		m_tooltip.RelayEvent(pMsg);	}	return CDialog::PreTranslateMessage(pMsg);	// CG: This was added by the ToolTips component.
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -