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

📄 askdlg.cpp

📁 能够进行汉字的查询
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		break;

	case RE_BT:
		m_cf.yHeight     = 200;     
		m_cf.crTextColor = RGB(64,128,128);
		m_cf.dwMask      = CFM_COLOR|CFM_SIZE|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE;
		m_cf.dwEffects   = CFE_BOLD ;
		break;

	case RE_EMAIL:
		m_cf.yHeight     = 200;     
		m_cf.crTextColor = RGB(0,0,255);
		m_cf.dwMask      = CFM_COLOR|CFM_SIZE|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE;
		m_cf.dwEffects   = CFE_ITALIC |CFE_UNDERLINE ;
		break;

	default:
		break;
	}	
	str += "\n";
	int iLength = m_REditCtrlCY.GetWindowTextLength();		
	m_REditCtrlCY.SetSel(iLength, iLength);
	m_REditCtrlCY.SetSelectionCharFormat(m_cf);
	m_REditCtrlCY.ReplaceSel(str);	
}


void CAskDlg::AddDataToCYEdit(CString strCY)
{
	m_REditCtrlCY.SetReadOnly(FALSE);
	m_REditCtrlCY.SetSel(0,-1);
	m_REditCtrlCY.Clear();	
	//UpdateData(FALSE);
	
	if(strCY.IsEmpty())
	{
		ShowCopyRight();
		return;
	}

#ifdef _DEBUG_AFXMESSAGEBOX_
	AfxMessageBox("AddDataToCYEdit(CString strCY)");	
#endif

	CString strTemp;
	m_strSQL.Format("Select * from cyk where cy like '%s'",strCY);
	m_Recordset.Open(CRecordset::forwardOnly,m_strSQL,CRecordset::readOnly);
	if( !m_Recordset.IsEOF() )
	{
		InsertTextToCYEdit(strCY,RE_CY);

		m_Recordset.GetFieldValue("cy",strTemp);

		m_Recordset.GetFieldValue("py",strTemp);
		InsertTextToCYEdit(strTemp,RE_PY);	
		
		InsertTextToCYEdit("【近义词】:",RE_BT);
		m_Recordset.GetFieldValue("jyc",strTemp);
		InsertTextToCYEdit(strTemp,RE_NORMAL);	

		InsertTextToCYEdit("【反义词】:",RE_BT);
		m_Recordset.GetFieldValue("fyc",strTemp);
		InsertTextToCYEdit(strTemp,RE_NORMAL);	

		InsertTextToCYEdit("【释义】:",RE_BT);
		m_Recordset.GetFieldValue("sy",strTemp);
		InsertTextToCYEdit(strTemp,RE_NORMAL);			

		InsertTextToCYEdit("【出处】:",RE_BT);
		m_Recordset.GetFieldValue("cc",strTemp);
		InsertTextToCYEdit(strTemp,RE_NORMAL);	

		InsertTextToCYEdit("【例句】:",RE_BT);
		m_Recordset.GetFieldValue("liju",strTemp);
		InsertTextToCYEdit(strTemp,RE_NORMAL);
		
	}
	m_Recordset.Close();
	m_REditCtrlCY.LineScroll(-10);
	m_REditCtrlCY.SetReadOnly();
	UpdateData(TRUE);
}

//LVN_ITEMCHANGED 事件可捕获列表控件中的值改变的各种情况(用鼠标点击或键盘的上下键操作),
void CAskDlg::OnItemchangedListCy(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
	// TODO: Add your control notification handler code here

#ifdef _DEBUG_AFXMESSAGEBOX_
	AfxMessageBox("ItemchangedListCy ");
#endif

	POSITION pos = m_listCtrlCY.GetFirstSelectedItemPosition();
	if (pos != NULL)
	{
	//	AfxMessageBox("if (pos != NULL)");
		int iSel  = m_listCtrlCY.GetNextSelectedItem(pos);
		if(iSel != m_iSelCy)
		{
			CString strCY = m_listCtrlCY.GetItemText(iSel, 0); 	
//			AfxMessageBox(strCY);
			AddDataToCYEdit(strCY);
			m_iSelCy = iSel;
		}		
	}
	m_listCtrlCY.SetFocus();
	*pResult = 0;
}


void CAskDlg::AddDataToSpellListCtrl(CString strSpell)
{
	int iLength = strSpell.GetLength();
	int i       = 0;
	int iNum    = 0;
	char c;
	for(i=0; i<iLength; i++)
	{
		c = strSpell.GetAt(i);
		switch(c)
		{
		case '?':
		case '_':
			strSpell.SetAt(i, '_');
			iNum ++;
			break;

		case '*':
		case '%':
			strSpell.SetAt(i, '%');
			break;

		default:	
			iNum ++;
			break;
		}
	}
	if(iNum < 1)return;
	
	m_listCtrlSpell.DeleteAllItems();
	m_strSQL.Format("Select * from wbpy where py1 like '%s' order by py1",strSpell);

#ifdef _DEBUG_AFXMESSAGEBOX_
	AfxMessageBox(m_strSQL);
#endif

	m_Recordset.Open(CRecordset::forwardOnly,m_strSQL,CRecordset::readOnly);
	
	i = 0;
	CString strTemp;
	while( !m_Recordset.IsEOF() )
	{	
		m_listCtrlSpell.InsertItem(i, "");	

		m_Recordset.GetFieldValue("hz", strTemp);
		m_listCtrlSpell.SetItemText(i, 0, "  " + strTemp);
		
		m_Recordset.GetFieldValue("wb86", strTemp);
		m_listCtrlSpell.SetItemText(i, 1, strTemp);

		m_Recordset.GetFieldValue("wb98", strTemp);
		m_listCtrlSpell.SetItemText(i, 2, strTemp);
		
		m_Recordset.GetFieldValue("py1", strTemp);
		m_listCtrlSpell.SetItemText(i, 3, strTemp);
				
		m_Recordset.MoveNext();			
		i++;
	}
	m_Recordset.Close();
	m_strQuerySpell = m_strSpell;

	m_strSpellNum.Format("共%d个",i);
//	UpdateData(false);

	if(!m_bAddDataFlag)
	{
		strTemp = m_listCtrlSpell.GetItemText(0, 0);
		strTemp.TrimLeft();
		m_strWORD = strTemp;
		FindWBPY(m_strWORD);	
	}	
	
	return;
	m_listCtrlSpell.InsertItem( i, "");
	m_listCtrlSpell.SetItemText(i, 0, "共");
	strTemp.Format("%d",i );
	m_listCtrlSpell.SetItemText(i, 1, strTemp);
	m_listCtrlSpell.SetItemText(i, 2, "个");

}

void CAskDlg::OnChangeEditSpell() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	int i = 0;
	int iLength = m_strSpell.GetLength();
	for(i=0; i<iLength; i++)
	{
		if((m_strSpell.GetAt(i) == '?')||(m_strSpell.GetAt(i) == '*'))
			continue;
		if((m_strSpell.GetAt(i) < 'a')||(m_strSpell.GetAt(i) > 'z'))
			m_strSpell.SetAt(i,'~');
	}
	m_strSpell.Remove('~');
	UpdateData(false);
	if(m_strSpell.IsEmpty())
	{
		GetDlgItem(IDC_EDIT_SPELL)->SetFocus();
		return;
	}		
	m_bAddDataFlag = false;
	AddDataToSpellListCtrl(m_strSpell);	
	m_bClickSpellListCtrl = false;
}

void CAskDlg::FindWBPY(CString strWord)
{
	m_staCtlWORD.SetText(m_strWORD);
	m_strPY = _T("拼音编码:");
	m_strWB = _T("五笔编码:");	
	if(strWord.IsEmpty())
	{		
		AddDataToCYListCtrl(m_strWORD,m_bShowAllCY);
	//	UpdateData(FALSE);
		return;
	}

#ifdef _DEBUG_AFXMESSAGEBOX_
	AfxMessageBox("FindWBPY() ");
#endif

	CString strTemp1;
	CString strTemp2;
	m_strSQL.Format("Select * from wbpy where hz like '%s'",strWord);
	m_Recordset.Open(CRecordset::forwardOnly,m_strSQL,CRecordset::readOnly);
	if( !m_Recordset.IsEOF() )
	{
		m_Recordset.GetFieldValue("hz",strTemp1);

		m_Recordset.GetFieldValue("wb86",strTemp1);
		m_Recordset.GetFieldValue("wb98",strTemp2);
		m_strWB.Format("五笔编码:%s  %s",strTemp1,strTemp2);

		m_Recordset.GetFieldValue("py1",strTemp1);
		m_Recordset.GetFieldValue("py2",strTemp2);
		m_strPY.Format("拼音编码:%s  %s",strTemp1,strTemp2);			
	}	
	m_Recordset.Close();	
		
	if(m_bAddDataFlag)
	{
		strTemp1.TrimRight();
		m_strSpell = strTemp1;
		m_strREditCY.Empty();
		UpdateData(FALSE);	
	}

	if(m_strQuerySpell != m_strSpell)
	{			
		AddDataToSpellListCtrl(m_strSpell);
	}	
	AddDataToCYListCtrl(m_strWORD,m_bShowAllCY);
	
}

void CAskDlg::OnItemchangedListSpell(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	
	POSITION pos = m_listCtrlSpell.GetFirstSelectedItemPosition();
	if (pos != NULL)
	{
		int iSel  = m_listCtrlSpell.GetNextSelectedItem(pos);
		CString strSpell = m_listCtrlSpell.GetItemText(iSel, 0);
		strSpell.TrimLeft();
		if(strSpell != m_strSelSpell)
		{

#ifdef _DEBUG_AFXMESSAGEBOX_
  		AfxMessageBox("changedListSpell");	
#endif
		
			m_strWORD = strSpell;			
			FindWBPY(m_strWORD);			
			m_strSelSpell   = strSpell;			
			
			m_bClickSpellListCtrl = true;
		//	UpdateData(FALSE);
		}		
	}
	if(m_bClickSpellListCtrl)
	{
		m_listCtrlSpell.SetFocus();		
	}
	else
	{
		GetDlgItem(IDC_EDIT_SPELL)->SetFocus();
	}
	
	*pResult = 0;
}

void CAskDlg::ShowCopyRight()
{	
#ifdef _DEBUG_AFXMESSAGEBOX_
	AfxMessageBox("ShowCopyRight");
#endif

	m_REditCtrlCY.SetReadOnly(FALSE);

	m_strREditCY.Empty();
	UpdateData(FALSE);	

	InsertTextToCYEdit("    ",RE_NORMAL);
	InsertTextToCYEdit(" 汉字查询系统1.0版",RE_CY);
	InsertTextToCYEdit("\n   本软件集 汉字五笔编码查询(86版、98版)、 拼音编码查询、相关成语查询于一体,使用简单,功能强大,是初学者练习打字、学习成语不可缺少的一个小工具。",RE_NORMAL);
	InsertTextToCYEdit("    ",RE_NORMAL);	
	InsertTextToCYEdit("       软件作者:阳炳林",RE_BT);
	InsertTextToCYEdit("     E-Mail: ybinglin@163.com     ",RE_EMAIL);
 
	UpdateData(TRUE);
	m_REditCtrlCY.SetReadOnly();
}

void CAskDlg::OnBTNCopyCYList() 
{
	// TODO: Add your control notification handler code here

	m_REditCtrlCY.HideSelection(true,false);
	m_listCtrlCY.SetTextBkColor(RGB(212,217,252));

	HANDLE hMem;
	CString strCYList;
	CString strTemp; 
	int iCount = m_listCtrlCY.GetItemCount();
	int i = 0;
	for(i = 0; i < iCount; i++)
	{
		//m_listCtrlCY.SetHotItem(i);
		strTemp = m_listCtrlCY.GetItemText(i, 0);
		m_listCtrlCY.SetItemText(i,0,strTemp);
		strCYList += strTemp;
		strCYList += "、";
	}	
	strCYList.TrimRight("、");

	hMem = LocalAlloc(LPTR, strCYList.GetLength()+1);
	memcpy(hMem, (LPCTSTR)strCYList, strCYList.GetLength()+1);
	if( OpenClipboard() ) 
	{
		if( !EmptyClipboard() ) 
		{
			MessageBox("Clipboard cannot be emptied!","ERROR!", MB_OK);
			return;
		}
		SetClipboardData(CF_TEXT, hMem);
		CloseClipboard();
	}
}

void CAskDlg::OnBTNCopyR() 
{
	UpdateData(TRUE);
	m_REditCtrlCY.SetFocus();
	m_REditCtrlCY.SetSel(0,-1);
	m_REditCtrlCY.Copy();
	m_REditCtrlCY.HideSelection(false,false);
	//m_REditCtrlCY.HideSelection(true,false);
	//SetCYListColor();	
}

void CAskDlg::OnSetfocusEditSpell() 
{
	// TODO: Add your control notification handler code here
	m_REditCtrlCY.HideSelection(true,false);
//	SetCYListColor();
}

void CAskDlg::OnSetfocusEditWord() 
{
	// TODO: Add your control notification handler code here
//	AfxMessageBox("OnSetfocusEditWord");
	m_editWORD.SetSel(0,-1);
	m_REditCtrlCY.HideSelection(true,false);
//	SetCYListColor();
}

void CAskDlg::OnSetfocusListSpell(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	m_REditCtrlCY.HideSelection(true,false);
//	SetCYListColor();
	*pResult = 0;
}

void CAskDlg::OnSetfocusListCy(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	m_REditCtrlCY.HideSelection(true,false);
//	SetCYListColor();
	*pResult = 0;
}

void CAskDlg::SetCYListColor()
{
	m_listCtrlCY.SetTextBkColor(RGB(255,255,255));

	int iCount = m_listCtrlCY.GetItemCount();
	int i = 0;
	for(i = 0; i < iCount; i++)
	{	
		m_listCtrlCY.SetItemText(i,0,m_listCtrlCY.GetItemText(i, 0));	
	}	
}

⌨️ 快捷键说明

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