📄 dispchar.c
字号:
#include <stdio.h>
#include <string.h>
#include <graphics.h>
/*
显示一个汉字字符
(left,top) 输出汉字字符的左上角点。
byte1 ------------汉字内码的第一字节
byte2 ------------汉字内码的第二字节
color ------------字符颜色
*/
int disp_hz(int left,int top,unsigned char byte1,unsigned char byte2,int color)
{
FILE *hzkfile;
unsigned char buf[32];
unsigned char mark;
long p;
int y,i,j;
int quma,weima;
hzkfile=fopen("E:\\wanglei\\TurboC\\source\\hanzi\\HZK16","rb");
if ((hzkfile==NULL))
{
outtextxy(10,10,"Can't open hzk file! Press any key to quit...");
exit(1);
}
if ((byte1>=0xa1&&byte1<=0xfe)&&(byte2>=0xa1&&byte2<=0xfe))
{
quma=byte1-0xa0;
weima=byte2-0xa0;
p=(quma-1)*94+weima-1;
p*=32;
fseek(hzkfile,(long)p,SEEK_SET);
fread(buf,sizeof(unsigned char ),32,hzkfile);
fclose(hzkfile);
for(i=0,y=top;i<31;i+=2,y++)
for(mark=0x80,j=0;mark>0;mark=mark>>1,j++)
{
if ((buf[i]&mark)!=0) putpixel(left+j,y,color);
if ((buf[i+1]&mark)!=0) putpixel(left+j+8,y,color);
}
}
fclose(hzkfile);
return 1;
}
/*
在西文DOS下,往屏幕上输出一中西文字符串
(x,y) 输出中西文字符串的左上角点
p 中西文字符串
color 输出字符串的颜色
*/
int OutTextxy(int x,int y,char *p,int color)
{
int oldcolor;
int disp_hz(int left,int top,unsigned char byte1,unsigned char byte2,int color);
oldcolor=getcolor();
setcolor(color);
while(*p)
{
if (((unsigned char )*p>=0xa1&&(unsigned char )*p<=0xfe) /*是汉字*/
&&((unsigned char)*(p+1)>=0xa1&&(unsigned char)*(p+1)<=0xfe))
{
if ((x+16-1)>getmaxx()||(y+16-1)>getmaxy()) return 0;
disp_hz(x,y,*p,*(p+1),color);
p+=2;
x+=16+2;
moveto(x,y);
}
else
{
char q[2];
moveto(x,y);
*q=*p;
*(q+1)='\0';
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(x,y+4,q);
x+=8+1;
p++;
}
}
setcolor(oldcolor);
return 1;
}
void main()
{
int x, y, color,gd,gm;
char str[20];
x = 10;
y = 10;
strcpy (str,"test!这是一个测试字符串!");
color = 5;
gd=DETECT;
initgraph(&gd,&gm,"f:\\tc30\\bgi");/*设置图形模式*/
OutTextxy(x, y, str, color );
/*closegraph()*/;/*关闭图形模式*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -