在 DOS 下显示汉字的方法

由于还有很多在上大学的朋友在使用 TC 2.0,可能没有显示汉字的方法,现在提供一种方法,不过需要字库,如有需要,给我 Email:Behard@21cn.com

注意:我使用的是 BC3.1,可能 TC 的注释方式有点区别。

#include <string.h>
#include <ctype.h>
#include <bios.h>
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include <graphics.h>
#include <conio.h>
#include <io.h>
#include <alloc.h>
#include <mem.h>
#include <fcntl.h>
#include <stdarg.h>
#include <math.h>

#define BOX_COLOR 13
#define FLAG_COLOR 13
#define WAVE_COLOR 5

#define LEFT_F_X 27 /* left pulse x */
#define RIGHT_F_X 255 /* right pusle x */
#define LEFT_P_X 508 /* left flow x */
#define RIGHT_P_X 736   /* right flow x */
#define PRN_MAX_X 956
#define PRN_MAX_Y 30
#define PRN_X 220
#define DX 20
#define DY 38
#define X_WID 16
#define Y_WID 16

FILE *hz16_handle;
int  getbit_16(unsigned char c,int n);
int  writec(int x,int y,int z,int color, unsigned char *p);
void writef(int x, int y, int width, int color, va_list arg_list, ...);

main()
{
 int drive=VGA;
 int mode=VGAHI;
 int i;

 hz16_handle=fopen("hzk16.dot","rb");    file://RED
 if(!hz16_handle){printf("Cant't open this file");return;}

// initgraph( &drive, &mode, "E://tc20" );
 initgraph( &drive, &mode, "E://bc31//bgi" );
 writef(100,8,44,BLACK+(LIGHTGRAY<<4),"  显示汉字,Test English,你好! ");
 writec(100,200,40,BLACK+(LIGHTGRAY<<4),"  显示汉字,Test English,你好! ");//No English
 while(!kbhit());
 closegraph();
}

void writeft(va_list arg_list, ...)
{
 int i=0;
 for(;i<32766;i++){i++;i--;}
}

void writef(int x, int y, int width, int color, va_list arg_list, ...)
{
 va_list arg_ptr;
 char *format;
 unsigned char output[81];
 unsigned char output_save,starti;
 struct textsettingstype  ts;
 int counter, len;
 unsigned char temp;
 int fc,bc,x1,y1;
 int dy,dx;
 union REGS inreg, outreg;
 if (width>78) return ;
 va_start(arg_ptr, arg_list);
 format = (char far *) arg_list;
 vsprintf((char *)output, format, arg_ptr);
 output[width]=0;
 fc=color & 0x0f;
 bc=((color & 0xf0) >>4);
 setfillstyle(1,bc);
 x1=x+width*8-1;y1=y+Y_WID;
 bar(x,y,x1,y1);
 settextstyle(0,0,1);
 dx=8;dy=4;
 counter=0;
 do {
  if((temp=output[counter])>(unsigned char) 0xa0)  /*chinese*/
  {
   starti=counter;
   counter++;
   do
   {
    temp=output[counter];counter++;
   } while (temp>(unsigned char)0xa0) ;
   output_save=output[--counter];
   output[counter]=0;
   writec(x,y,0,color,&output[starti]);
   output[counter]=output_save;
   x+=(counter-starti)*8;
  }
  else if (output[counter])   /*ascii*/
  {
   starti=counter;
   counter++;
   while(output[counter] && output[counter]<(unsigned char ) 0xa0) counter++;
   output_save=output[counter];
   output[counter]=0;
   setcolor(fc);
   outtextxy(x,y+dy,(char *) output+starti);
   output[counter]=output_save;
   x+=(counter-starti)*dx;
  }
 } while(output[counter] && counter<width);
}


int writec(int x,int y,int z,int color, unsigned char *p)
{
 int c1,c2,f=0;
 int i1,i2,i3,rec,jj;
 unsigned char i;
 int len;
 int fcolor,bcolor;
 long l;
 char by[32];
 unsigned char *q;

 fcolor=color & 0x0f;
 bcolor=((color & 0x0f0) >>4);
 len=strlen(p);
 setfillstyle(1,bcolor);
 bar(x,y,x+len*8+(len/2)*z,y+15);
 for ( ; i= *p; p++)
 {
  if(i & 0x80)
  {
   if(f==0)
   {
    c1=(char)i;
    f=1;
   }
   else
   {
    c2=(char)i;
    f=0;
    if(c1<0)
    {
     c1=c1+97;
     c2=c2+1;
     l=((c1-1)*94L+c2)*32;
/*     printf("%d,%d,,",c1,c2);*/
     fseek(hz16_handle,l,SEEK_SET);
     fread(by,32,1,hz16_handle);
    }
    for(i1=0;i1<16;i1++)
    {
     for(i2=0;i2<2;i2++)
     {
      for(i3=0;i3<8;i3++)
      {
       if(getbit_16( (unsigned char) by[i1*2+i2],7-i3))
       {
        putpixel(x+i2*8+i3-1,y+i1-1,fcolor);/*printf("1");*/
       }
      }
     }
    }
    x=x+16;
   }
  }
 }
 return(x);
}

int getbit_16(unsigned char c,int n)
{
 return((c>>n)&1);
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值