www.pudn.com > file_systerm.rar > SEdit.h, change:2005-01-20,size:3049b


#include "windows.h" 
#include "stdio.h" 
#include "crtdbg.h" 
#include "string.h" 
 
#define DIR_UP -1 
#define DIR_DOWN 1 
/* 字体颜色*/ 
#define FORE_BLACK 0 
#define FORE_BLUE FOREGROUND_BLUE 
#define FORE_GREEN FOREGROUND_GREEN 
#define FORE_RED FOREGROUND_RED 
#define FORE_WHITE (FORE_BLUE|FORE_GREEN|FORE_RED) 
#define FORE_MASK (FORE_BLUE|FORE_GREEN|FORE_RED|FOREGROUND_INTENSITY) 
/*背景颜色*/ 
#define BACK_BLACK 0 
#define BACK_BLUE BACKGROUND_BLUE 
#define BACK_GREEN BACKGROUND_GREEN 
#define BACK_RED BACKGROUND_RED 
#define BACK_WHITE (BACK_BLUE|BACK_GREEN|BACK_RED) 
#define BACK_MASK (BACK_BLUE|BACK_GREEN|BACK_RED|BACKGROUND_INTENSITY) 
 
static HANDLE stdinput=INVALID_HANDLE_VALUE , stdoutput=INVALID_HANDLE_VALUE; 
 
void InitIoSystem();//屏幕初始化函数 
 
void GetCursorXY(int * px ,int * py); 
unsigned short GetTextForeColor(void); 
unsigned short GetTextBackColor(void); 
 
void SetTextForeColor(unsigned short forecolor); 
void SetTextBackColor(unsigned short backcolor); 
 
 
void InitIoSystem() 
{ 
	COORD cursorinitpos={0 , 0}; 
	COORD buffersize={80 , 25}; 
	stdinput=GetStdHandle(STD_INPUT_HANDLE); 
	_ASSERTE(stdinput!=INVALID_HANDLE_VALUE); 
	stdoutput=GetStdHandle(STD_OUTPUT_HANDLE); 
	_ASSERTE(stdoutput!=INVALID_HANDLE_VALUE); 
	_ASSERTE(SetConsoleCursorPosition(stdoutput , cursorinitpos)!=0); 
	SetTextForeColor(FORE_WHITE); 
	SetTextBackColor(BACK_BLACK); 
	_ASSERTE(SetConsoleScreenBufferSize(stdoutput , buffersize)!=0); 
}//屏幕初始化函数 
 
void SetCursorXY(int x ,int y) 
{ 
	COORD cursorpos={x , y}; 
	_ASSERTE(stdoutput!=INVALID_HANDLE_VALUE); 
	_ASSERTE(x>=0&&x<80&&y>=0&&y<25); 
	_ASSERTE(SetConsoleCursorPosition(stdoutput , cursorpos)!=0); 
}//设置光标位置函数 
 
void GetCursorXY(int * px , int * py) 
{ 
	CONSOLE_SCREEN_BUFFER_INFO screenbufferinfo; 
	_ASSERTE(stdoutput!=INVALID_HANDLE_VALUE); 
	_ASSERTE(px!=NULL&&py!=NULL); 
	_ASSERTE(GetConsoleScreenBufferInfo(stdoutput , &screenbufferinfo)!=0); 
	*px=screenbufferinfo.dwCursorPosition.X; 
	*py=screenbufferinfo.dwCursorPosition.Y; 
}//获取光标位置函数 
 
unsigned short GetTextForeColor(void) 
{ 
	CONSOLE_SCREEN_BUFFER_INFO screenbufferinfo; 
	_ASSERTE(stdoutput!=INVALID_HANDLE_VALUE); 
	_ASSERTE(GetConsoleScreenBufferInfo(stdoutput , &screenbufferinfo)!=0); 
	return screenbufferinfo.wAttributes & FORE_MASK; 
}//获取字体颜色函数 
 
unsigned short GetTextBackColor(void) 
{ 
	CONSOLE_SCREEN_BUFFER_INFO screenbufferinfo; 
	_ASSERTE(stdoutput!=INVALID_HANDLE_VALUE); 
	_ASSERTE(GetConsoleScreenBufferInfo(stdoutput , &screenbufferinfo)!=0); 
	return screenbufferinfo.wAttributes & BACK_MASK; 
}//获取背景颜色函数 
 
void SetTextForeColor(unsigned short forecolor) 
{ 
	_ASSERTE(stdoutput!=INVALID_HANDLE_VALUE); 
	_ASSERTE(SetConsoleTextAttribute(stdoutput , (WORD)(forecolor|GetTextBackColor()))!=0); 
}//设置字体颜色函数 
 
void SetTextBackColor(unsigned short backcolor) 
{ 
	_ASSERTE(stdoutput!=INVALID_HANDLE_VALUE); 
	_ASSERTE(SetConsoleTextAttribute(stdoutput , (WORD)(GetTextForeColor()|backcolor))!=0); 
}//设置背景颜色函数