分享
 
 
 

C语言库函数(G类字母)

王朝c/c++·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

函数名: getgraphmode

功 能: 返回当前图形模式

用 法: int far getgraphmode(void);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy, mode;

char numname[80], modename[80];

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult();

/* an error occurred */

if (errorcode != grOk)

{

printf("Graphics error: %s\n",

grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

/* terminate with an error code */

exit(1);

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

/* get mode number and name strings */

mode = getgraphmode();

sprintf(numname,

"%d is the current mode number.",

mode);

sprintf(modename,

"%s is the current graphics mode",

getmodename(mode));

/* display the information */

settextjustify(CENTER_TEXT, CENTER_TEXT);

outtextxy(midx, midy, numname);

outtextxy(midx, midy+2*textheight("W"),

modename);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getimage

功 能: 将指定区域的一个位图存到主存中

用 法: void far getimage(int left, int top, int right, int bottom,

void far *bitmap);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

#include <alloc.h>

void save_screen(void far *buf[4]);

void restore_screen(void far *buf[4]);

int maxx, maxy;

int main(void)

{

int gdriver=DETECT, gmode, errorcode;

void far *ptr[4];

/* auto-detect the graphics driver and mode */

initgraph(&gdriver, &gmode, "");

errorcode = graphresult(); /* check for any errors */

if (errorcode != grOk)

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1);

}

maxx = getmaxx();

maxy = getmaxy();

/* draw an image on the screen */

rectangle(0, 0, maxx, maxy);

line(0, 0, maxx, maxy);

line(0, maxy, maxx, 0);

save_screen(ptr); /* save the current screen */

getch(); /* pause screen */

cleardevice(); /* clear screen */

restore_screen(ptr); /* restore the screen */

getch(); /* pause screen */

closegraph();

return 0;

}

void save_screen(void far *buf[4])

{

unsigned size;

int ystart=0, yend, yincr, block;

yincr = (maxy+1) / 4;

yend = yincr;

size = imagesize(0, ystart, maxx, yend); /* get byte size of image */

for (block=0; block<=3; block++)

{

if ((buf[block] = farmalloc(size)) == NULL)

{

closegraph();

printf("Error: not enough heap space in save_screen().\n");

exit(1);

}

getimage(0, ystart, maxx, yend, buf[block]);

ystart = yend + 1;

yend += yincr + 1;

}

}

void save_screen(void far *buf[4])

{

unsigned size;

int ystart=0, yend, yincr, block;

yincr = (maxy+1) / 4;

yend = yincr;

size = imagesize(0, ystart, maxx, yend); /* get byte size of image */

for (block=0; block<=3; block++)

{

if ((buf[block] = farmalloc(size)) == NULL)

{

closegraph();

printf("Error: not enough heap space in save_screen().\n");

exit(1);

}

getimage(0, ystart, maxx, yend, buf[block]);

ystart = yend + 1;

yend += yincr + 1;

}

}

void restore_screen(void far *buf[4])

{

int ystart=0, yend, yincr, block;

yincr = (maxy+1) / 4;

yend = yincr;

for (block=0; block<=3; block++)

{

putimage(0, ystart, buf[block], COPY_PUT);

farfree(buf[block]);

ystart = yend + 1;

yend += yincr + 1;

}

}

函数名: getlinesettings

功 能: 取当前线型、模式和宽度

用 法: void far getlinesettings(strUCt linesettingstype far *lininfo):

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

/* the names of the line styles supported */

char *lname[] = { "SOLID_LINE",

"DOTTED_LINE",

"CENTER_LINE",

"DASHED_LINE",

"USERBIT_LINE"

};

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

struct linesettingstype lineinfo;

int midx, midy;

char lstyle[80], lpattern[80], lwidth[80];

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

/* get information about current line settings */

getlinesettings(&lineinfo);

/* convert line information into strings */

sprintf(lstyle, "%s is the line style.",

lname[lineinfo.linestyle]);

sprintf(lpattern, "0x%X is the user-defined line pattern.",

lineinfo.upattern);

sprintf(lwidth, "%d is the line thickness.",

lineinfo.thickness);

/* display the information */

settextjustify(CENTER_TEXT, CENTER_TEXT);

outtextxy(midx, midy, lstyle);

outtextxy(midx, midy+2*textheight("W"), lpattern);

outtextxy(midx, midy+4*textheight("W"), lwidth);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getmaxcolor

功 能: 返回可以传给函数setcolor的最大颜色值

用 法: int far getmaxcolor(void);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy;

char colstr[80];

/* initialize graphics and local variables

*/ initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

/* grab the color info. and convert it to a string */

sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor());

/* display the information */

settextjustify(CENTER_TEXT, CENTER_TEXT);

outtextxy(midx, midy, colstr);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getmaxx

功 能: 返回屏幕的最大x坐标

用 法: int far getmaxx(void);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy;

char xrange[80], yrange[80];

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

/* convert max resolution values into strings */

sprintf(xrange, "X values range from 0..%d", getmaxx());

sprintf(yrange, "Y values range from 0..%d", getmaxy());

/* display the information */

settextjustify(CENTER_TEXT, CENTER_TEXT);

outtextxy(midx, midy, xrange);

outtextxy(midx, midy+textheight("W"), yrange);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getmaxy

功 能: 返回屏幕的最大y坐标

用 法: int far getmaxy(void);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy;

char xrange[80], yrange[80];

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

/* convert max resolution values into strings */

sprintf(xrange, "X values range from 0..%d", getmaxx());

sprintf(yrange, "Y values range from 0..%d", getmaxy());

/* display the information */

settextjustify(CENTER_TEXT, CENTER_TEXT);

outtextxy(midx, midy, xrange);

outtextxy(midx, midy+textheight("W"), yrange);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getmodename

功 能: 返回含有指定图形模式名的字符串指针

用 法: char *far getmodename(int mode_name);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request autodetection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy, mode;

char numname[80], modename[80];

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

/* get mode number and name strings */

mode = getgraphmode();

sprintf(numname, "%d is the current mode number.", mode);

sprintf(modename, "%s is the current graphics mode.", getmodename(mode));

/* display the information */

settextjustify(CENTER_TEXT, CENTER_TEXT);

outtextxy(midx, midy, numname);

outtextxy(midx, midy+2*textheight("W"), modename);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getmoderange

功 能: 取给定图形驱动程序的模式范围

用 法: void far getmoderange(int graphdriver, int far *lomode,

int far *himode);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy;

int low, high;

char mrange[80];

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

/* get the mode range for this driver */

getmoderange(gdriver, &low, &high);

/* convert mode range info. into strings */

sprintf(mrange, "This driver supports modes %d..%d", low, high);

/* display the information */

settextjustify(CENTER_TEXT, CENTER_TEXT);

outtextxy(midx, midy, mrange);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getpalette

功 能: 返回有关当前调色板的信息

用 法: void far getpalette(struct palettetype far *palette);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

struct palettetype pal;

char psize[80], pval[20];

int i, ht;

int y = 10;

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult();

/* an error occurred */

if (errorcode != grOk)

{

printf("Graphics error: %s\n",

grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

/* terminate with an error code */

exit(1);

}

/* grab a copy of the palette */

getpalette(&pal);

/* convert palette info. into strings */

sprintf(psize, "The palette has %d \

modifiable entries.", pal.size);

/* display the information */

outtextxy(0, y, psize);

if (pal.size != 0)

{

ht = textheight("W");

y += 2*ht;

outtextxy(0, y, "Here are the current \

values:");

y += 2*ht;

for (i=0; i<pal.size; i++, y+=ht)

{

sprintf(pval,

"palette[%02d]: 0x%02X", i,

pal.colors[i]);

outtextxy(0, y, pval);

}

}

/* clean up */

getch();

closegraph();

return 0;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有