C語言直接顯示漢字(轉)

subid發表於2007-08-16
C語言直接顯示漢字(轉)[@more@]
如何顯示漢字

在模式 13H 下, 直接寫屏顯示漢字.
其中 hzk16 是 UCDOS 的字型檔, 把它放在當前目錄下
顯示漢字用的是 區位碼, 稍加修改可變成顯示其它碼.

// Graphics Mode 13h Test, Display a Chinese String, Wildrose Inc.
// Compile it with Watcom C/C++ 10.0 compiler
// Copyright(c) Jan. 1997 ZhangWei
// All rights reserved

#if !defined(__WATCOMC__)' '!defined(__386__)
#error "This Program needs Watcom C/C++ 10.0 Compiler"
#endif

#include
#include
#include
#include
#include
#include
#include

char c=1;
int orig_mode=3;
char *pv=(char *)(0x0A0000L);
FILE *fp; char buffer[32];

void PutPixel(int x, int y, char c)
{
*(pv+y*320+x)=c; //put pixel color
}
void InitGraph()//Set 320x200 256 colors Mode
{
union REGS regs;

//Test if it is VGA Adapter.
regs.w.ax = 0x1A00;
int386(0x10, ®s, ®s);
if(regs.h.al != 0x1A)
{
puts("This Program needs VGA Adapter ");
exit(1);
}
// get original video mode
regs.w.ax = 0x0F00;
int386(0x10, ®s, ®s);
orig_mode = regs.h.al;
// set graphic mode 13h
regs.w.ax = 0x0013;
int386(0x10, ®s, ®s);
}
void CloseGraph()
{
union REGS regs;
regs.h.ah = 0x00;
regs.h.al = orig_mode;
int386(0x10, ®s, ®s);
}

void CoutTextxy(int x, int y, int *qwm) //Display Chinese Character String
{
int pos=0;
long addr;
register p;
unsigned char bit;
while(qwm[pos])
{
if(((qwm[pos]>=101)&&(qwm[pos]<=994))||((qwm[pos]>=1601)&&(qwm[pos]<=8794)
{
addr=((long)(qwm[pos]/100-1)*94+(long)(qwm[pos]%100-1))*32; //Calculate
pos++; if(fseek(fp,addr,SEEK_SET))return; //Failed
for(register i=0;i<32;i++)
{
buffer[i]=fgetc(fp);
}
for(i=0;i<16;i++)
{
bit=0x80;
for(register k=0;k<8;k++,bit>>=1)
{
if((buffer[2*i]&bit))PutPixel(x+k,y+i,c);
if((buffer[2*i+1]&bit))PutPixel(x+k+8,y+i,c);
}
}
}
x+=16;
}
}

void main()
{
int x=120, y=60;
char filename[]="hzk16";
int sd[]={4168,2181,5102,4859,2011,0};
if((fp=fopen(filename,"rb"))==NULL)
{
printf("Can't open file %s ",filename);
return;
}
InitGraph();

CoutTextxy(x,y,sd);
c=2; CoutTextxy(x,y+16,sd);
c=3; CoutTextxy(x,y+32,sd);
c=4; CoutTextxy(x,y+48,sd);
getch();
CloseGraph();
fclose(fp);
}



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10796304/viewspace-962569/,如需轉載,請註明出處,否則將追究法律責任。

相關文章