⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphic.part2.h

📁 C语言库函数介绍
💻 H
📖 第 1 页 / 共 2 页
字号:
@函数名称:     setusercharsize
函数原型:     void far setusercharsize(int multx, int divx,int multy, int divy)
函数功能:     图形模式下设置任意比例大小的字体显示
函数返回:
参数说明:     multx,divx-x方向比例,显示大小为multx/divx的倍数
	      multy,divy-y方向比例,显示大小为multy/divy的倍数
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void xat(int x,int y);
char *hjust[]={"LEFT_TEXT","CENTER_TEXT","RIGHT_TEXT"};
char *vjust[]={"LEFT_TEXT","CENTER_TEXT","RIGHT_TEXT"};
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int midx,midy,hj,vj;
    char msg[80];
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode != grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    midx=getmaxx()/2;
    midy=getmaxy()/2;
    for (hj=LEFT_TEXT; hj<=RIGHT_TEXT; hj++)
        for (vj=LEFT_TEXT; vj<=RIGHT_TEXT; vj++)
        {
            cleardevice();
            settextjustify(hj,vj);
            sprintf(msg,"%s %s",hjust[hj],vjust[vj]);
            xat(midx,midy);
            outtextxy(midx,midy,msg);
            getch();
        }
    closegraph();
    return 0;
}


@函数名称:     textheight
函数原型:     int far textheight(char far *textstring)
函数功能:     得到图形模式下的字符串高度
函数返回:
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int y=0;
    int i;
    char msg[80];
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode != grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    for (i=1; i<11; i++)
    {
        settextstyle(TRIPLEX_FONT,HORIZ_DIR,i);
        sprintf(msg,"Size: %d",i);
        outtextxy(1,y,msg);
        y+= textheight(msg);
    }
    getch();
    closegraph();
    return 0;
}


@函数名称:     textwidth
函数原型:     int far textwidth(char far *textstring)
函数功能:     得到图形模式下的字符串宽度
函数返回:
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int y=0;
    int i;
    char msg[80];
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    for (i=1;i<11;i++)
    {
        settextstyle(TRIPLEX_FONT,HORIZ_DIR,i);
        sprintf(msg,"Size: %d",i);
        outtextxy(1,y,msg);
        y+=textwidth(msg);
    }
    getch();
    closegraph();
    return 0;
}


@函数名称:     graphresult
函数原型:     int far graphresult(void)
函数功能:     返回最近一次图形操作的结果状态值
函数返回:     图形操作结果,含义如下:
		grOk=0 grNoInitGraph=-1  grNotDetected=-2
		grFileNotFound=-3 grInvalidDriver=-4 grNoLoadMem=-5
		grNoScanMem=-6  grNoFloodMem=-7   grFontNotFound=-8
		grNoFontMem=-9  grInvalidMode=-10   grError=-11
		grIOerror=-12   grInvalidFont=-13   grInvalidFontNum=-14
		grInvalidVersion=-18
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    line(0,0,getmaxx(),getmaxy());
    getch();
    closegraph();
    return 0;
}


@函数名称:     initgraph
函数原型:     void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver)
函数功能:     初始化图形系统
函数返回:     以下代码将图形系统初始化为VGA 640X480 16色工作方式:
		int driver=VGA,mode=VGAHI; 
		initgraph(&amp;driver,&amp;mode,"c:\tc")
参数说明:     graphdriver 图形驱动器代号,具体如下:
		DETECT 0    CGA   1  MCGA  2   EGA   3
		EGA64  4    EGAMONO   5    IBM8514   6
		HERCMONO 7   ATT400    8    VGA     9
		PC3270  10  graphmode 选定图形驱动器的工作模式,具体如下:
		CGAC0=0 320x200  palette 0   1 page
		CGAC1=1 320x200  palette 1   1 page
		CGAC2=2 320x200  palette 2   1 page
		CGAC3=3 320x200  palette 3   1 page
		CGAHI=4 640x200     1 page
		MCGAC0=0 320x200  palette 0   1 page
		MCGAC1=1 320x200  palette 1   1 page
		MCGAC2=2 320x200  palette 2   1 page
		MCGAC3=3 320x200  palette 3   1 page
		MCGAMED=4 640x200      1 page
		MCGAHI=5  640x480      1 page
		EGALO=0   640x200  16 color    4 pages
		EGAHI=1   640x350  16 color    2 pages
		EGA64LO=0 640x200  16 color    1 page
		EGA64HI=1 640x350   4 color    1 page
		EGAMONOHI=0 640x350  64K on card 1 page
		256K on card 4 pages
		HERCMONOHI=0 720x348     2 pages
		ATT400C0=0   320x200  palette 0  1 page
		ATT400C1=1   320x200  palette 1  1 page
		ATT400C2=2   320x200  palette 2  1 page
		ATT400C3=3   320x200  palette 3  1 page
		ATT400MED=4  640x200     1 page
		ATT400HI=5   640x400     1 page
		VGALO=0  640x200 16 color    4 pages
		VGAMED=1 640x350 16 color    2 pages
		VGAHI=2  640x480 16 color    1 page
		PC3270HI=0  720x350          1 page
		IBM8514LO=0 640x480 256 colors
		IBM8514HI=1 1024x768 256 colors
		pathtodriver-图形驱动器文件路径,如不修改,图形驱动器文件在TC目录下
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    line(0,0,getmaxx(),getmaxy());
    getch();
    closegraph();
    return 0;
}


@函数名称:     getviewsettings
函数原型:     void far getviewsettings(struct viewporttype far *viewport)
函数功能:     得到当前视口信息
函数返回:
参数说明:     viewport 视口信息,该结构如下:
		struct viewporttype{
		  int left,top,right,bottom;
		  int clip;
		};
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
char *clip[]={"OFF","ON"};
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    struct viewporttype viewinfo;
    int midx,midy,ht;
    char topstr[80],botstr[80],clipstr[80];
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    midx=getmaxx()/2;
    midy=getmaxy()/2;
    getviewsettings(&viewinfo);
    sprintf(topstr,"(%d,%d) is the upper left viewport corner.",
	viewinfo.left,viewinfo.top);
    sprintf(botstr,"(%d,%d) is the lower right viewport corner.",
	viewinfo.right,viewinfo.bottom);
    sprintf(clipstr,"Clipping is turned %s.",clip[viewinfo.clip]);
    settextjustify(CENTER_TEXT,CENTER_TEXT);
    ht=textheight("W");
    outtextxy(midx,midy,topstr);
    outtextxy(midx,midy+2*ht,botstr);
    outtextxy(midx,midy+4*ht,clipstr);
    getch();
    closegraph();
    return 0;
}


@函数名称:     clearviewport
函数原型:     void far clearviewport(void)
函数功能:     清除当前屏幕窗口显示,仅用于图形工作方式
函数返回:
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define CLIP_ON 1
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int ht;
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    setcolor(getmaxcolor());
        ht=textheight("W");
    outtextxy(0,0,"* <-- (0,0) in default viewport");
    setviewport(50,50,getmaxx()-50,getmaxy()-50,CLIP_ON);
    outtextxy(0,0,"* <-- (0,0) in smaller viewport");
    outtextxy(0,2*ht,"Press any key to clear viewport:");
    getch();
    clearviewport();
    outtextxy(0,0,"Press any key to quit:");
    getch();
    closegraph();
    return 0;
}


@函数名称:     getx
函数原型:     int far getx(void)
函数功能:     得到当前位置的x坐标
函数返回:     当前位置的x坐标
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    char msg[80];
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    moveto(getmaxx()/2,getmaxy()/2);
    sprintf(msg,"<-(%d,%d) is the here.",getx(),gety());
    outtext(msg);
    getch();
    closegraph();
    return 0;
}


@函数名称:     gety
函数原型:     int far gety(void)
函数功能:     得到当前位置的y坐标
函数返回:     当前位置的y坐标
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    char msg[80];
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    moveto(getmaxx()/2,getmaxy()/2);
    sprintf(msg,"<-(%d,%d) is the here.",getx(),gety());
    outtext(msg);
    getch();
    closegraph();
    return 0;
}


@函数名称:     setviewport
函数原型:     void far setviewport(int left, int top, int right, int bottom, int clip)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -