?? function.cpp
字號:
#include <cstdio>
#include <cstring>
#include <math.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#include <ctype.h>
#include "function.h"
/*
function:設置輸入窗口顏色
param:color顏色代號
return:無返回值
*/
void function::SetTextCorlor(unsigned short int color)
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hOut,color);
}
/*
function:獲得光標當前位置
param:x,y決定光標坐標
return:無返回值
*/
void function::GetXY(int *x,int *y)
{
HANDLE hOut; // 獲取標準輸出設備句柄
CONSOLE_SCREEN_BUFFER_INFO bInfo;
COORD pos;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo( hOut, &bInfo );
pos = bInfo.dwCursorPosition;
*x = pos.X;
*y = pos.Y;
}
/*
function:將光標定位到控制臺上的某個位置
param:xcursor,ycursor決定光標要定位到的坐標
return:無返回值
*/
void function::SetXY(int xcursor, int ycursor)
{
COORD pos = {xcursor,ycursor};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); // 獲取標準輸出設備句柄
SetConsoleCursorPosition(hOut, pos);
}
/*
function:讀取系統當前時間并顯示
param:無參數
return:無返回值
*/
void function::GetTime()
{
time_t tval;
struct tm *now;
/* Get current date and time */
tval = time(NULL);
now = localtime(&tval);
printf("CurrentTime: %4d-%d-%02d \n",
now->tm_year+1900,now->tm_mon+1,now->tm_mday);
}
/*
function:畫一個輸入框
param:color設置輸入框顏色;xcursor,ycursor決定畫輸入框的位置
return:無返回值
*/
void function::DrawInputFrame(unsigned short color,int xcursor,int ycursor,int len)
{
int i;
SetXY(xcursor,ycursor);
SetTextCorlor(color);
for(i=0;i<len;i++)
{
printf(" ");
}
}
/*
function:清屏區域函數
param:(fromX,fromY)區域開始坐標,(toX,toY)區域終點坐標
return:無返回值
*/
void function::ClearScreen(int fromX,int fromY,int toX,int toY)
{
int i,j;
int row,line;//row代表行,line代表列
row=toY-fromY+1;
line=toX-fromX+1;
for(i=0;i<row;i++)
{
for(j=0;j<line;j++)
{
SetXY(fromX+j,fromY+i);
printf(" ");
}
}
}
//載入條
void function::Loading()
{
int i;
DrawInputFrame(255,10,10,50);
for(i=1;i<=50;i++)
{
Sleep(80);
SetXY(35,9);
SetTextCorlor(10);
printf("%d%%",2*i);
DrawInputFrame(202,10,10,i);
}
SetTextCorlor(15);
}
/*
function:設置文本顏色
param:color顏色代號
return:無返回值
*/
void function::SetCorlor(short int color)
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hOut,color);
}
/*
function:框控制定長輸入
param:str[]存放輸入的字符串,len輸入字符串的最大長度
return:無返回值
*/
int function::input(char str[], int len)
{
int i=0;
int ch;
while(1)
{
ch=getch();
if(ch==0xe0)
{
ch=getch();//方向鍵不接收
//continue;
}
else if(ch==27)
{
return 1;//按ESC退出
}
else if(ch==8)
{
if(i>0)
{
printf("\b");//光標前移,然后用空格代替光標當前位置的字符
printf(" ");
printf("\b");
i--;
str[i]='\0';
}
}
else if(ch==13)
{
str[i]='\0';
return 0;
}
else if(i<len)
{
if(isprint(ch))//isprint(ch)判斷ch是否是可打印字符,不包括Tab鍵
{
str[i++]=ch;
putchar(ch);
}
}
}
return 0;
}
//輸入的數字超過10
int function::InputValidate(char str[],int begin,int to)
{
int len;
int i=0;
int value=0;//0為正確
len=strlen(str);
if(len<=0)
return value=1;//為空
else
{
while(i<len)
{
if(!(str[i]>=48 && str[i]<=57))
return value=2;//不是數字,即非法字符
i++;
}
}
if(len>0)
{
if(atoi(str)<begin || atoi(str)>to)
return value=3;//超出范圍
}
return value;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -