www.pudn.com > T9InPut.rar > setcontrol.h, change:2011-02-21,size:7458b


#pragma once 
 
#include<ctype.h> 
//#include "ColorStatic.h" 
// CControl 对话框 
 
class CControl : public CStatic 
{ 
public: 
	//CWnd* pWnd; 
	//CDC* pControlDC; //表示控件窗口的设备描述表.DC  
 
//	CColorStatic * m_Static[10]; 
 
	CStatic * m_Static[10]; 
	CString m_sChiWord[255]; 
	CString m_sEngWord[40]; 
	CString m_sShowWord[8]; 
 
	CRect m_rControl; 
	CRect m_rt[12]; 
	CFont * m_pFont; 
	int m_iQC; 
	int m_iShowNum; 
	int m_iWordNum; 
 
	bool m_bIsShow; //保存控件显示状态 
 
	 
 
public: 
	CControl(void);   // 标准构造函数 
	~CControl(void); 
 
 
 
	bool InitCStatic(CRect *rt, CWnd *pParent); //初始化CStatic 
	void ShowCStatic(void); 
	void HideCStatic(void); 
	void DelData(void); //清空数据 
	void SetChiData(CString str); //设置CStatic控件的汉字显示 
	void SetEngData(CString str); //设置CStatic控件的英文显示 
	void SetFHData(CString str); //设置CStatic控件的符号显示 
 
	bool CheckABC(CString str); //检测是否为英文字母 
 
	CRect GetControlRect(void); //返回控件大小 
	CString SelectData(CPoint point,UINT type); //返回点击的数据 
	void PageUp(UINT type); 
	void PageDown(UINT type); 
 
 
 
}; 
 
 
// SetControl.cpp : 实现文件 
// 
 
 
// CControl 对话框 
CControl::CControl(void) 
{ 
 
	m_iQC = 0; 
	m_iShowNum = 8; 
	m_iWordNum = 0; 
 
	m_bIsShow = false; 
 
	for(int i=0;i<10;i++) 
	{ 
		m_sChiWord[i].Empty(); 
	} 
	m_pFont = new CFont; 
	 
	m_pFont->CreateFont(40,0,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,_T("宋体")); 
 
} 
 
CControl::~CControl() 
{ 
} 
 
 
/* 
void  CControl::OnPaint() 
{ 
	CDC* pdc; 
	pdc=this->GetDC(); 
	 
	CRect rect; 
	GetClientRect(&rect); 
 
 
	//CFont *pFont=GetParent()->GetFont();	//获取主窗口的字体 
	CFont *pOldFont; 
	pOldFont=pdc->SelectObject(m_pFont); 
 
	pdc->SetTextColor(RGB(0,130,255)); 
 
	CString strCaption; 
	this->GetWindowText(strCaption);		//获取窗口文本 
 
	pdc->DrawText(strCaption,&rect,DT_CENTER); 
 
	pdc->SelectObject(pOldFont); 
}*/ 
 
 
 
bool CControl::InitCStatic(CRect *rt,CWnd *pParent) 
{ 
	int num = rt->right/10; 
	int right = 0; 
	 
	for(int i=0;i<10;i++) 
	{ 
		m_rt[i].left = num * i + rt->left; 
		m_rt[i].top = rt->top; 
		m_rt[i].right = num + m_rt[i].left; 
		m_rt[i].bottom = 45+ m_rt[i].top; 
 
 
 
// 		m_Static[i] = new CColorStatic(); 
//  
// 		if(!m_Static[i]->Create(_T(""),WS_CHILD|WS_VISIBLE|/*WS_BORDER|*/SS_CENTER,m_rt[i],pParent,i)) 
// 		{ 
// 			return false; 
// 		} 
//  
//  
// 		m_Static[i]->SetTextColor(RGB(0,130,255)); 
// 		m_Static[i]->SetWindowText(_T("")); 
//  
// 		m_Static[i]->ShowWindow(SW_HIDE); 
 
 
		m_Static[i] = new CStatic; 
		if(!m_Static[i]->Create(_T(""),WS_CHILD|WS_VISIBLE|/*WS_BORDER|*/SS_CENTER,m_rt[i],pParent,i)) 
		{ 
			return false; 
		} 
 
		m_Static[i]->SetFont(m_pFont);	 
		 
		m_Static[i]->SetWindowText(_T("")); 
 
		 
		m_Static[i]->ShowWindow(SW_HIDE); 
 
 
		right += m_rt[i].right; 
	} 
 
	//m_bIsShow = true; 
 
 
	m_rControl.left = m_rt[0].left; 
	m_rControl.top = m_rt[0].top; 
	m_rControl.right = right; 
	m_rControl.bottom = m_rt[0].bottom; 
 
 
 
	return true; 
} 
 
void CControl::ShowCStatic(void) 
{ 
	m_bIsShow = true; 
	for(int i=0;i<10;i++) 
	{ 
		m_Static[i]->ShowWindow(SW_SHOW); 
 
	} 
} 
 
void CControl::HideCStatic(void) 
{ 
	m_bIsShow = false; 
	for(int i=0;i<10;i++) 
	{ 
		m_Static[i]->ShowWindow(SW_HIDE); 
	} 
} 
 
void CControl::DelData(void) 
{ 
	for(int i=0;i<255;i++) 
	{ 
		if(i>0 && i<9) 
		{ 
			m_Static[i]->SetWindowText(_T("")); 
		} 
		if(i<9) 
		{ 
			m_sEngWord[i].Empty(); 
		} 
		m_sChiWord[i].Empty(); 
	} 
} 
 
void CControl::SetFHData(CString str) 
{ 
 
 
	m_iQC = 0; //显示符号起始值初始化 
	 
	m_bIsShow = true; 
 
	m_iWordNum = str.GetLength(); 
	int index = m_iWordNum; 
	if(index < 10) 
	{ 
		index = 10; 
	} 
	 
	for(int i=m_iQC;i<index;i++) 
	{ 
		m_sChiWord[i] = str.Mid(i,1); 
		m_sEngWord[i] = m_sChiWord[i]; 
 
		if(i<10) 
		{ 
			if(i == 0) 
			{ 
				m_Static[i]->SetWindowText(_T("<")); 
			} 
			if(i>0 && i < 9) 
			{ 
				m_sShowWord[i-1] = m_sChiWord[i-1]; 
				m_Static[i]->SetWindowText(m_sShowWord[i-1]); 
			} 
			if(i == 9) 
			{ 
				m_Static[i]->SetWindowText(_T(">")); 
			} 
			m_Static[i]->ShowWindow(SW_SHOW); 
		} 
	} 
} 
 
void CControl::SetEngData(CString str) 
{ 
	m_iQC = 0; //显示汉字起始值初始化 
	m_bIsShow = true; 
 
	int index = 0; 
	int count = str.GetLength(); 
	 
	for(int i=0;i<10;i++) 
	{ 
		 
		if(i == 0) 
		{ 
			 
			m_Static[i]->SetWindowText(_T("<")); 
		} 
		if(i > 0 && i < count + 1) 
		{ 
			m_sEngWord[index] = str.Mid(i-1,1); 
			int num = m_sEngWord[index].GetLength(); 
			WCHAR *chTemp = m_sEngWord[index].GetBuffer(num); 
			WCHAR chBig = *chTemp + 'A' - 'a'; //转小写字母为大写字母 
			m_sEngWord[i-1].ReleaseBuffer(); 
			m_sEngWord[index + 1] = chBig; 
			index += 2; 
		} 
		if(i > 0 && i < count * 2 + 1) 
		{ 
			 
			m_sShowWord[i-1] = m_sEngWord[i-1]; 
			 
			m_Static[i]->SetWindowText(m_sShowWord[i-1]); 
 
		} 
		if(i == 9) 
		{ 
			 
			m_Static[i]->SetWindowText(_T(">")); 
		} 
		m_Static[i]->ShowWindow(SW_SHOW); 
	} 
 
} 
 
void CControl::SetChiData(CString str) 
{	 
	m_iQC = 0; //显示汉字起始值初始化 
 
	m_iWordNum = str.GetLength(); 
 
 
	int index = m_iWordNum; 
	if(index < 10) 
	{ 
		index = 10; 
	} 
	 
	for(int i=m_iQC;i<index;i++) 
	{ 
		if(i > m_iWordNum) 
		{ 
			break; 
		} 
		m_sChiWord[i] = str.Mid(i,1); 
		 
		if(i == 0) 
		{ 
			m_Static[i]->SetWindowText(_T("<")); 
		} 
		if(i>0 && i < 9) 
		{ 
			m_sShowWord[i-1] = m_sChiWord[i-1]; 
			m_Static[i]->SetWindowText(m_sShowWord[i-1]); 
		} 
		if(i == 9) 
		{ 
			m_Static[i]->SetWindowText(_T(">")); 
		} 
	} 
} 
 
void CControl::PageUp(UINT type) 
{ 
	m_iQC -= 8; 
	if(m_iQC < 0) 
	{ 
		m_iQC += 8; 
		//AfxMessageBox("已至起始页"); 
		return; 
	} 
	for(int i=0;i<10;i++) 
	{ 
		if(i<8) 
		{ 
			 
			m_Static[i+1]->SetWindowText(m_sChiWord[i+m_iQC]); 
		} 
	} 
} 
 
void CControl::PageDown(UINT type) 
{ 
	if(type == 1) //当输入为英文字母时,因不足二页,禁止翻页; 
	{ 
		if(CheckABC(m_sEngWord[0])) 
		{ 
			return ; 
		} 
	} 
 
	m_iQC += 8; 
	if(m_iQC >= m_iWordNum) 
	{ 
		m_iQC -= 8; 
		//AfxMessageBox("已至尾页"); 
		return; 
	} 
	for(int i=0;i<10;i++) 
	{ 
		if(i<8) 
		{ 
			m_Static[i+1]->SetWindowText(m_sChiWord[i+m_iQC]); 
		} 
	} 
} 
 
CRect CControl::GetControlRect(void) 
{ 
	return m_rControl; 
} 
 
CString CControl::SelectData(CPoint point,UINT type) 
{ 
	CString strData = _T(""); 
	for(int i=0;i<10;i++) 
	{ 
		if(point.x > m_rt[i].left && point.y > m_rt[i].top && point.x < m_rt[i].right && point.y < m_rt[i].bottom) 
		{ 
			if(i>0 && i<9) 
			{ 
				if(type == 2) 
				{ 
					strData = m_sChiWord[i-1+m_iQC]; 
					return strData; 
				} 
				if(type == 1) 
				{ 
					if(CheckABC(m_sEngWord[i-1+m_iQC])) 
					{ 
						strData = m_sEngWord[i-1+m_iQC]; 
						return strData; 
					} 
					if(!CheckABC(m_sEngWord[0])) 
					{ 
						strData = m_sEngWord[i-1+m_iQC]; 
						return strData; 
					} 
				} 
				if(type == 0) 
				{ 
					strData = m_sEngWord[i-1+m_iQC]; 
					return strData; 
				} 
			} 
			if(i == 0) 
			{ 
				PageUp(type); 
			} 
			if(i == 9) 
			{ 
				PageDown(type); 
			} 
			return strData; 
		} 
	} 
	return strData; 
} 
 
bool CControl::CheckABC(CString str) 
{ 
	int num = str.GetLength(); 
	WCHAR* chTemp = str.GetBuffer(num + 1); 
	WCHAR temp = *chTemp; 
	if(islower(temp) || isupper(temp)) 
	{ 
		str.ReleaseBuffer(); 
		return true; 
	} 
	str.ReleaseBuffer(); 
	return false; 
}