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

📄 keychar.cpp

📁 数据结构中的多项式相加问题
💻 CPP
字号:
// KeyChar.cpp: implementation of the CKeyChar class.
//
//////////////////////////////////////////////////////////////////////

#include "KeyChar.h"
#include "string.h"
#include "iostream.h"
#include "conio.h"
#include "stdio.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CKeyChar::CKeyChar()
{
    m_nStyle=KEY_ANY;
	m_npSpecial=NULL;
	m_nMaxChar=0;
	m_nCount=0;
	m_i=-1;
	m_chpSpecial=NULL;
	m_strpString=NULL;
}

CKeyChar::~CKeyChar()
{
	delete [] m_npSpecial;
	delete [] m_chpSpecial;
}

void CKeyChar::SetStyle(int Long,int Style,int * Special,int Count)
{
	
	if(m_npSpecial)
		delete [] m_npSpecial;
	if(m_strpString)
		delete [] m_strpString;
	m_npSpecial=new int[Count];
	for(int i=0;i<Count;i++)
		m_npSpecial[i]=Special[i];
	m_nMaxChar=Long;
	m_strpString=new char[Long+1];
	m_strpString[0]=0;
	m_nCount=Count;
	m_nStyle=Style;
	m_i=-1;
	m_nStyle=(Style & 0xFFFFFFE7)|0x00000010;
}
void CKeyChar::SetStyle(int Long,int Style,char * Special)
{
	if(m_chpSpecial)
		delete [] m_chpSpecial;
	if(m_strpString)
		delete [] m_strpString;
	m_chpSpecial=new char[strlen(Special)+1];
	strcpy(m_chpSpecial,Special);
	m_nMaxChar=Long;
	m_strpString=new char[Long+1];
	m_strpString[0]=0;
	m_nStyle=(Style & 0xFFFFFFE7)|0x00000008;
	m_i=-1;
}

int  CKeyChar::GetKey()
{
	int value;
    value=HitKey();
	if(!value)
		return 0;
	if(value==KEY_BACKSPACE && m_i>=0)
	{
		printf("\b ");
		m_strpString[m_i]='\0';
		m_i--;
	}
	if(value==KEY_ENTER)
		return value;
	if(value>128)
		return value;
	if(m_i<m_nMaxChar && value && value!=KEY_BACKSPACE)
	{
		printf("%c",value);
		m_i++;
	    m_strpString[m_i]=value;
		m_strpString[m_i+1]='\0';
	}
	printf("\r%s",m_strpString);
	return 0;
}

void CKeyChar::SetStar()
{
	m_i=-1;
	m_strpString[0]=0;
}

/*void CKeyChar::GetKey(int & Value)
{

}

void CKeyChar::GetKey(double & Value)
{
}
void CKeyChar::GetKey(char & Value)
{
}*/

void CKeyChar::GetKey(char * Value)
{
	strcpy(Value,m_strpString);
}
/*
void CKeyChar::GetKey(int * Value,int & Long)
{
}
void CKeyChar::GetKey(double * Value,int & Long)
{
}
*/
int  CKeyChar::HitKey()
{
	int value=0;
	int i;
	if(kbhit())
	{
		value=getch();
		if(value==224 || value==0)
			value+=getch();
	}
	if((KEY_NUMBER & m_nStyle) && value>='0'&&value<='9')
	    return value;
    if((KEY_LETTER & m_nStyle) &&(value>='a'&&value<='z' || value>='A'&&value<='Z'))
	    return value;
	if((KEY_SPACE & m_nStyle) && value==' ')
		return value;
	if(KEY_SPECIAL_CHAR & m_nStyle)
		for(i=0;i<strlen(m_chpSpecial);i++)
			if(value==m_chpSpecial[i])
		        return value;
	if(KEY_SPECIAL_INT & m_nStyle)
	{
		for(i=0;i<m_nCount;i++)
			if(value==m_npSpecial[i])
		        return value;
	}
	if(value==KEY_ENTER||value==KEY_BACKSPACE)
		return value;
	return 0;
}

⌨️ 快捷键说明

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