www.pudn.com > T9InPut.rar > T9.cpp, change:2011-06-13,size:26386b


XConnPtContainer 
// T9.cpp : 实现文件 
// 
/* 
	Provide by Yuanwei  
	WuHan 
	QQ:382919276 
*/ 
#include "stdafx.h" 
#include "resource.h" 
#include "T9.h" 
 
 
// CT9 对话框 
 
IMPLEMENT_DYNAMIC(CT9, CDialog) 
 
CT9::CT9(CWnd* pParent /*=NULL*/) 
	: CDialog(CT9::IDD, pParent), 
	m_chEnter(_T('=')),m_chDel(_T(';')),m_chCancel(_T('~')), 
	m_chSign(_T('*')),m_chType(_T('#')), 
	m_kType(Type_PY), 
	m_clrLo(::GetSysColor( COLOR_BTNSHADOW)), m_clrActiveLo(RGB(0, 0, 255)),	 
	m_clrHi(::GetSysColor(COLOR_BTNHIGHLIGHT)), m_clrActiveHi(RGB(255, 0, 0)) 
 
{ 
	//键盘布局表 
	TCHAR chaArray[3][5] =  
	{ 
		{_T('1'),_T('2'),_T('3'),m_chSign,m_chType}, 
		{_T('4'),_T('5'),_T('6'),_T('0'),m_chCancel}, 
		{_T('7'),_T('8'),_T('9'),m_chDel,m_chEnter} 
	}; 
	pZk = new CZK(); // 
	m_nPYPage=m_nHZPage=0; 
 
	m_nRow=3; 
	m_nColumn=5; 
 
	m_nPYSelectColumn=3; 
	m_nHZSelectColumn=6; 
 
	for (int i=0;i<m_nRow;i++) 
	{ 
		for (int j=0;j<m_nColumn;j++) 
		{ 
			m_chLayout[i][j]=chaArray[i][j]; 
		} 
	} 
 
	m_bValidRectArray = FALSE; 
	m_nSpace = 1; 
	m_nPenWidth = 2; 
	m_ptKeyboardIndex[0]=m_ptHZIndex[0]=m_ptPYIndex[0]=CPoint(-1,-1); 
	m_ptKeyboardIndex[1]=m_ptHZIndex[1]=m_ptPYIndex[1]=CPoint(-1,-1); 
	m_peditAcceptInput = NULL; 
 
	ClearShowWord(); 
	ClearPYSelectWord(); 
	SetFont(_T("Arial"), 18, FALSE); 
 
	m_iKeyPress = 0; //按键记数初始化 
	m_iPYNum = 0;    //本次输入所得可用拼音总数初始化 
	m_iPYNumOld = 0; //上一次输入所得可用拼音总数初始化 
 
 
	m_sInputWord.Empty(); //输入字符初始化 
	m_sShowWord.Empty(); //显示字符初始化 
 
 
	 
} 
 
CT9::~CT9() 
{ 
	if (m_font.GetSafeHandle()) 
		m_font.DeleteObject(); 
	if(pZk) 
		delete pZk; 
 
} 
 
void CT9::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
} 
 
 
BEGIN_MESSAGE_MAP(CT9, CDialog) 
	ON_WM_PAINT() 
	ON_WM_SIZE() 
	ON_WM_ERASEBKGND() 
	ON_WM_LBUTTONDOWN() 
//	ON_WM_NCHITTEST() 
END_MESSAGE_MAP() 
 
 
// CT9 消息处理程序 
 
void CT9::SetFont( LPCTSTR lpszFaceName, int nPointSize, BOOL bRedraw/* = TRUE*/ ) 
{ 
	LOGFONT lf; 
	memset(&lf, 0, sizeof(lf)); 
 
	if (lpszFaceName == NULL) 
	{ 
		CFont *pFont = GetFont(); 
		VERIFY(pFont); 
		pFont->GetLogFont(&lf); 
	} 
	else 
	{ 
		_tcsncpy(lf.lfFaceName, lpszFaceName, sizeof(lf.lfFaceName)/sizeof(TCHAR)-1); 
	} 
 
	HDC hdc = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL); 
	VERIFY(hdc); 
	int cyPixelsPerInch = ::GetDeviceCaps(hdc, LOGPIXELSY); 
	::DeleteDC(hdc); 
 
	lf.lfHeight = -MulDiv(nPointSize, cyPixelsPerInch, 72); 
 
	if (m_font.GetSafeHandle()) 
		m_font.DeleteObject(); 
 
	lf.lfWeight = FW_BOLD;// : FW_NORMAL; 
 
	m_font.CreateFontIndirect(&lf); 
 
	if (bRedraw) 
		RedrawWindow(); 
} 
 
void CT9::OnPaint() 
{ 
	CPaintDC dc(this); // device context for painting 
 
	CBrush nullBrush; 
	CPen pen(PS_SOLID, m_nPenWidth, RGB(200, 100, 100)); 
	nullBrush.Attach((HBRUSH)::GetStockObject(NULL_BRUSH)); 
	CBrush* pOldBrush = dc.SelectObject(&nullBrush); 
	CPen* pOldPen = dc.SelectObject(&pen); 
	CFont *pOldFont = dc.SelectObject(&m_font); 
 
	if (m_bValidRectArray) 
	{ 
		dc.SetBkMode(TRANSPARENT); 
		DrawKeyboard(&dc); 
	} 
	DrawPYRect(&dc); 
	DrawHZRect(&dc); 
	DrawSelectedKey(&dc); 
 
	dc.SelectObject(pOldFont); 
	dc.SelectObject(pOldBrush); 
	dc.SelectObject(pOldPen); 
	nullBrush.DeleteObject(); 
} 
 
void CT9::DrawPYRect(CDC *pDC) 
{ 
	//确保是有效的绘图环境 
	VERIFY(pDC != NULL && pDC->GetSafeHdc() != NULL); 
	CFont fntPY; 
	CRect rect(m_rcPY[0]) ; 
	int iFontHeight=-1*rect.Height()/2; 
 
	fntPY.CreateFont( 
		iFontHeight,    //字体高度 
		0,//iFontWidth, //系统选取字体最佳宽度 
		0,              //倾斜度为0,表示水平 
		0,              //字体倾斜度为0 
		FW_HEAVY,          //字体粗度,400为正常 
		FALSE,          //斜体字 
		0,              //下划线 
		0,              //删除线 
		DEFAULT_CHARSET,        //所用的字符集 
		OUT_STROKE_PRECIS,      //输出粗度为默认值 
		CLIP_STROKE_PRECIS,     //裁减粗度为默认值 
		DRAFT_QUALITY,          //输出质量为默认值 
		DEFAULT_PITCH|FF_DONTCARE,  //字间距和字体系列 
		_T( "Times New Roman" ) //字体名称 Face Name 
		); 
	ASSERT(m_nPYPage>=0); 
	for (int i=0;i<m_nPYSelectColumn+2;i++) 
	{ 
		Frame3DRect(pDC->m_hDC, m_clrHi, m_clrLo, CRect(m_rcPY[i]), 2, TRUE, TRUE, TRUE, TRUE); 
	} 
	 
	if (m_ptPYIndex[0]!=CPoint(-1,-1)  ) 
	{ 
		Frame3DRect(pDC->m_hDC, m_clrHi, m_clrLo, CRect(m_rcPY[m_ptPYIndex[0].x]), 
			2, TRUE, TRUE, TRUE, TRUE); 
	} 
	if(m_ptPYIndex[1]!=CPoint(-1,-1)) 
		Frame3DRect(pDC->m_hDC, m_clrActiveHi, m_clrActiveLo, CRect(m_rcPY[m_ptPYIndex[1].x]),  
		2, TRUE, TRUE, TRUE, TRUE); 
 
	COLORREF clr=pDC->GetTextColor(); 
	pDC->SetTextColor(CLR_PY); 
	CString strTemp; 
	CFont *pfntOld = NULL; 
		pfntOld = pDC->SelectObject( &fntPY ); 
	for (int i=0;i<m_nPYSelectColumn+2;i++) 
	{ 
		strTemp.Empty(); 
		if (i==0) 
		{ 
			strTemp=_T("<"); 
		} 
		else if(i==m_nPYSelectColumn+2-1) 
			strTemp=_T(">"); 
		else 
		{ 
			if(m_iPYNum>m_nPYPage*m_nPYSelectColumn+i-1) 
				strTemp=m_arrSelectWord[m_nPYPage*m_nPYSelectColumn+i-1]; 
		} 
		pDC->DrawText(strTemp, &m_rcPY[i], DT_SINGLELINE | DT_VCENTER | DT_CENTER); 
	 
	} 
	pDC->SelectObject( pfntOld ); 
	pDC->SetTextColor(clr); 
	fntPY.DeleteObject(); 
 
} 
void CT9::DrawHZRect( CDC*pDC ) 
{ 
	//确保是有效的绘图环境 
	VERIFY(pDC != NULL && pDC->GetSafeHdc() != NULL); 
	CFont fntHZ; 
	CRect rect(m_rcHZ[0]) ; 
	int iFontHeight=-1*rect.Height()+5; 
 
	fntHZ.CreateFont( 
		iFontHeight,    //字体高度 
		0,//iFontWidth, //系统选取字体最佳宽度 
		0,              //倾斜度为0,表示水平 
		0,              //字体倾斜度为0 
		FW_NORMAL,          //字体粗度,400为正常 
		FALSE,          //斜体字 
		0,              //下划线 
		0,              //删除线 
		DEFAULT_CHARSET,        //所用的字符集 
		OUT_STROKE_PRECIS,      //输出粗度为默认值 
		CLIP_STROKE_PRECIS,     //裁减粗度为默认值 
		DRAFT_QUALITY,          //输出质量为默认值 
		DEFAULT_PITCH|FF_DONTCARE,  //字间距和字体系列 
		_T( "Arial" ) //字体名称 Face Name 
		); 
	ASSERT(m_nHZPage>=0); 
	for (int i=0;i<m_nHZSelectColumn+2;i++) 
	{ 
		Frame3DRect(pDC->m_hDC, m_clrHi, m_clrLo, CRect(m_rcHZ[i]), 2, TRUE, TRUE, TRUE, TRUE); 
	} 
 
	if (m_ptHZIndex[0]!=CPoint(-1,-1)  ) 
	{ 
		Frame3DRect(pDC->m_hDC, m_clrHi, m_clrLo, CRect(m_rcHZ[m_ptHZIndex[0].x]), 
			2, TRUE, TRUE, TRUE, TRUE); 
	} 
	if(m_ptHZIndex[1]!=CPoint(-1,-1)) 
		Frame3DRect(pDC->m_hDC, m_clrActiveHi, m_clrActiveLo, CRect(m_rcHZ[m_ptHZIndex[1].x]),  
		2, TRUE, TRUE, TRUE, TRUE); 
 
	COLORREF clr=pDC->GetTextColor(); 
	pDC->SetTextColor(CLR_HZ); 
	CString strTemp; 
	CFont *pfntOld = NULL; 
	pfntOld = pDC->SelectObject( &fntHZ ); 
	for (int i=0;i<m_nHZSelectColumn+2;i++) 
	{ 
		strTemp.Empty(); 
		if (i==0) 
		{ 
			strTemp=_T("<"); 
		} 
		else if(i==m_nHZSelectColumn+2-1) 
			strTemp=_T(">"); 
		else 
		{ 
			if(m_sShowWord.GetLength()>m_nHZPage*m_nHZSelectColumn+i-1) 
				strTemp=m_sShowWord.GetAt(m_nHZPage*m_nHZSelectColumn+i-1); 
		} 
		pDC->DrawText(strTemp, m_rcHZ[i], DT_SINGLELINE | DT_VCENTER | DT_CENTER); 
		 
	} 
	pDC->SelectObject( pfntOld ); 
	pDC->SetTextColor(clr); 
	fntHZ.DeleteObject(); 
} 
 
void CT9::DrawKeyboard(CDC* pDC) 
{ 
	//确保是有效的绘图环境 
	VERIFY(pDC != NULL && pDC->GetSafeHdc() != NULL); 
 
	CFont   fntDigit;            // 数码管字体 
	CFont	fntInfo; 
	CRect rect( m_rcLayout[0][0] ); 
	int iFontHeight = -1 * rect.Height() /2+2; 
	fntDigit.CreateFont( 
		iFontHeight,    //字体高度 
		0,//iFontWidth, //系统选取字体最佳宽度 
		0,              //倾斜度为0,表示水平 
		0,              //字体倾斜度为0 
		FW_HEAVY,          //字体粗度,400为正常 
		FALSE,          //斜体字 
		0,              //下划线 
		0,              //删除线 
		DEFAULT_CHARSET,        //所用的字符集 
		OUT_STROKE_PRECIS,      //输出粗度为默认值 
		CLIP_STROKE_PRECIS,     //裁减粗度为默认值 
		DRAFT_QUALITY,          //输出质量为默认值 
		DEFAULT_PITCH|FF_DONTCARE,  //字间距和字体系列 
		_T( "Times New Roman" ) //字体名称 Face Name 
		); 
 
	fntInfo.CreateFont( 
		iFontHeight,    //字体高度 
		0,//iFontWidth, //系统选取字体最佳宽度 
		0,              //倾斜度为0,表示水平 
		0,              //字体倾斜度为0 
		FW_HEAVY,          //字体粗度,400为正常 
		FALSE,          //斜体字 
		0,              //下划线 
		0,              //删除线 
		DEFAULT_CHARSET,        //所用的字符集 
		OUT_STROKE_PRECIS,      //输出粗度为默认值 
		CLIP_STROKE_PRECIS,     //裁减粗度为默认值 
		DRAFT_QUALITY,          //输出质量为默认值 
		DEFAULT_PITCH|FF_DONTCARE,  //字间距和字体系列 
		_T( "Arial" ) //字体名称 Face Name 
		); 
 
	COLORREF clr=pDC->GetTextColor(); 
	pDC->SetTextColor(CLR_KEY); 
  	BOOL bIsDigit = FALSE; 
	for (int i = 0; i < m_nRow; i++) 
	{ 
		 
		CString strTmp; 
		for (int j = 0; j < m_nColumn; j++) 
		{ 
			bIsDigit=FALSE; 
			if (m_chLayout[i][j] == m_chEnter) 
			{ 
				strTmp = _T( "确定" );//_T("Enter"); 
			} 
			else if (m_chLayout[i][j] == m_chDel) 
			{ 
				strTmp = _T( "删除" );//_T("Del"); 
			} 
		 
			else if (m_chLayout[i][j] == m_chType) //输入法 
			{ 
				switch(m_kType) 
				{ 
				case Type_PY: 
					strTmp = _T( "拼音" ); 
					break; 
				case Type_ZM: 
					strTmp = _T( "字母" ); 
					break; 
				case Type_SZ: 
					strTmp = _T( "数字" ); 
					break; 
				default: 
					break; 
				} 
				 
			} 
			else if (m_chLayout[i][j] ==m_chSign) 
			{ 
				strTmp=_T("符号"); 
			} 
			else if (m_chLayout[i][j] == m_chCancel) 
			{ 
				strTmp = _T( "取消" );//_T("ESC"); 
			} 
			else 
			{ 
				if(m_kType==Type_SZ) 
					strTmp=m_chLayout[i][j]; 
				else if(m_kType==Type_PY) 
				{ 
					switch(m_chLayout[i][j]) 
					{ 
					case '1': 
						strTmp=_T("1"); 
						break; 
					case '2': 
						bIsDigit=TRUE; 
						strTmp=_T("2\nABC"); 
						break; 
					case '3': 
						bIsDigit=TRUE; 
						strTmp=_T("3\nDEF"); 
						break; 
					case '4': 
						bIsDigit=TRUE; 
						strTmp=_T("4\nGHI"); 
						break; 
					case '5': 
						bIsDigit=TRUE; 
						strTmp=_T("5\nJKL"); 
						break; 
					case '6': 
						bIsDigit=TRUE; 
						strTmp=_T("6\nMNO"); 
						break; 
					case '7': 
						bIsDigit=TRUE; 
						strTmp=_T("7\nPQRS"); 
						break; 
					case '8': 
						bIsDigit=TRUE; 
						strTmp=_T("8\nTUV"); 
						break; 
					case '9': 
						bIsDigit=TRUE; 
						strTmp=_T("9\nWXYZ"); 
						break; 
					case '0': 
						strTmp=_T("0"); 
						break; 
					} 
				} 
				else if(m_kType==Type_ZM) 
				{ 
					switch(m_chLayout[i][j]) 
					{ 
					case '1': 
						strTmp=_T("1"); 
						break; 
					case '2': 
						strTmp=_T("ABC"); 
						break; 
					case '3': 
						strTmp=_T("DEF"); 
						break; 
					case '4': 
						strTmp=_T("GHI"); 
						break; 
					case '5': 
						strTmp=_T("JKL"); 
						break; 
					case '6': 
						strTmp=_T("MNO"); 
						break; 
					case '7': 
						strTmp=_T("PQRS"); 
						break; 
					case '8': 
						strTmp=_T("TUV"); 
						break; 
					case '9': 
						strTmp=_T("WXYZ"); 
						break; 
					case '0': 
						strTmp=_T("0"); 
						break; 
					} 
			} 
		} 
 
 
			Frame3DRect(pDC->m_hDC, m_clrHi, m_clrLo, CRect(m_rcLayout[i][j]), 2, TRUE, TRUE, TRUE, TRUE); 
			if ( bIsDigit ) 
			{ 
				CFont *pfntOld = NULL; 
				pfntOld = pDC->SelectObject( &fntDigit ); 
				pDC->DrawText(strTmp, &m_rcLayout[i][j], DT_WORDBREAK|DT_CENTER); 
				pDC->SelectObject( pfntOld ); 
			} 
			else 
			{ 
				CFont *pfntOld = NULL; 
				pfntOld = pDC->SelectObject( &fntInfo ); 
				pDC->DrawText(strTmp, &m_rcLayout[i][j], DT_SINGLELINE | DT_VCENTER | DT_CENTER); 
				pDC->SelectObject( pfntOld ); 
			} 
			 
		} 
	} 
	pDC->SetTextColor(clr); 
	fntDigit.DeleteObject();             // 默认字体 
	fntInfo.DeleteObject(); 
} 
 
void CT9::Frame3D(HDC hDC, COLORREF clrHi, COLORREF clrLo, POINT& ptLeftTop, POINT& ptRightBottom, int iFrameWid,  
			 BOOL bDrawLeft, BOOL bDrawTop, BOOL bDrawRight, BOOL bDrawBottom) 
{ 
	HPEN hPen; 
	HPEN hPen2; 
	HPEN hPenOld; 
 
	hPen = ::CreatePen(PS_SOLID, 1, clrHi); 
	hPenOld = (HPEN)::SelectObject(hDC, hPen); 
 
	int tx = ptLeftTop.x; 
	int ty = ptLeftTop.y; 
	int lx = ptRightBottom.x; 
	int ly = ptRightBottom.y; 
	int brdWid = iFrameWid; 
 
	while (1) 
	{ 
		if (bDrawTop) 
		{ 
			::MoveToEx(hDC, tx, ty, NULL); 
			::LineTo(hDC, lx, ty); 
		} 
 
		if (bDrawLeft) 
		{ 
			::MoveToEx(hDC, tx, ty, NULL); 
			::LineTo(hDC, tx, ly); 
		} 
 
		--tx; 
		--ty; 
		++lx; 
		++ly; 
		--brdWid; 
		if (0 == brdWid) 
		{ 
			break; 
		} 
	} 
 
	hPen2 = (HPEN)::CreatePen(PS_SOLID, 1, clrLo); 
	hPen = (HPEN)::SelectObject(hDC, hPen2); 
	::DeleteObject(hPen); 
 
	tx = ptLeftTop.x; 
	ty = ptLeftTop.y; 
	lx = ptRightBottom.x; 
	ly = ptRightBottom.y; 
	brdWid = iFrameWid; 
 
	while (1) 
	{ 
		if (bDrawBottom) 
		{ 
			::MoveToEx(hDC, tx, ly, NULL); 
			::LineTo(hDC, lx, ly); 
		} 
 
		if (bDrawRight) 
		{ 
			::MoveToEx(hDC, lx, ty, NULL); 
			++ly; 
			::LineTo(hDC, lx, ly); 
			--ly; 
		} 
 
		--tx; 
		--ty; 
		++lx; 
		++ly; 
 
		--brdWid; 
		if (0 == brdWid) 
		{ 
			break; 
		} 
	} 
 
	::SelectObject(hDC, hPenOld); 
	::DeleteObject(hPen2); 
} 
 
void CT9::Frame3DRect(HDC hDC, COLORREF clrHi, COLORREF clrLo, CRect& rcFrame,  
				 int iFrameWid, BOOL bDrawLeft /*= TRUE*/, BOOL bDrawTop /*= TRUE*/, BOOL bDrawRight /*= TRUE*/, BOOL bDrawBottom /*= TRUE*/) 
{ 
	POINT ptLeftTop; 
	ptLeftTop.x = rcFrame.left; 
	ptLeftTop.y = rcFrame.top; 
	POINT ptBottomRight; 
	ptBottomRight.x = rcFrame.right; 
	ptBottomRight.y = rcFrame.bottom; 
	Frame3D(hDC, clrHi, clrLo, ptLeftTop, ptBottomRight,1,  
		bDrawLeft, bDrawTop, bDrawRight, bDrawBottom); 
 
	ptLeftTop.x = rcFrame.left + 2; 
	ptLeftTop.y = rcFrame.top + 2; 
	ptBottomRight.x = rcFrame.right -2; 
	ptBottomRight.y = rcFrame.bottom - 2; 
	Frame3D(hDC, clrLo, clrHi, ptLeftTop, ptBottomRight, 1,  
		bDrawLeft, bDrawTop, bDrawRight, bDrawBottom);     
} 
 
 
void CT9::OnSize(UINT nType, int cx, int cy) 
{ 
	CDialog::OnSize(nType, cx, cy); 
 
	if (cy < (m_nRow - 1+2) * m_nSpace || cx < (m_nColumn - 1) * m_nSpace) 
	{ 
		return; 
	} 
 
	FillRectLayoutArray(cx, cy); 
	Invalidate(); 
} 
 
void CT9::FillRectLayoutArray(int cx, int cy) 
{ 
 
	int m_nSelectColumn=8; 
	int nWid1=(cx - m_nSpace * (m_nSelectColumn - 1)) / m_nSelectColumn; 
	int nWid = (cx - m_nSpace * (m_nColumn - 1)) / m_nColumn; 
	int nHei = (cy - m_nSpace * (m_nRow+2 - 1)) / (m_nRow+2); 
 
	int j = 0; 
	int i=0; 
 
	i=1; 
	for (j=0;j<m_nHZSelectColumn+2;j++) 
	{ 
		m_rcHZ[j].left=j*(nWid1+m_nSpace)+m_nSpace; 
		m_rcHZ[j].top=i*(nHei+m_nSpace)+m_nSpace; 
		m_rcHZ[j].right=m_rcHZ[j].left+nWid1; 
		m_rcHZ[j].bottom=m_rcHZ[j].top+nHei; 
	} 
	m_rcHZ[j-1].right=cx; 
 
	i=0; 
	for (j=0;j<m_nPYSelectColumn+2;j++) 
	{ 
		m_rcPY[j].top=i*(nHei+m_nSpace)+m_nSpace; 
		m_rcPY[j].bottom=m_rcPY[j].top+nHei; 
	} 
	m_rcPY[0].left=m_rcHZ[0].left; 
	m_rcPY[0].right=m_rcHZ[0].right; 
 
	m_rcPY[1].left=m_rcHZ[1].left; 
	m_rcPY[1].right=m_rcHZ[2].right; 
 
	m_rcPY[2].left=m_rcHZ[3].left; 
	m_rcPY[2].right=m_rcHZ[4].right; 
 
	m_rcPY[3].left=m_rcHZ[5].left; 
	m_rcPY[3].right=m_rcHZ[6].right; 
 
	m_rcPY[4].left=m_rcHZ[7].left; 
	m_rcPY[4].right=m_rcHZ[7].right; 
	for ( i = 2; i < m_nRow+2; i++) 
	{ 
		for (j = 0; j < m_nColumn; j++) 
		{ 
			m_rcLayout[i-2][j].left = j * (nWid + m_nSpace) + m_nSpace; 
			m_rcLayout[i-2][j].top = i * (nHei + m_nSpace) + m_nSpace; 
			m_rcLayout[i-2][j].right = m_rcLayout[i-2][j].left + nWid; 
			m_rcLayout[i-2][j].bottom = m_rcLayout[i-2][j].top + nHei; 
			if(i-2==m_nRow-1) 
				m_rcLayout[i-2][j].bottom = cy; //消除空白 
		} 
		m_rcLayout[i-2][j-1].right = cx; //消除空白 
		 
		 
	}	 
	 
 
	m_bValidRectArray = TRUE; 
} 
 
void CT9::DrawSelectedKey(CDC* pDC) 
{ 
	//确保是有效的绘图环境 
	VERIFY(pDC != NULL && pDC->GetSafeHdc() != NULL); 
 
	if (m_ptKeyboardIndex[0]!=CPoint(-1,-1)  ) 
	{ 
 
		Frame3DRect(pDC->m_hDC, m_clrHi, m_clrLo, CRect(m_rcLayout[m_ptKeyboardIndex[0].x][m_ptKeyboardIndex[0].y]), 
			2, TRUE, TRUE, TRUE, TRUE); 
	} 
	if(m_ptKeyboardIndex[1]!=CPoint(-1,-1)) 
		Frame3DRect(pDC->m_hDC, m_clrActiveHi, m_clrActiveLo, CRect(m_rcLayout[m_ptKeyboardIndex[1].x][m_ptKeyboardIndex[1].y]),  
			2, TRUE, TRUE, TRUE, TRUE); 
 
	 
} 
 
BOOL CT9::OnEraseBkgnd(CDC* pDC) 
{ 
	CRect rc; 
	GetClientRect(&rc); 
	pDC->FillSolidRect(&rc, CLR_BK);	 
 
	return TRUE;		 
} 
 
void CT9::OnLButtonDown(UINT nFlags, CPoint point) 
{ 
	OnMouseDown(point); 
 
	CDialog::OnLButtonDown(nFlags, point); 
} 
 
void CT9::OnMouseDown( const CPoint point ) 
{ 
	for (int i=0;i<m_nRow;i++) 
	{ 
		for (int j=0;j<m_nColumn;j++) 
		{ 
			if (PtInRect(&m_rcLayout[i][j],point)) 
			{ 
				if(m_ptKeyboardIndex[1]!=CPoint(-1,-1)) 
					m_ptKeyboardIndex[0]=m_ptKeyboardIndex[1]; 
				m_ptKeyboardIndex[1]=CPoint(i,j); 
				goto KeyboardLoop; 
			} 
		} 
	} 
	 
	 
 
	for (int i=0;i<m_nPYSelectColumn+2;i++) 
	{ 
		if (PtInRect(&m_rcPY[i],point)) 
		{ 
			if(m_ptPYIndex[1]!=CPoint(-1,-1)) 
				m_ptPYIndex[0]=m_ptPYIndex[1]; 
			m_ptPYIndex[1].x=i; 
			goto PYLoop; 
		} 
	} 
	 
 
 
	for (int i=0;i<m_nHZSelectColumn+2;i++) 
	{ 
		if (PtInRect(&m_rcHZ[i],point)) 
		{ 
			if(m_ptHZIndex[1]!=CPoint(-1,-1)) 
				m_ptHZIndex[0]=m_ptHZIndex[1]; 
			m_ptHZIndex[1].x=i; 
			goto HZLoop; 
		} 
	} 
 
	m_ptKeyboardIndex[1]=CPoint(-1,-1); 
	m_ptPYIndex[1]=CPoint(-1,-1); 
	m_ptHZIndex[1]=CPoint(-1,-1); 
	 
	return; 
 
 
KeyboardLoop: 
	GetKeyBoardChar(); 
 
	InvalidateRect(&m_rcLayout[m_ptKeyboardIndex[1].x][m_ptKeyboardIndex[1].y]); 
	if (m_ptKeyboardIndex[0] != CPoint(-1,-1) && m_ptKeyboardIndex[0]!=m_ptKeyboardIndex[1]) 
	{ 
		InvalidateRect(&m_rcLayout[m_ptKeyboardIndex[0].x][m_ptKeyboardIndex[0].y]); 
	}	 
	return; 
PYLoop: 
	GetPYInputChar(); 
	InvalidateRect(&m_rcPY[m_ptPYIndex[1].x]); 
	if (m_ptPYIndex[0] != CPoint(-1,-1) && m_ptPYIndex[0]!=m_ptPYIndex[1]) 
	{ 
		InvalidateRect(&m_rcPY[m_ptPYIndex[0].x]); 
	}	 
	return; 
 
HZLoop: 
	GetHZInputChar(); 
	InvalidateRect(&m_rcHZ[m_ptHZIndex[1].x]); 
	if (m_ptHZIndex[0] != CPoint(-1,-1) && m_ptHZIndex[0]!=m_ptHZIndex[1]) 
	{ 
		InvalidateRect(&m_rcHZ[m_ptHZIndex[0].x]); 
	}	 
	return; 
} 
 
void CT9::ClearPYSelectWord() 
{ 
	m_nPYPage=0; 
	m_iKeyPress=0; 
	m_iPYNum=0; 
	m_iPYNumOld=0; 
	for (int i=0;i<20;i++) 
	{ 
		m_arrSelectWord[i].Empty(); 
		if (i<6) 
		{ 
			m_arrInputWord[i].Empty(); 
		} 
	} 
} 
 
void CT9::ClearShowWord() 
{ 
	m_nHZPage=0; 
	m_iKeyPress=0; 
	m_iPYNum=0; 
	m_iPYNumOld=0; 
	m_sShowWord.Empty(); 
} 
 
void CT9::GetPYInputChar() 
{ 
	CString temp; 
	int nIndex; 
	if (m_ptPYIndex[1]!=CPoint(-1,-1)) 
	{ 
		if (m_ptPYIndex[1].x==0) 
		{ 
			if(m_nPYPage>0) 
				m_nPYPage--; 
			nIndex=m_nPYSelectColumn*m_nPYPage; 
		} 
		else if (m_ptPYIndex[1].x==m_nPYSelectColumn-1+2) 
		{ 
			int m_nMaxCount=(m_iPYNum-1)/m_nPYSelectColumn; 
			if (m_nPYPage<m_nMaxCount) 
			{ 
				m_nPYPage++; 
				 
			} 
			nIndex=m_nPYSelectColumn*m_nPYPage; 
		} 
		//否则点击拼音 
		else 
		{ 
			 nIndex=m_ptPYIndex[1].x+m_nPYSelectColumn*m_nPYPage-1; 
		} 
	} 
	else 
		nIndex=0; 
	if (nIndex>=m_iPYNum|| nIndex<0) 
	{ 
		temp.Empty(); 
	} 
	else 
	{ 
		temp=m_arrSelectWord[nIndex]; 
		m_sShowWord=pZk->GetInputString(temp); 
	} 
	RefrshHZRect(); 
	RefrshPYRect(); 
} 
 
void CT9::GetHZInputChar() 
{ 
	if (m_ptHZIndex[1]!=CPoint(-1,-1)) 
	{ 
		if (m_ptHZIndex[1].x==0) 
		{ 
			if(m_nHZPage>0) 
				m_nHZPage--; 
		} 
		else if (m_ptHZIndex[1].x==m_nHZSelectColumn-1+2) 
		{ 
			int m_nMaxCount=(m_sShowWord.GetLength()-1)/m_nHZSelectColumn; 
			if (m_nHZPage<m_nMaxCount) 
			{ 
				m_nHZPage++; 
			} 
		} 
		//选中汉字 
		else 
		{ 
			int nIndex=m_nHZSelectColumn*m_nHZPage+m_ptHZIndex[1].x-1; 
			CString temp; 
			temp.Empty(); 
			if(nIndex<m_sShowWord.GetLength()) 
				temp=m_sShowWord.GetAt(nIndex); 
			if(temp.IsEmpty()==false) 
			{ 
				CString str; 
				m_peditAcceptInput->GetWindowText(str); 
				m_peditAcceptInput->SetWindowText(str+temp); 
				m_ptPYIndex[1]=m_ptHZIndex[1]=CPoint(-1,-1); 
				ClearPYSelectWord();		//清空拼音 
				ClearShowWord();				//清空汉字 
			} 
		} 
	} 
	RefrshHZRect(); 
	RefrshPYRect(); 
 
	 
} 
 
void CT9::GetKeyBoardChar() 
{ 
 
	//处理输入法 
	if(m_ptKeyboardIndex[1]!=CPoint(-1,-1)) 
		ConfigT9(m_chLayout[m_ptKeyboardIndex[1].x][m_ptKeyboardIndex[1].y]); 
	 
} 
 
void CT9::RefrshPYRect() 
{ 
	 
	CRect rc; 
	rc.TopLeft()=m_rcPY[0].TopLeft(); 
	rc.BottomRight()=m_rcPY[m_nPYSelectColumn+2-1].BottomRight(); 
	InvalidateRect(rc); 
 
} 
 
void CT9::RefrshHZRect() 
{ 
	CRect rc; 
	rc.TopLeft()=m_rcHZ[0].TopLeft(); 
	rc.BottomRight()=m_rcHZ[m_nHZSelectColumn+2-1].BottomRight(); 
	InvalidateRect(rc); 
} 
 
void CT9::T9TypeOperate() 
{ 
 
	Del123All(); 
	DelABC(); 
	DelT9All(); 
	switch(m_kType) 
	{ 
	case Type_PY: 
		m_kType=Type_ZM; 
		break; 
	case Type_ZM: 
		m_kType=Type_SZ; 
		break; 
	case Type_SZ: 
		m_kType=Type_PY; 
		break; 
	} 
	Invalidate(); 
} 
 
void CT9::Del123All() 
{ 
	 
} 
 
void CT9::DelABC() 
{ 
	m_sInputWord.Empty(); 
} 
 
void CT9::DelT9All() 
{ 
	m_iKeyPress = 0; 
	m_iPYNum = 0; 
	m_iPYNumOld = 0; 
	m_sShowWord.Empty(); 
 
	for(int i=0;i<20;i++) 
	{ 
		if(i < 6) 
		{ 
			m_arrInputWord[i].Empty(); 
		} 
		m_arrSelectWord[i].Empty(); 
	} 
} 
 
void CT9::ConfigT9( TCHAR input ) 
{ 
	//切换输入法 
	if (input==m_chType) 
	{ 
		T9TypeOperate(); 
		return; 
	} 
	//输入符号 
	if (input==m_chSign) 
	{ 
		OperateFH(); 
		return; 
	} 
	//确定? 
	if (input==m_chEnter) 
	{ 
		PostMessage(WM_CLOSE); 
		return; 
	} 
	//取消? 
	if (input==m_chCancel) 
	{ 
		m_peditAcceptInput->SetWindowTextW(m_strOrinalNumber); 
		PostMessage(WM_CLOSE); 
		return; 
	} 
	//删除? 
	if (input==m_chDel) 
	{ 
		if (m_kType!=Type_PY) 
		{ 
			if (m_sShowWord.IsEmpty()==false) 
			{ 
				ClearShowWord(); 
				RefrshHZRect(); 
				return; 
			} 
			else 
			{ 
				m_peditAcceptInput->PostMessage(WM_KEYDOWN,VK_END,NULL); 
				m_peditAcceptInput->PostMessage(WM_CHAR,VK_BACK,NULL); 
				return; 
			} 
		} 
		//拼音输入法 
		else 
		{ 
			DelInputWord(); 
			GetPYInputChar(); 
			if (m_iPYNum==0) 
			{ 
				m_peditAcceptInput->PostMessage(WM_KEYDOWN,VK_END,NULL); 
				m_peditAcceptInput->PostMessage(WM_CHAR,VK_BACK,NULL); 
				 
			} 
			return; 
 
		} 
	} 
	//是否输入数字? 
	if (m_kType==Type_SZ) 
	{ 
		Operate123(input); 
	} 
	else 
	{ 
		m_sInputWord.Empty(); 
		switch(input) 
		{ 
		case '1': 
			return; 
		case '2': 
			m_sInputWord = _T("abc"); 
			break; 
		case '3': 
			m_sInputWord = _T("def"); 
			break; 
		case '4': 
			m_sInputWord = _T("ghi"); 
			break; 
		case '5': 
			m_sInputWord = _T("jkl"); 
			break; 
		case '6': 
			m_sInputWord = _T("mno"); 
			break; 
		case '7': 
			m_sInputWord = _T("pqrs"); 
			break; 
		case '8': 
			m_sInputWord = _T("tuv"); 
			break; 
		case '9': 
			m_sInputWord =_T("wxyz"); 
			break; 
		default: 
			break; 
		} 
 
		if(input == '0') 
		{ 
			 
			return; 
		} 
		if (m_kType==Type_ZM) 
		{ 
			OperateABC(); 
			return; 
		} 
		if(m_iKeyPress < 6) 
		{ 
			m_arrInputWord[m_iKeyPress] = m_sInputWord; //保存当前输入至字符串数组 
 
			m_iKeyPress++; 
 
		} 
		else 
		{ 
			return ; 
		} 
		if(m_kType ==Type_PY) 
		{ 
 
			OperateT9(); 
		} 
	} 
} 
 
void CT9::OperateFH() 
{ 
	 
	ClearPYSelectWord(); 
	ClearShowWord(); 
	m_sShowWord=pZk->GetInputString(_T("*")); 
	RefrshPYRect(); 
	RefrshHZRect(); 
} 
 
void CT9::RefrshKeyBoardRect() 
{ 
	CRect rc; 
	rc.TopLeft()=m_rcLayout[0][0].TopLeft(); 
	rc.BottomRight()=m_rcLayout[m_nRow-1][m_nColumn-1].BottomRight(); 
	InvalidateRect(rc); 
} 
 
void CT9::Operate123(WCHAR input) 
{ 
	if(input>='0' && input<='9') 
	{ 
		m_peditAcceptInput->PostMessage(WM_KEYDOWN,VK_END,NULL); 
		m_peditAcceptInput->PostMessage(WM_CHAR,input,NULL); 
	} 
		 
} 
 
void CT9::OperateT9() 
{ 
	CString strTemp; 
	CString arrTemp[20]; 
	int count1,count2;//count1为外循环(上次可用拼音组合次数),count2为内循环(当前按键字母数) 
	if(m_iKeyPress == 1)//如初次按键则赋外循环为1,只判断当前按键字母的拼音组合 
	{ 
		count1 = 1; 
	} 
	else 
	{ 
		count1 = m_iPYNumOld; //外循环次数为上次可用拼音组合 
	} 
	count2 = m_arrInputWord[m_iKeyPress-1].GetLength(); 
 
	CString str1,str2,temp; 
	m_iPYNum = 0; //当前可用拼音组合总数(用于当前可用拼音组合数组下标) 
 
	for(int m=0;m<count1;m++) 
	{ 
		str1 = m_arrSelectWord[m]; 
 
		for(int n=0;n<count2;n++) 
		{ 
			str2 = m_arrInputWord[m_iKeyPress-1].Mid(n,1); 
 
			temp = str1 + str2; 
			if(!pZk->GetInputString(temp).IsEmpty()) 
			{ 
				arrTemp[m_iPYNum] = temp; 
				m_iPYNum++; //可用拼音组合计数 
			} 
		} 
	} 
 
	if(m_iPYNum <= 0) 
	{ 
		for(int i=m_iKeyPress-1;i>-1;i--) 
		{ 
			if(m_arrInputWord[i] != _T("")) 
			{ 
				m_arrInputWord[i].Empty(); 
				m_iKeyPress--; 
				return; 
			} 
		} 
	} 
	m_iPYNumOld = m_iPYNum; 
	//先清空数组,再从(临时)可用拼音数组保存至(成员变量)可用拼音组合数组 
	for(int i=0;i<20;i++) 
	{ 
		m_arrSelectWord[i].Empty(); 
 
		m_arrSelectWord[i] = arrTemp[i]; 
	} 
	GetPYInputChar(); 
 
} 
 
void CT9::OperateABC() 
{ 
	 
	if (m_sInputWord.IsEmpty()==false) 
	{ 
		ClearShowWord(); 
		int nCount=m_sInputWord.GetLength(); 
		CString str=m_sInputWord; 
		str.MakeUpper(); 
		for (int i=0;i<nCount;i++) 
		{ 
			m_sShowWord+=m_sInputWord.GetAt(i); 
			m_sShowWord+=str.GetAt(i); 
		} 
		RefrshHZRect(); 
	} 
	 
} 
 
void CT9::DelInputWord() 
{ 
	for(int i=m_iKeyPress-1;i>-1;i--) 
	{ 
		if(m_arrInputWord[i] != _T("")) 
		{ 
			m_arrInputWord[i].Empty(); 
			m_iKeyPress--; 
			if(m_iKeyPress == 0) 
			{ 
				m_sShowWord = _T(""); 
				m_iKeyPress = 0; 
				m_iPYNum = 0; 
 
			} 
			for(int z=0;z<20;z++) 
			{ 
				m_arrSelectWord[z].Empty(); 
			} 
 
 
			CString strTemp; 
			CString arrTemp[20]; 
			int count1,count2;//count1为外循环(上次可用拼音组合次数),count2为内循环(当前按键字母数) 
			for(int j=1;j<=m_iKeyPress;j++) 
			{ 
 
				if(j == 1)//如初次按键则赋外循环为1,只判断当前按键字母的拼音组合 
				{ 
					count1 = 1; 
				} 
				else 
				{ 
					count1 = m_iPYNumOld; //外循环次数为上次可用拼音组合 
				} 
				count2 = m_arrInputWord[j-1].GetLength(); 
 
				CString str1,str2,temp; 
 
				m_iPYNum = 0; //当前可用拼音组合总数(用于当前可用拼音组合数组下标) 
 
				for(int m=0;m<count1;m++) 
				{ 
					str1 = m_arrSelectWord[m]; 
 
					for(int n=0;n<count2;n++) 
					{ 
						str2 = m_arrInputWord[j-1].Mid(n,1); 
 
						temp = str1 + str2; 
						if( pZk->GetInputString(temp) != _T("")) 
						{ 
							arrTemp[m_iPYNum] = temp; 
 
							m_iPYNum++; //可用拼音组合计数 
						} 
					} 
				} 
 
				m_iPYNumOld = m_iPYNum; 
				//先清空数组,再从(临时)可用拼音数组保存至(成员变量)可用拼音组合数组 
				for(int i=0;i<20;i++) 
				{ 
					m_arrSelectWord[i] = _T(""); 
 
					m_arrSelectWord[i] = arrTemp[i]; 
				} 
			} 
			return ; 
		} 
	} 
}