Board logo

标题: dos下的c编程,如何才能显示汉字? [打印本页]

作者: imur02     时间: 2009-2-12 10:48    标题: dos下的c编程,如何才能显示汉字?

dos下的c编程,如何才能显示汉字?

谢谢先
作者: Sufone     时间: 2009-2-12 12:21
加载汉字系统
作者: pujihong123     时间: 2009-2-12 22:22
你google 一下,估计要加载一个小程序!
作者: tty1a     时间: 2009-2-13 17:55
是自己写C程序吗?
Turbo c下,可以自己从字体文件中提取字模,然后画出来就可以了。
给你一段代码吧。字模文件你可以在本论坛上找到很多--HZK16
代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <conio.h>
#include <graphics.h>
int disphz(int left,int top,unsigned char byte1,unsigned char byte2,int color)
{
  FILE *fp;
  struct linesettingstype oldlinetype;unsigned int buf[16];
  unsigned char mark;long p;int x,y,i;int qu,wei;
  unsigned int linetypedata[16];
  if ((fp=fopen("hzk16f","rb"))==NULL)
  {
          outtextxy(10,10,"can't open HZ16_file!");
          exit(0);
  }
  qu=byte1-0xa0;wei=byte2-0xa0;
  p=(qu-1)*94+wei-1;p*=32;
  fseek(fp,(long)p,SEEK_SET);
  fread(buf,2,16,fp);
  fclose(fp);
  for (i=0;i<16;i++)
  {
          linetypedata[i]=(buf[i]<<8&0xff00)|(buf[i]>>8&0x00ff);
  }
  x=left+15;setcolor(color);
  getlinesettings(&oldlinetype);
  for (i=0,y=top;i<16;i++,y++)
  {
          setlinestyle(4,linetypedata[i],1);
          moveto(left,y);
          lineto(x,y);
  }
  setlinestyle(oldlinetype.linestyle,oldlinetype.upattern,oldlinetype.thickness);
  return;
}

int outhz(int x,int y,char *p,int color)
{
  int oldcolor=getcolor();
  setcolor(color);
  while (*p)
  {
    if (x>639||y>479)
      return 0;
    if (((unsigned char)*p>=0xa1&&(unsigned char)*p<=0xfe)&&((unsigned char)*(p+1)>=0xa1&&(unsigned char)*(p+1)<=0xfe))
    {
      disphz(x,y,*p,*(p+1),color);
      p+=2;
      x+=18;
      moveto(x,y);
     }
    else
    {
      unsigned char *q[2];
      moveto(x,y);
      *q=*p;
      *(q+1)='\0';
      settextstyle(0,0,1);
      outtextxy(x,y+4,q);
      x+=9;
      p++;
    }
  }
  setcolor(oldcolor);
}

int main()
{
  int gd=VGA,gm=VGAHI;
  registerbgidriver(EGAVGA_driver); /*如果你的g没有先编译EGAVGA加到graphics.lib 请注释掉此句*/
  initgraph(&gd,&gm,"");
  outhz(100,100,"你好!测试一下程序ABCabc123",WHITE);
  outhz(100,120,"同是一颗金星,早上,人们叫它启明,傍晚,人们叫它长庚。",WHITE);
  getch();
  closegraph();
  clrscr();
  return 0;
}
作者: SinLow     时间: 2009-9-17 10:26
谢了,我收了,呵呵!
感谢提供