| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 184 人关注过本帖
标题:另类函数,让编程更加有效,更加方便(DIY函数)
收藏  订阅  推荐  打印 
xql0501
Rank: 1
等级:新手上路
帖子:16
积分:460
注册:2007-3-16
另类函数,让编程更加有效,更加方便(DIY函数)

/* ---- 学习另类函数,教你如何获得组合键的Bioskey(0)值(例如:Ctrl + F = 8454 ) ----*/
/* ---- 让编程更加有效,更加方便!!! ----*/

/*-------------------------------------------*/
/*----- ------*/
/*----- DIY (文本模式)C语言函数 ------*/
/*----- ------*/
/*-------------------------------------------*/

#include "stdio.h"
#include "conio.h"
#include "dos.h"
#include "time.h"
union REGS regs;

/*函数一:*/
int Box(int x1,int y1,int x2,int y2,int Textcolor,int bkcolor)
{ /* 画矩形框函数,若将Textcolor等于bkcolor则可以画出一个粗边框的矩形*/
int i;
char back[2];
struct text_info ti;

if(x1>x2||y1>y2||x1<1||x2>80||y1<1||y2>25) return 0;
gettextinfo(&ti); /* 获得当前窗口的文本信息*/
window(x1,y1,x2,y2);textcolor(Textcolor);textbackground(bkcolor);
putch(0xd9); /* 将框右下角保存*/
gettext(x1,y1,x1,y1,back);gotoxy(1,1);
putch(0xda); /* 画框左上角*/
for(i=2;i<=x2-x1;i++) putch(0xc4); /* 画框上边*/
putch(0xbf); /* 画框右上角*/
for(i=2;i<=y2-y1;i++)
{ /* 画框的左右两边*/
gotoxy(1,i); putch(0xb3);/*字符 '|'*/
gotoxy(x2-x1+1,i); putch(0xb3);
}
gotoxy(1,y2); putch(0xc0); /* 画框左下角*/
for(i=2;i<=x2-x1;i++) putch(0xc4);/* 画框下边,字符'—'*/
puttext(x2,y2,x2,y2,back); /* 画框右下角,为了避免光标下移,所以用了puttext()*/
window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
textbackground(ti.attribute>>4);textcolor(ti.attribute&0x000f);
gotoxy(ti.curx,ti.cury);
}

/*函数二:*/
int Window_roll(int x1,int y1,int x2,int y2,int direct,int step,int bkcolor)
{ /*窗口上下滚屏,bkcolor被移屏处显示的颜色*/
union REGS regs;

if(x1>x2||y1>y2||x1<1||x2>80||y1<1||y2>25||(direct!=6&&direct!=7))
return 0;

regs.h.ah=direct;/*ah=6 向上滚动当前页*/
/*ah=7 向下滚动当前页*/
regs.h.al=step; /*滚动行数*/
regs.h.bh=bkcolor*16;
regs.h.ch=y1-1; /*左上角行*/
regs.h.cl=x1-1; /*列*/
regs.h.dh=y2; /*右下角行*/
regs.h.dl=x2; /*列*/
int86(16,&regs,&regs);
return 1;
}

/*函数三:*/
void My_clrscr(int x1,int y1,int x2,int y2,int bkcolor)
{ /*清除屏幕,想清哪就清哪,内置的clrscr();函数只能清除当前窗口,不能随意清除
而且要用textbackground()+clrscr()才能达到效果,这个函数就方便多咯*/
if(x1<1||y1<1 || y2>25||x2>80 || x1>x2||y1>y2) return;

regs.h.ah=6; /*子功能号*/
regs.h.al=0; /*滚动行数*/
regs.h.bh=bkcolor*16;
regs.h.ch=y1-1;
regs.h.cl=x1-1;
regs.h.dh=y2;
regs.h.dl=x2;
int86(16,&regs,&regs);
}
/*函数四:*/
void My_delay(float t)
{ /* 精确延时函数,单位为秒,可以精确到0.000001秒,
而且延迟中可以按任意键跳出*/
clock_t OldTime;/* time_t是long型的*/
if (t<0) return;
OldTime=clock();
while((clock()-OldTime)/18.2<t) if(kbhit())break;
}

void main()
{
int ch;

Box(1,1,80,25,6,6);/* 应用画框函数*/
gotoxy(6,2);textcolor(14);
cprintf("Get the ASIIC value and Bioskey() value! QQGroup:31545052 and 31544991\r\n\n");
gotoxy(10,3);cprintf("And test some DIY functions ... <Press 'Esc' to quit!>");

for(;;)
{
gotoxy(5,6);
textcolor(15);
cprintf(" Word ASIIC BIOSKEY(10) (16) < Press a key >");
ch=bioskey(0); /* 等待按键*/
if(ch==283) break;
gotoxy(5,8);
textcolor(9);
cprintf(" \'%c\' %d %d 0x%x",ch,ch&0x00ff,ch,ch);
/* 显示" 字符 ASIIC码值 扫描值(10进制)(16进制) "*/
textcolor(2);
gotoxy(5,11);
cputs("Press any key to begin rollup one step ...");
ch=getch();
if(ch==283) break;
Window_roll(5,6,77,22,6,1,0);/* 应用滚屏函数*/
gotoxy(5,15);
cputs("Press any key to clean all ,but not clean the edge ...");
ch=getch();
if(ch==283) break;
My_clrscr(5,6,77,22,0); /* 应用清屏函数*/

}
gotoxy(5,18);
cputs("Now begin to delay 2.222 seconds and quit...");
My_delay(2.222); /* 应用延时函数*/
}

搜索更多相关主题的帖子: DIY  函数  另类  
2007-3-18 21:14
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.061796 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved