电脑里面翻出来的学生时代的一段代码
本帖最后由 冰糖 于 2010-11-9 21:22 编辑当时学C时候抄袭来的代码,不保证能运行 /:017#include <graphics.h>
#include <stdio.h>
#include <fcntl.h>
#include <alloc.h>
#include <stdlib.h>
#include <string.h>
#include "Conio.h"
#include "graphics.h"
#define closegr closegraph
void initgr(void) /* BGI初始化 */
{int gd=DETECT,gm=0; /* 和gd=VGA,gm=VGAHI是同样效果 */
registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */
initgraph(&gd,&gm,"");
}
void drawmat(char *mat,int matsize,int x,int y,int color)
/*依次:字模指针、点阵大小、起始坐标(x,y)、颜色*/
{int i,j,k,n;
n=(matsize-1)/8+1;
for(j=0;j<matsize;j++)
for(i=0;i<n;i++)
for(k=0;k<8;k++)
if(mat&(0x80>>k))/*测试为1的位则显示*/
putpixel(x+i*8+k,y+j,color);
}
char shi64[]={
/* 以下是 '师' 的 64点阵黑体 字模,512 byte */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0x3F,0xFF,0xFF,0xFF,0xF0,
0x00,0x00,0x7C,0x3F,0xFF,0xFF,0xFF,0xF0,
0x00,0x00,0x7C,0x3F,0xFF,0xFF,0xFF,0xF0,
0x03,0xF0,0x7C,0x3F,0xFF,0xFF,0xFF,0xF0,
0x03,0xE0,0x7C,0x00,0x00,0xF8,0x00,0x00,
0x03,0xE0,0x7C,0x00,0x00,0xF8,0x00,0x00,
0x03,0xE0,0x7C,0x00,0x00,0xF8,0x00,0x00,
0x03,0xE0,0x7C,0x00,0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0xF8,0x07,0xC0,
0x03,0xE0,0x78,0x0F,0x80,0xF8,0x07,0xC0,
0x03,0xE0,0xF8,0x0F,0x80,0xF8,0x07,0xC0,
0x03,0xE0,0xF8,0x0F,0x80,0xF8,0x07,0xC0,
0x03,0xE0,0xF8,0x0F,0x80,0xF8,0x07,0x80,
0x03,0xE1,0xF0,0x0F,0x80,0xF8,0xFF,0x80,
0x00,0x01,0xF0,0x0F,0x80,0xF8,0xFF,0x80,
0x00,0x03,0xF0,0x0F,0x80,0xF8,0x7F,0x80,
0x00,0x03,0xE0,0x0F,0x80,0xF8,0x7F,0x00,
0x00,0x07,0xE0,0x0F,0x80,0xF8,0x7C,0x00,
0x00,0x0F,0xC0,0x0F,0x80,0xF8,0x60,0x00,
0x00,0x1F,0xC0,0x0F,0x80,0xF8,0x00,0x00,
0x00,0x3F,0x80,0x00,0x00,0xF8,0x00,0x00,
0x00,0x7F,0x00,0x00,0x00,0xF8,0x00,0x00,
0x00,0xFE,0x00,0x00,0x00,0xF8,0x00,0x00,
0x01,0xFC,0x00,0x00,0x00,0xF8,0x00,0x00,
0x07,0xF8,0x00,0x00,0x00,0xF8,0x00,0x00,
0x07,0xF0,0x00,0x00,0x00,0xF8,0x00,0x00,
0x01,0xE0,0x00,0x00,0x00,0xF8,0x00,0x00,
0x00,0xC0,0x00,0x00,0x00,0xF8,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
char da64[]={
/* 以下是 '大' 的 64点阵黑体 字模,512 byte */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x01,0xE0,0x00,0x07,0xC0,0x00,0x07,0xC0,
0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,
0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,
0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,
0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xF0,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0xF0,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0xF0,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0xF8,0x00,0x00,0x00,
0x00,0x00,0x00,0x3E,0x78,0x00,0x00,0x00,
0x00,0x00,0x00,0x3E,0x7C,0x00,0x00,0x00,
0x00,0x00,0x00,0x7C,0x3E,0x00,0x00,0x00,
0x00,0x00,0x00,0xFC,0x3E,0x00,0x00,0x00,
0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00,
0x00,0x00,0x01,0xF8,0x1F,0x80,0x00,0x00,
0x00,0x00,0x03,0xF0,0x0F,0xC0,0x00,0x00,
0x00,0x00,0x03,0xF0,0x07,0xE0,0x00,0x00,
0x00,0x00,0x07,0xE0,0x07,0xF0,0x00,0x00,
0x00,0x00,0x0F,0xC0,0x03,0xF8,0x00,0x00,
0x00,0x00,0x1F,0xC0,0x01,0xFC,0x00,0x00,
0x00,0x00,0x3F,0x80,0x00,0xFE,0x00,0x00,
0x00,0x00,0xFF,0x00,0x00,0xFF,0x80,0x00,
0x00,0x01,0xFE,0x00,0x00,0x7F,0xC0,0x00,
0x00,0x03,0xFC,0x00,0x00,0x3F,0xE0,0x00,
0x00,0x0F,0xF8,0x00,0x00,0x1F,0xF8,0x00,
0x00,0x3F,0xF0,0x00,0x00,0x0F,0xFE,0x00,
0x00,0xFF,0xC0,0x00,0x00,0x07,0xFF,0x80,
0x03,0xFF,0x80,0x00,0x00,0x01,0xFF,0xE0,
0x0F,0xFF,0x00,0x00,0x00,0x00,0xFF,0xC0,
0x07,0xFC,0x00,0x00,0x00,0x00,0x7F,0x80,
0x03,0xF8,0x00,0x00,0x00,0x00,0x1F,0x00,
0x01,0xE0,0x00,0x00,0x00,0x00,0x0E,0x00,
0x01,0xC0,0x00,0x00,0x00,0x00,0x02,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
char matarray16k[]={
/* 以下是 '2' 的 16点阵宋体 字模,32 byte */
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,
0x10,0x10,0x00,0x10,0x00,0x10,0x00,0xE0,
0x03,0x00,0x04,0x00,0x08,0x00,0x10,0x00,
0x10,0x10,0x10,0x10,0x1F,0xF0,0x00,0x00,
/* 以下是 '0' 的 16点阵宋体 字模,32 byte */
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x08,0x20,0x07,0xC0,0x00,0x00,
/* 以下是 '0' 的 16点阵宋体 字模,32 byte */
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x08,0x20,0x07,0xC0,0x00,0x00,
/* 以下是 '2' 的 16点阵宋体 字模,32 byte */
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,
0x10,0x10,0x00,0x10,0x00,0x10,0x00,0xE0,
0x03,0x00,0x04,0x00,0x08,0x00,0x10,0x00,
0x10,0x10,0x10,0x10,0x1F,0xF0,0x00,0x00,
/* 以下是 '0' 的 16点阵宋体 字模,32 byte */
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x08,0x20,0x07,0xC0,0x00,0x00,
/* 以下是 '6' 的 16点阵宋体 字模,32 byte */
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,
0x10,0x10,0x10,0x00,0x10,0x00,0x17,0xC0,
0x18,0x20,0x10,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x08,0x20,0x07,0xC0,0x00,0x00,
/* 以下是 '1' 的 16点阵宋体 字模,32 byte */
0x00,0x00,0x01,0x00,0x03,0x00,0x05,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x07,0xC0,0x00,0x00,
/* 以下是 '6' 的 16点阵宋体 字模,32 byte */
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,
0x10,0x10,0x10,0x00,0x10,0x00,0x17,0xC0,
0x18,0x20,0x10,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x08,0x20,0x07,0xC0,0x00,0x00,
};
int puthz16(int,int,int,int,char *);
int puthz24(int,int,int,int,int,int,char *);
int getbit(unsigned char,int);
int handle,test1,test2,test3,test4,test5;
main()
{
int gdriver,gmode;
int i,j;
gdriver=DETECT;
/* registerbgidriver(EGAVGA_driver);*/
initgraph(&gdriver,&gmode,"c:\\ccdos\\program\\tc");/*修改以适应*/
setbkcolor(7);
setcolor(LIGHTBLUE);
cleardevice();
ReadIcon(100,100,"C:\\fnt\\about.dat",0);
initgr(); /* BGI初始化 */
drawmat(shi64,64,200,125,WHITE);
drawmat(da64,64,300,125,WHITE);
for(i=0;i<8;i++)
drawmat(matarray16k+i*32,16,300+i*16,250,RED);
cleardevice();
mainmenu();
closegraph();
exit(0);
getch(); /* 暂停一下,看看前面绘图代码的运行结果 */
closegr(); /* 恢复TEXT屏幕模式 */
}
int openhzk(char c)
{ if (c=='s')
handle=open("c:\\ucdos\\fnt\\hzk24s",O_RDONLY|O_BINARY);
if (c=='f')
handle=open("c:\\ucdos\\fnt\\hzk24f",O_RDONLY|O_BINARY);
if (c=='k')
handle=open("c:\\ucdos\\fnt\\hzk24k",O_RDONLY|O_BINARY);
if (c=='h')
handle=open("c:\\ucdos\\fnt\\hzk24h",O_RDONLY|O_BINARY);
if (c=='o')
handle=open("c:\\ucdos\\hzk16",O_RDONLY|O_BINARY);
if(handle==-1)
{
cputs("Error on open hzk");
getch();
closegraph();
exit(1);
}
}
int puthz16(int x,int y,int z,int color,char *p)
{
unsigned int i,c1,c2,f=0;
int i1,i2,i3,rec;
long l;
char by;
while((i=*p++)!=0)
{
if(i>0xa1)
if(f==0)
{
c1=(i-0xa1)&0x7f;
f=1;
}
else
{
c2=(i-0xa1)&0x7f;
f=0;
rec=c1*94+c2;
l=rec*32L;
lseek(handle,l,SEEK_SET);
read(handle,by,32);
for(i1=0;i1<16;i1++)
for(i2=0;i2<2;i2++)
for(i3=0;i3<8;i3++)
if(getbit(by,7-i3))
putpixel(x+i2*8+i3,y+i1,color);
x=x+16+z;
}
}
return(x);
}
int puthz24(int x,int y,int z,int color,int xm,int ym,char *p)
{
unsigned int i,c1,c2,f=0;
int i1,i2,i3,i4,i5,rec;
long l;
char by;
while((i=*p++)!=0)
{
if(i>0xa1)
if(f==0)
{
c1=(i-0xa1-15)&0x07f;
f=1;
}
else
{
c2=(i-0xa1)&0x07f;
f=0;
rec=c1*94+c2;
l=rec*72L;
lseek(handle,l,SEEK_SET);
read(handle,by,72);
for(i1=0;i1<24*xm;i1=i1+xm)
for(i4=0;i4<xm;i4++)
for(i2=0;i2<3;i2++)
for(i3=0;i3<8;i3++)
if(getbit(by,7-i3))
for(i5=0;i5<ym;i5++)
putpixel(x+i1+i4,y+i2*8*ym+i3*ym+i5,color);
x=x+24*ym+z;
}
}
return(x);
}
int getbit(unsigned char c, int n)
{
return((c>>n)&1);
}
int mainmenu()
{
unsigned char *f[]={"数据输入","数据检查","数据修改","统计记录",
"报表打印","退出系统"};
int i,x,key1,key2,test,size;
char c;void *buffer;
setcolor(12);
rectangle(1,0,637,33);
setfillstyle(1,3);
floodfill(200,20,12);
setcolor(LIGHTRED);
setlinestyle(0,0,2);
rectangle(1,0,637,479);
openhzk('s');
x=-3;
for(i=0;i<=5;i++)
x=puthz24(10+x,6,0,1,1,1,f);
close(handle);
setcolor(12);
line(1,33,637,33);
line(107,0,107,33);
line(213,0,213,33);
line(319,0,319,33);
line(425,0,425,33);
line(531,0,531,33);
size=imagesize(3,2,105,31);
buffer=malloc(size);
getimage(3,2,105,31,buffer);
putimage(3,2,buffer,NOT_PUT);
x=3;
while(1)
{
while(key1!=13)
{
while(bioskey(1)==0);
key1=key2=bioskey(0);
key1=key1&0xff;
key2=key2&0xff?0:key2>>8;
if(key2==75||key2==77)
{
putimage(x,2,buffer,COPY_PUT);
if(key2==77) x=x>=533?3:x+106;
if(key2==75) x=x<=3?533:x-106;
getimage(x,2,x+102,31,buffer);
putimage(x,2,buffer,NOT_PUT);
}
}
test=(x-3)/106+1;
switch(test)
{
case 1:menu11();
break;
case 2:menu12();
break;
case 3:menu13();
break;
case 4:menu14();
break;
case 5:menu15();
break;
case 6:closegraph();
exit(0);
}
key1=0;
}
free(buffer);
}
int menu11()
{
unsigned char *f[]={"单个录入","连续录入"};
int x0=1,y0=35,h=2;
menu0(x0,y0,h,f);
switch(test1)
{case 1:do1();
break;
case 2:break;
}
mainmenu();
}
int do1()
{setviewport(1,0,638,479,1);
clearviewport();
outtextxy(50,50,"name");
outtextxy(50,60,"number");
getch();
clearviewport();
}
int menu12()
{
unsigned char *f[]={"单个录入","连续录入"};
int x0=107,y0=35,h=2;
menu0(x0,y0,h,f);
}
int menu13()
{
unsigned char *f[]={"单个录入","连续录入"};
int x0=213,y0=35,h=2;
menu0(x0,y0,h,f);
}
int menu14()
{
unsigned char *f[]={"单个录入","连续录入"};
int x0=319,y0=35,h=2;
menu0(x0,y0,h,f);
}
int menu15()
{
unsigned char *f[]={"单个录入","连续录入"};
int x0=425,y0=35,h=2;
menu0(x0,y0,h,f);
}
int menu0(int x0,int y0,int h,unsigned char *f[])
{
int i,y,key1,key2,size0,size1;
void *buf0,*buf1;
char c;
int j,k,len;
k=0;
for(j=1;j<h;j++)
if(strlen(f)<strlen(f)) k=j;
len=strlen(f)*8+2;
if((x0+len)>637) x0=637-len;
size0=imagesize(x0,y0,x0+len,y0+20*h);
buf0=malloc(size0);
getimage(x0,y0,x0+len,y0+20*h,buf0);
setcolor(12);
rectangle(x0,y0,x0+len,y0+20*h);
setfillstyle(1,3);
floodfill(x0+10,y0+10,12);
setcolor(12);
setlinestyle(SOLID_LINE,0,1);
rectangle(x0,y0,x0+len,y0+20*h);
openhzk('o');
for(i=0;i<h;i++)
puthz16(x0+2,i*20+y0+2,0,1,f);
close(handle);
size1=imagesize(x0+2,y0,x0+len-2,y0+20);
buf1=malloc(size1);
getimage(x0+2,y0,x0+len-2,y0+20,buf1);
putimage(x0+2,y0,buf1,NOT_PUT);
y=y0;
key1=0;
while(key1!=13&&key1!=27)
{
while(bioskey(1)==0);
key1=key2=bioskey(0);
key1=key1&0xff;
key2=key2&0xff?0:key2>>8;
if(key2==72||key2==80)
{
putimage(x0+2,y,buf1,COPY_PUT);
if(key2==72) y=y==y0?(y0+20*(h-1)):y-20;
if(key2==80) y=y==(y0+20*(h-1))?y0:y+20;
getimage(x0+2,y,x0+len-2,y+20,buf1);
putimage(x0+2,y,buf1,NOT_PUT);
}
}
free(buf1);
if(key1==13) test1=(y-y0)/20+1;
if(key1==27) test1=0;
putimage(x0,y0,buf0,COPY_PUT);
free(buf0);
}
ReadIcon(int x,int y,char *filename,int mode)
{
void *buf;
long size;
int fp;
fp=open(filename,O_CREAT|O_BINARY);
if(fp==-1) return 0;
size=filelength(fp);
buf=malloc(size);
read(fp,buf,size);
putimage(x,y,buf,mode);
free(buf);
close(fp);
}
忘了说,需要中文DOS支持 太长了,不想看。 500行的代码,看不懂 那是自古英雄出少年啊!
页:
[1]