📄 dlginput.cpp
字号:
/*! @file DlgInput.cpp \brief 文件功能: 输入对话框的实现文件 ,在没有真实键盘的情况下,实现各种输入 <br> <br> 文件名称: DlgInput.cpp <br> 模块名 : 输入法 <br> \author zqp \version 1.0.0 \remark <br> 修改记录 : <br> 日 期 版本 修改人 修改内容<br>2005/06/13 1.0.0 zqp 创建 <br>******************************************************************************** <br>版权:浙江昆仑科技有限公司 保留所有权利 *******************************************************************************//////// comment generated by CommentMakerPro from www.FeinSoftware.com ////////
// DlgInput.cpp : 实现文件
//
#include "stdafx.h"
#include "ChineseInputer.h"
#include "DlgInput.h"
#include <atltime.h>
#include ".\dlginput.h"
// CDlgInput 对话框
IMPLEMENT_DYNAMIC(CDlgInput, CDialog)
CDlgInput::CDlgInput(CWnd* pParent /*=NULL*/)
: CDialog(CDlgInput::IDD, pParent)
, m_strChar(_T(""))
, m_strInput(_T(""))
, m_bSpell(FALSE)
, m_bNum(TRUE)
, m_bChar(TRUE)
, m_bStrokeOrder(TRUE)
, m_bLower(FALSE)
, m_bUpper(TRUE )
{
m_Inputer.SetMode(ChineseInputer::Inputer::Input_Spell) ;
m_bKillThread = FALSE ;
m_bLock = FALSE ;
}
CDlgInput::~CDlgInput( )
{
HANDLE hWinThread = m_pWinThread->m_hThread ;
m_bKillThread = TRUE ;
int ret = WaitForSingleObject(hWinThread ,5000) ;
if ( ret == WAIT_FAILED )
AfxMessageBox("结束线程出错!") ;
enumer.clear( ) ;
//free(&m_Dic ) ;
}
void CDlgInput::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST, m_lsList);
DDX_Text(pDX, IDC_STCCHAR, m_strChar);
DDX_Control(pDX, IDC_BTNHOME, m_btnHome);
DDX_Control(pDX, IDC_BUTTON1, m_btnB1);
DDX_Control(pDX, IDC_BTNUPGAGE, m_btnUpPage);
DDX_Control(pDX, IDC_BTNDOWNGAGE, m_btnDownPage);
DDX_Control(pDX, IDC_BTNEND, m_btnEnd);
DDX_Control(pDX, IDC_BTNBACk, m_btnBack);
DDX_Radio(pDX, IDC_RADSPELL, m_bSpell);
DDX_Radio(pDX, IDC_RADNUM, m_bNum);
DDX_Radio(pDX, IDC_RADCHAR, m_bChar);
DDX_Radio(pDX, IDC_RADSTROKEORDER, m_bStrokeOrder);
DDX_Radio(pDX, IDC_RADUPPER, m_bUpper);
DDX_Radio(pDX, IDC_RADLOWER, m_bLower);
DDX_Text(pDX, IDC_EDTIN, m_strInput);
DDX_Control(pDX, IDC_EDTIN, m_edtIn);
}
BEGIN_MESSAGE_MAP(CDlgInput, CDialog)
// ON_WM_KEYUP()
// ON_WM_SYSKEYUP()
// ON_WM_CHAR()
// ON_WM_KEYDOWN()
ON_LBN_DBLCLK(IDC_LIST, OnLbnDblclkList)
// ON_LBN_SELCHANGE(IDC_LIST, OnLbnSelchangeList)
ON_BN_CLICKED(IDC_BTN1, OnBnClickedBtn1)
ON_BN_CLICKED(IDC_BTN2, OnBnClickedBtn2)
ON_BN_CLICKED(IDC_BTN3, OnBnClickedBtn3)
ON_BN_CLICKED(IDC_BTN4, OnBnClickedBtn4)
ON_BN_CLICKED(IDC_BTN5, OnBnClickedBtn5)
ON_BN_CLICKED(IDC_BTN6, OnBnClickedBtn6)
ON_BN_CLICKED(IDC_BTN7, OnBnClickedBtn7)
ON_BN_CLICKED(IDC_BTN8, OnBnClickedBtn8)
ON_BN_CLICKED(IDC_BTN9, OnBnClickedBtn9)
ON_BN_CLICKED(IDC_BTNHOME, OnBnClickedBtnhome)
ON_BN_CLICKED(IDC_BTNDOWNGAGE, OnBnClickedBtndowngage)
ON_BN_CLICKED(IDC_BTNEND, OnBnClickedBtnend)
ON_BN_CLICKED(IDC_BTNUPGAGE, OnBnClickedBtnupgage)
ON_BN_CLICKED(IDC_RADSPELL, OnBnClickedRadspell)
ON_BN_CLICKED(IDC_RADNUM, OnBnClickedRadnum)
ON_BN_CLICKED(IDC_RADCHAR, OnBnClickedRadchar)
ON_BN_CLICKED(IDC_RADSTROKEORDER, OnBnClickedRadstrokeorder)
ON_BN_CLICKED(IDC_BTN10, OnBnClickedBtn10)
ON_BN_CLICKED(IDC_BTNBACk, OnBnClickedBtnback)
ON_BN_CLICKED(IDC_BTNLEFT, OnBnClickedBtnleft)
ON_BN_CLICKED(IDC_BTNRIGHT, OnBnClickedBtnright)
ON_EN_SETFOCUS(IDC_EDTIN, OnEnSetfocusEdtin)
ON_EN_KILLFOCUS(IDC_EDTIN, OnEnKillfocusEdtin)
ON_LBN_SELCHANGE(IDC_LIST, OnLbnSelchangeList)
ON_EN_MAXTEXT(IDC_EDTIN, OnEnMaxtextEdtin)
ON_BN_CLICKED(IDC_BTN11, OnBnClickedBtn11)
ON_BN_CLICKED(IDC_RADUPPER, OnBnClickedRadupper)
ON_BN_CLICKED(IDC_RADLOWER, OnBnClickedRadlower)
ON_BN_CLICKED(IDC_BTNOK, OnBnClickedBtnok)
END_MESSAGE_MAP( )
BOOL CDlgInput::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
int nChar;
CString strStrokeOrder = "一丨丿丶乙" ;
CString strFilter ;
if ( pMsg->message == WM_LBUTTONDOWN )
{
CPoint pos = pMsg->pt ;
RECT rInput ;
m_edtIn.GetWindowRect(&rInput) ;
//CPoint pInput =
if ( ( pos.x >= rInput.left) && (pos.x <= rInput.right )
&&(pos.y >= rInput.top ) && ( pos.y <= rInput.bottom ) )
{
return TRUE ; //不需要再处理
}
else //不是在此矩形框内,转发此消息
{
return CDialog::PreTranslateMessage(pMsg) ;
}
}
else if ( (pMsg->message != WM_KEYUP ) && ( pMsg->message != WM_KEYDOWN )
&& (pMsg->message != WM_CHAR ) )
{
return CDialog::PreTranslateMessage(pMsg) ; //转发其它消息
}
else
{
nChar = pMsg->wParam ;
if( ( nChar >= 65 && nChar <= 90) || ( nChar >= 48 && nChar <= 57 )
|| (nChar == 8 ) || ( nChar == 37 ) || ( nChar == 39 ) )
{
if (pMsg->message == WM_KEYUP )
{
TCHAR cChar = pMsg->wParam ;
//是向前删除键
if ( nChar == 8 )
{
int al = m_strChar.GetLength( ) ;
if ( m_nMode == StrokesOrder_Mode ) //!笔顺输入模式
al = (int) al/2 ;
if ( al > 1 )
{
if (m_nMode == 0) //!拼音输入模式
{
m_strChar = m_strChar.Left(m_strChar.GetLength() -1 ) ;
m_Inputer.Reset( ) ;
m_Inputer.Put(_T(m_strChar) ) ;
}
else if (m_nMode == StrokesOrder_Mode) //!笔顺输入模式
{
m_strChar = m_strChar.Left(m_strChar.GetLength() - 2 ) ;
m_strOrderFilter = m_strOrderFilter.Left(m_strOrderFilter.GetLength() -1 ) ;
m_Inputer.Reset( ) ;
m_Inputer.Put(_T(m_strOrderFilter) ) ;
}
}
else if (al == 1)
{
m_strChar ="" ;
m_strOrderFilter ="" ;
m_Inputer.Reset( ) ;
m_lsList.ResetContent( ) ;
this->UpdateData(FALSE) ;
return TRUE ;
}
else
{
CDialog::PreTranslateMessage(pMsg) ;
this->UpdateData( TRUE ) ;
return FALSE ;
}
}
else if (( nChar == 37 ) || ( nChar == 39 ) ) //左右箭头键
{
if ( nChar == 37 )
{
if (m_nCount == 0 )
{
m_edtIn.SetFocus( ) ;
m_edtIn.SetSel(m_nCount,m_nCount) ;
return TRUE ;
}
char cCount = m_strInput.GetAt(m_nCount-1) ;
if ( cCount<0 || cCount > 255 ) //!不是ASCII码字符
m_nCount-- ;
m_nCount-- ;
if( m_nCount < 0 )
m_nCount = 0 ;
m_edtIn.SetFocus( ) ;
m_edtIn.SetSel(m_nCount,m_nCount) ;
}
else
{
char cCount = m_strInput.GetAt(m_nCount) ;
if ( cCount< 0 || cCount > 255 ) //!不是ASCII码字符
{
if ( m_nCount < m_nInputMaxLen - 1 )
m_nCount += 2 ;
}
else
{
if ( m_nCount < m_nInputMaxLen )
m_nCount++ ;
}
if( m_nCount > m_strInput.GetLength( ) )
m_nCount = m_strInput.GetLength( ) ;
m_edtIn.SetFocus( ) ;
m_edtIn.SetSel(m_nCount,m_nCount ) ;
}
}
else //字符和数字键
{
if ( m_nMode == Number_Mode ) //数字输入模式
{
if ( nChar >= 48 && nChar <= 57 )
{
// m_strInput = m_strInput + cChar ;
//this->UpdateData(FALSE) ;
}
return TRUE ;
}
else if (m_nMode == Char_Mode) //字符输入模式
{
if( ( nChar >= 65 && nChar <= 90) || ( nChar >= 48 && nChar <= 57 ) )
{
// m_strInput = m_strInput + cChar ;
// this->UpdateData(FALSE) ;
}
return TRUE ;
}
else if ( m_nMode == Spell_Mode ) // 拼音输入方式
{
if( nChar >= 65 && nChar <= 90)
{
m_strChar =m_strChar + cChar ;
m_Inputer.Put(_T(cChar));
}
else
return TRUE ;
}
else if (m_nMode == StrokesOrder_Mode) //笔顺输入模式
{
if (nChar >= 49 && nChar <= 53 )
{
m_strChar =m_strChar + strStrokeOrder.Mid(2* (nChar-49),2) ;
m_strOrderFilter = m_strOrderFilter + cChar ;
m_Inputer.Put( cChar ) ;
}
else
return TRUE ;
}
}
this->UpdateData(FALSE ) ;
if (m_nMode == Spell_Mode ) //拼音输放模式
{
strFilter = m_Inputer.GetSpell( ) ;
if ( strFilter.GetLength( ) < 1 ) //没有字符串
return TRUE ; //CDialog::PreTranslateMessage(pMsg);
strFilter.MakeLower( ) ;
ChineseDictionary::SpellQuery * spellquery = m_ChineseInputer.GetSpellQuery( ) ;
enumer.clear( );
if ( !spellquery->QueryWords(strFilter , enumer ) )
return TRUE ;
//增中排序
}
else if ( m_nMode == StrokesOrder_Mode) //笔顺
{
strFilter = m_Inputer.GetStrokesOrder( ) ;
if ( strFilter.GetLength( ) < 1 ) //没有字符串
return TRUE ; //CDialog::PreTranslateMessage(pMsg);
ChineseDictionary::StrokesOrderQuery * STrokeOrderQuery = m_ChineseInputer.GetStrokesOrderQuery( ) ;
enumer.clear( );
if ( !STrokeOrderQuery->QueryWords(strFilter , enumer ))
return TRUE ;
//增中排序
}
CString stri ;
m_lsList.ResetContent( ) ;
ChineseInputer::WordEnumerator::iterator it ;
m_it= enumer.begin( ) ;
m_nPageCount = (int)(enumer.size( )/m_nPageSize) ; //总页数
//计数总页数
if ( (enumer.size( ) % m_nPageSize ) != 0 )
m_nPageCount = m_nPageCount + 1 ;
m_nCurrPage = 0 ; //当前页码
for (int i = 1 ; i<= m_nPageSize ; i++ ) //m_it =enumer.begin( ) ; m_it !=enumer.end() ;m_it++
{
if ( m_it == enumer.end( ) )
break ;
if ( i == 10 )
stri.Format("%d" ,0) ;
else
stri.Format("%d" ,i) ;
m_lsList.AddString( stri+ ":" + (CString)(Word)(*m_it)) ;
if ( i != m_nPageSize )
m_it++ ; //下移一个
}
}
else
return TRUE ;
}
}
}
/*! @function public SpellQuery********************************************************************************\brief 功能 : 根据输入的拼音字母查询汉字 <br>函数名 :\return BOOL <insert return value description here>\exception \author zqp \remark <br>典型用法: <br>复杂度 : *******************************************************************************/BOOL CDlgInput::SpellQuery( )
{
CString strFilter = m_Inputer.GetSpell( ) ;
if ( strFilter.GetLength( ) < 1 ) //没有字符串
return TRUE ; //CDialog::PreTranslateMessage(pMsg);
strFilter.MakeLower( ) ;
ChineseDictionary::SpellQuery * spellquery = m_ChineseInputer.GetSpellQuery( ) ;
enumer.clear( );
if ( !spellquery->QueryWords(strFilter , enumer ) ) //!查询失败
return FALSE ;
CString stri ;
m_lsList.ResetContent( ) ;
ChineseInputer::WordEnumerator::iterator it ;
m_it= enumer.begin( ) ;
m_nPageCount = (int)(enumer.size( )/m_nPageSize) ; //!总页数
//!计数总页数
if ( (enumer.size( ) % m_nPageSize ) != 0 )
m_nPageCount = m_nPageCount + 1 ;
m_nCurrPage = 0 ; //!当前页码
for (int i = 1 ; i<= m_nPageSize ; i++ ) //m_it =enumer.begin( ) ; m_it !=enumer.end() ;m_it++
{
if ( m_it == enumer.end( ) )
break ;
if ( i == 10 )
stri.Format("%d" ,0) ;
else
stri.Format("%d" ,i) ;
m_lsList.AddString( stri+ ":" + (CString)(Word)(*m_it)) ;
if ( i != m_nPageSize )
m_it++ ; //下移一个
}
}
void CDlgInput::OnBnClickedBtnabc( )
{
// TODO: 在此添加控件通知处理程序代码
//MSG * pMsg ;
// pMsg->hwnd = this->m_hWnd ;
// pMsg->wParam = 65 ;
this->PostMessage(WM_KEYUP ,65,0 ) ;
}
void CDlgInput::OnLbnDblclkList( )
{
// TODO: 在此添加控件通知处理程序代码
}
//void CDlgInput::OnLbnSelchangeList( )
//{
// // TODO: 在此添加控件通知处理程序代码
//}
BOOL CDlgInput::OnInitDialog( )
{
CDialog::OnInitDialog();
//HICON ico = ::LoadIcon( ::AfxGetInstanceHandle( ),MAKEINTRESOURCE(IDI_ICOHOME) ) ; //IDI_QUESTION MAKEINTRESOURCE( IDI_ICOHOME) ) ;
//m_btnB1.SetIcon(ico ) ;
//!初始化上翻,下翻,最前和最后的按钮图标
m_btnHome.SetIcon(::LoadIcon( ::AfxGetInstanceHandle( ),MAKEINTRESOURCE(IDI_ICOHOME) ) ) ;
m_btnEnd.SetIcon(::LoadIcon( ::AfxGetInstanceHandle( ),MAKEINTRESOURCE(IDI_ICOEND) ) ) ;
m_btnUpPage.SetIcon(::LoadIcon( ::AfxGetInstanceHandle( ),MAKEINTRESOURCE(IDI_ICOUPPAGE) ) ) ;
m_btnDownPage.SetIcon(::LoadIcon( ::AfxGetInstanceHandle( ),MAKEINTRESOURCE(IDI_ICODOWNPAGE) ) ) ;
//!初始化回退按钮的图标
m_btnBack.SetIcon(::LoadIcon( ::AfxGetInstanceHandle( ),MAKEINTRESOURCE(IDI_ICOBACK) ) ) ;
CFont ft ;
ft.CreateFont(19, // nHeight
10, // nWidth
0, // nEscapement
0, // nOrientation
15, // nWeight FW_NORMAL
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
DEFAULT_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"宋体" ); // lpszFacename Arial
//!设置列表框的字体
m_lsList.SetFont( &ft ) ;
ft.DeleteObject( ) ;
//!初始化光标前的字符个数为0;
m_nCount = 0 ;
m_nPageCount = 0 ;
enumer.clear( ) ;
//!初始化输入框的字体
LOGFONT lf ;
lf.lfHeight = 20 ;
lf.lfWidth = 10 ;
lf.lfEscapement = 0 ;
lf.lfOrientation= 0 ;
lf.lfWeight = 15 ;
lf.lfItalic =FALSE ;
lf.lfUnderline = FALSE ;
lf.lfStrikeOut = 0 ;
lf.lfCharSet = DEFAULT_CHARSET ;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS ;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS ;
lf.lfQuality = DEFAULT_QUALITY ;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS ;
//lf.lfFaceName =CString::CopyChars( "宋体" ;
//StringCchCopy( (LPSTR)&lf.lfFaceName, 5, "宋体" );
TCHAR * strFace = "宋体" ;
::strcpy(lf.lfFaceName ,strFace ) ;
CFont fInput ; //! 获取输入框的字
fInput.CreateFontIndirect( &lf ) ;
m_edtIn.SetFont(&fInput) ;
//fInput->GetLogFont( &lf) ;
//CString fName = lf.lfFaceName ;
//!默认的输入模式为拼音输入法
m_nMode = Spell_Mode ;
//!默认为小写
m_nUpperOrLower = CharLower ;
//!初始化连续击键的时间间隔 ,单位是毫秒
m_nTimeGap = 1000 ;
//!初始化前一次击键的时间
m_tPreTime = CFileTime::GetCurrentTime( ) ;
//!初始化前一次击键的序号
m_nPreBtnNo = 0 ;
m_edtIn.SetLimitText(m_nInputMaxLen ) ;
//!初始化特殊符号
m_aSymbol[0] ='!' ;
m_aSymbol[1] ='@' ;
m_aSymbol[2] ='#' ;
m_aSymbol[3] ='$' ;
m_aSymbol[4] ='%' ;
m_aSymbol[5] ='?' ;
m_aSymbol[6] ='&' ;
m_aSymbol[7] ='*' ;
m_aSymbol[8] ='(' ;
m_aSymbol[9] =')' ;
m_aSymbol[10] ='-' ;
m_aSymbol[11] ='+' ;
m_aSymbol[12] ='=' ;
m_aSymbol[13] ='_' ;
m_aSymbol[14] ='.' ;
m_aSymbol[15] ='^' ;
m_aSymbol[16] ='<' ;
m_aSymbol[17] ='>' ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -