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

📄 engrecitedlg.cpp

📁 背单词程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	Shell_NotifyIcon(NIM_ADD, &m_notifyIconData);
	ShowWindow(SW_HIDE);
}

void CEngReciteDlg::OnExit() 
{
	switch(AfxMessageBox(_T("是否保存修改?"), MB_YESNOCANCEL | MB_ICONWARNING))
	{
	case IDYES:
		BeginWaitCursor();

		SaveToFile();
		ClearUpReciteRecMap();

		EndWaitCursor();
	case IDNO:
		EndDialog(IDOK);
	default:
		break;
	}
}

void CEngReciteDlg::OnDestroy() 
{
	CDialog::OnDestroy();

	Shell_NotifyIcon(NIM_DELETE, &m_notifyIconData);
	::GlobalDeleteAtom(m_HotKeyId1);
	::GlobalDeleteAtom(m_HotKeyId2);
}

void CEngReciteDlg::OnEditchangeWordList() 
{
	m_selWord.GetWindowText(m_szWord);
	
	ReciteHisinfoList* pList = GetHisInfoListFromMap(m_szWord);
	
	if (pList != NULL)
	{
		int nIndex = m_selWord.FindStringExact(0, m_szWord);
		if (nIndex != LB_ERR)
		{
			m_selWord.SetCurSel(nIndex);
			RefreshRecInfo();
			
			g_bAddNew = TRUE;			
		}
	}
	else
	{
		g_bAddNew = FALSE;

		if (m_selWord.m_bIsBack)
		{
			m_selWord.m_bIsBack = FALSE;
		}
		else
		{
			int nIndex = m_selWord.FindString(0, m_szWord);
			if (nIndex != LB_ERR)
			{
				m_selWord.SetCurSel(nIndex);
				m_selWord.SetEditSel(m_szWord.GetLength(), -1);
					
				RefreshRecInfo();
			}
		}
	}
}

void CEngReciteDlg::OnKillfocusWordList() 
{
	m_selWord.GetWindowText(m_szWord);
	m_szWord.TrimLeft();
	m_szWord.TrimRight();

	if (m_szWord.IsEmpty() || m_szWord.GetLength() == 0)
		return;
	
	ReciteHisinfoList* pList = GetHisInfoListFromMap(m_szWord);
	if (!g_bAddNew && pList != NULL)
	{
		int nIndex = m_selWord.FindStringExact(0, m_szWord);
		if (nIndex != LB_ERR)
		{
			m_selWord.SetCurSel(nIndex);
			RefreshRecInfo();
		}
		return;
	}

	if (pList != NULL)
	{
		ReciteHisInfo* pNewRec = new ReciteHisInfo();
		
		pNewRec->ct				= CTime::GetCurrentTime();
		pNewRec->hzMeaning		= pList->back()->hzMeaning;
		pNewRec->allStatement	= _T("");
		pNewRec->ownStatement	= _T("");
		pNewRec->remark.Format(_T("这是您第%d次背诵该单词!"), pList->size() + 1);

		pList->insert(pList->end(), pNewRec);		
		
		int nIndex = m_selWord.FindStringExact(0, m_szWord);
		if (nIndex != LB_ERR)
		{
			m_selWord.SetCurSel(nIndex);
			RefreshRecInfo();
		}
	}
	else
	{
		ReciteHisInfo* pNewRec = new ReciteHisInfo();

		pNewRec->ct				= CTime::GetCurrentTime();
		pNewRec->hzMeaning		= _T("");
		pNewRec->allStatement	= _T("");
		pNewRec->ownStatement	= _T("");
		pNewRec->remark			= _T("<添加新单词>");

		ReciteHisinfoList* pNewList = new ReciteHisinfoList();
		pNewList->insert(pNewList->end(), pNewRec);

		mapReciteRec.insert(ReciteRecordMap::value_type(m_szWord, pNewList));

		int nIndex = m_selWord.AddString(m_szWord);
		if (nIndex != LB_ERR)
		{
			m_selWord.SetItemData(nIndex, (DWORD)pNewList);
			m_selWord.SetCurSel(nIndex);
			RefreshRecInfo();
		}

		m_txtChinese.SetFocus();
	}
	g_bAddNew = FALSE;
	
	m_btnSave.EnableWindow(TRUE);
}

void CEngReciteDlg::OnSelendcancelWordList() 
{
}

void CEngReciteDlg::OnSetfocusWordList() 
{
	m_selWord.SetEditSel(0, -1);
}

BOOL CEngReciteDlg::RefreshRecInfo()
{
	m_selHistory.ResetContent();
	
	int nWordIndex = m_selWord.GetCurSel();
	if (nWordIndex != LB_ERR)
	{
		ReciteHisinfoList* pList = (ReciteHisinfoList*)m_selWord.GetItemData(nWordIndex);

		if (pList != NULL)
		{
			ReciteHisinfoList::iterator i;

			int nCount = 1;
			CTime ctNow = CTime::GetCurrentTime();

			for (i = pList->begin(); i != pList->end(); ++i)
			{
				ReciteHisInfo* pInfo = (ReciteHisInfo*)*i;
				if (pInfo != NULL)
				{
					CTimeSpan ctInterval = ctNow - pInfo->ct;

					CString msg;
					msg.Format(_T("第%02d次背诵 (%s) 到当前时间已经: %d天%d小时了!"), 
								nCount++, 
								pInfo->ct.Format("%Y-%m-%d %H:%M"),
								ctInterval.GetDays(),
								ctInterval.GetHours());
					
					int nHisIndex = m_selHistory.AddString(msg);
					if (nHisIndex != LB_ERR)
					{
						m_selHistory.SetItemData(nHisIndex, (DWORD)pInfo);
					}
				}
			}

			m_selHistory.SetCurSel(m_selHistory.GetCount() - 1);
			RefreshHisInfo();
		}
	}

	return TRUE;
}

BOOL CEngReciteDlg::RefreshHisInfo()
{
	int nIndex = m_selHistory.GetCurSel();
	if (nIndex != LB_ERR)
	{
		ReciteHisInfo* pInfo = (ReciteHisInfo*)m_selHistory.GetItemData(nIndex);

		if (pInfo != NULL)
		{
			m_txtChinese.SetWindowText(pInfo->hzMeaning);		
			m_txtAllStatement.SetWindowText(pInfo->allStatement);
			m_txtOwnStatement.SetWindowText(pInfo->ownStatement);
			m_txtRemark.SetWindowText(pInfo->remark);

			DecorateAllStatement();
		}
	}

	return TRUE;
}

void CEngReciteDlg::OnKillfocusAllStatement() 
{
	UpdateData(TRUE);

	int nIndex = m_selHistory.GetCurSel();
	if (nIndex != LB_ERR)
	{
		ReciteHisInfo* pInfo = (ReciteHisInfo*)m_selHistory.GetItemData(nIndex);
		
		if (pInfo != NULL)
		{
			pInfo->allStatement = m_szAllStatement;
			DecorateAllStatement();
		}
	}	
}

void CEngReciteDlg::OnKillfocusChinese() 
{
	UpdateData(TRUE);

	int nIndex = m_selHistory.GetCurSel();
	if (nIndex != LB_ERR)
	{
		ReciteHisInfo* pInfo = (ReciteHisInfo*)m_selHistory.GetItemData(nIndex);
		
		if (pInfo != NULL)
		{
			pInfo->hzMeaning = m_szChinese;
		}
	}
}

void CEngReciteDlg::OnKillfocusOwnStatemnet() 
{
	UpdateData(TRUE);

	int nIndex = m_selHistory.GetCurSel();
	if (nIndex != LB_ERR)
	{
		ReciteHisInfo* pInfo = (ReciteHisInfo*)m_selHistory.GetItemData(nIndex);
		
		if (pInfo != NULL)
		{
			pInfo->ownStatement = m_szOwnStatement;
		}
	}
}

void CEngReciteDlg::OnKillfocusRemark() 
{
	UpdateData(TRUE);

	int nIndex = m_selHistory.GetCurSel();
	if (nIndex != LB_ERR)
	{
		ReciteHisInfo* pInfo = (ReciteHisInfo*)m_selHistory.GetItemData(nIndex);
		
		if (pInfo != NULL)
		{
			pInfo->remark = m_szRemark;
		}
	}
}

void CEngReciteDlg::OnSelchangeHistoryList() 
{
	RefreshHisInfo();
}

void CEngReciteDlg::OnSelendokWordList() 
{
	RefreshRecInfo();	
}


void CEngReciteDlg::OnSave() 
{
	m_btnSave.EnableWindow(FALSE);

	SaveToFile();
}

void CEngReciteDlg::OnCancel() 
{
}

void CEngReciteDlg::OnOK() 
{
}

void CEngReciteDlg::OnDeleteRec() 
{
	int nIndex = m_selWord.GetCurSel();
	if (nIndex != LB_ERR)
	{
		m_selWord.GetWindowText(m_szWord);
		ReciteHisinfoList* pList = (*(mapReciteRec.find(m_szWord))).second;
		mapReciteRec.erase(m_szWord);
		if (pList != NULL)
		{
			ReciteHisinfoList::iterator i = NULL;
			for (i = pList->begin(); i != pList->end(); ++i)
			{
				ReciteHisInfo* pInfo = *i;
				if (pInfo != NULL)
				{
					delete pInfo;
				}
			}

			delete pList;
		}

		m_selWord.DeleteString(nIndex);
		if (nIndex < m_selWord.GetCount())
		{
			m_selWord.SetCurSel(nIndex);
		}
		else
		{
			if (nIndex > 0) 
				m_selWord.SetCurSel(nIndex - 1);
			else
				m_selWord.SetWindowText(_T(""));
		}
		RefreshRecInfo();
	}
}

void CEngReciteDlg::OnDeleteHis() 
{
	int nIndex = m_selHistory.GetCurSel();
	if (nIndex != LB_ERR)
	{
		m_selWord.GetWindowText(m_szWord);
		ReciteHisinfoList* pList = (*(mapReciteRec.find(m_szWord))).second;
		if (pList != NULL)
		{
			ReciteHisinfoList::iterator i = NULL;
			for (i = pList->begin(); i != pList->end(); ++i)
			{
				ReciteHisInfo* pInfo = *i;
				if (pInfo != NULL && (DWORD)pInfo == m_selHistory.GetItemData(nIndex))
				{
					pList->erase(i);
					delete pInfo;
					break;
				}
			}
		}

		if (pList->size() == 0)
		{
			OnDeleteRec();
			return;
		}

		m_selHistory.DeleteString(nIndex);
		if (nIndex < m_selHistory.GetCount())
		{
			m_selHistory.SetCurSel(nIndex);
		}
		else
		{
			if (nIndex > 0) 
				m_selHistory.SetCurSel(nIndex - 1);
			else
				m_selHistory.SetWindowText(_T(""));
		}
		RefreshHisInfo();
		

	}
}

void CEngReciteDlg::DecorateAllStatement()
{
	int nIndex = m_selWord.GetCurSel();

	if (nIndex == LB_ERR)
		return;

	m_selWord.GetLBText(nIndex, m_szWord);

	FINDTEXTEX ft;
	ft.chrg.cpMin = 0;
	ft.chrg.cpMax = -1;
	ft.lpstrText  = m_szWord.GetBuffer(0);

	while (m_txtAllStatement.FindText(0, &ft) != -1)
	{
		ft.chrg.cpMin = ft.chrgText.cpMax;
		
		m_txtAllStatement.SetSel(ft.chrgText);

		CHARFORMAT cf;
		cf.dwMask	   = CFM_STRIKEOUT | CFM_BOLD | CFM_COLOR;
		cf.dwEffects   = CFE_BOLD;
		cf.crTextColor = RGB(255, 0, 0);

		m_txtAllStatement.SetSelectionCharFormat(cf);

		m_txtAllStatement.HideSelection(TRUE, FALSE);
	}

	m_szWord.ReleaseBuffer();
}

void CEngReciteDlg::OnHelpAbout() 
{
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();
}

static int g_nClickFlag = 0;
void CEngReciteDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	g_nClickFlag++;

	if (g_nClickFlag == 2)
	{
		g_nClickFlag = 0;

		CString msg;

		msg.Format(_T("当前词汇总数为: %d"), mapReciteRec.size());
		
		MessageBox(msg, _T("系统信息"));
	}

	CDialog::OnLButtonDown(nFlags, point);
}

void CEngReciteDlg::OnRButtonDown(UINT nFlags, CPoint point) 
{
	g_nClickFlag++;

	if (g_nClickFlag == 2)
	{
		g_nClickFlag = 0;

		CString msg;

		msg.Format(_T("当前词汇总数为: %d"), mapReciteRec.size());
		
		MessageBox(msg, _T("系统信息"));
	}

	CDialog::OnRButtonDown(nFlags, point);
}

void CEngReciteDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	g_nClickFlag = 0;
	CDialog::OnLButtonUp(nFlags, point);
}

void CEngReciteDlg::OnRButtonUp(UINT nFlags, CPoint point) 
{
	g_nClickFlag = 0;
	CDialog::OnRButtonUp(nFlags, point);
}

int CEngReciteDlg::MyFindString_ListBox(CListBox* lpLst, const CString &szText)
{
	if (lpLst == NULL || szText.IsEmpty())
		return LB_ERR;

	return 0;
}

void CEngReciteDlg::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	int nIndex = m_selWord.GetCurSel();
	if (nIndex != LB_ERR)
	{
		m_selWord.SetCurSel(nIndex+1);
		RefreshRecInfo();
	}

	CDialog::OnLButtonDblClk(nFlags, point);
}

void CEngReciteDlg::OnRButtonDblClk(UINT nFlags, CPoint point) 
{
	int nIndex = m_selWord.GetCurSel();
	if (nIndex != LB_ERR)
	{
		m_selWord.SetCurSel(nIndex-1);
		RefreshRecInfo();
	}
	
	CDialog::OnRButtonDblClk(nFlags, point);
}

void CEngReciteDlg::OnRecite() 
{
	if (m_btnRecite.GetCheck() == 1)
	{
		m_txtChinese.EnableWindow(FALSE);
		m_txtChinese.ShowWindow(FALSE);
	}
	else
	{
		m_txtChinese.EnableWindow(TRUE);
		m_txtChinese.ShowWindow(TRUE);
	}
}

⌨️ 快捷键说明

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