📄 fg.htm
字号:
<p> /* read result of initialization */ <br>
errorcode = graphresult(); <br>
if (errorcode != grOk) /* an error occurred */
<br>
{ <br>
printf("Graphics error:
%s\n", grapherrormsg(errorcode)); <br>
printf("Press any key to
halt:"); <br>
getch(); <br>
exit(1); /* terminate with an
error code */ <br>
} </p>
<p> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; </p>
<p> /* get mode number and name strings */ <br>
mode = getgraphmode(); <br>
sprintf(numname, "%d is the current mode
number.", mode); <br>
sprintf(modename, "%s is the current graphics
mode.", getmodename(mode)); </p>
<p> /* display the information */ <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); <br>
outtextxy(midx, midy, numname); <br>
outtextxy(midx, midy+2*textheight("W"),
modename); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: getmoderange <br>
功 能: 取给定图形驱动程序的模式范围 <br>
用 法: void far getmoderange(int graphdriver, int far
*lomode, <br>
int far *himode); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int midx, midy; <br>
int low, high; <br>
char mrange[80]; </p>
<p> /* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<p> /* read result of initialization */ <br>
errorcode = graphresult(); <br>
if (errorcode != grOk) /* an error occurred */
<br>
{ <br>
printf("Graphics error:
%s\n", grapherrormsg(errorcode)); <br>
printf("Press any key to
halt:"); <br>
getch(); <br>
exit(1); /* terminate with an
error code */ <br>
} </p>
<p> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; </p>
<p> /* get the mode range for this driver */ <br>
getmoderange(gdriver, &low, &high); </p>
<p> /* convert mode range info. into strings */ <br>
sprintf(mrange, "This driver supports modes
%d..%d", low, high); </p>
<p> /* display the information */ <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); <br>
outtextxy(midx, midy, mrange); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: getpalette <br>
功 能: 返回有关当前调色板的信息 <br>
用 法: void far getpalette(struct palettetype far
*palette); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
struct palettetype pal; <br>
char psize[80], pval[20]; <br>
int i, ht; <br>
int y = 10; </p>
<p>/* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<p>/* read result of initialization */ <br>
errorcode = graphresult(); <br>
/* an error occurred */ <br>
if (errorcode != grOk) <br>
{ <br>
printf("Graphics error:
%s\n", <br>
grapherrormsg(errorcode)); <br>
printf("Press any key to
halt:"); <br>
getch(); <br>
/* terminate with an error code */ <br>
exit(1); <br>
} </p>
<p>/* grab a copy of the palette */ <br>
getpalette(&pal); </p>
<p>/* convert palette info. into strings */ <br>
sprintf(psize, "The palette has %d \ <br>
modifiable entries.", pal.size); </p>
<p>/* display the information */ <br>
outtextxy(0, y, psize); <br>
if (pal.size != 0) <br>
{ <br>
ht = textheight("W"); <br>
y += 2*ht; <br>
outtextxy(0, y, "Here are the
current \ <br>
values:"); <br>
y += 2*ht; <br>
for (i=0; i<pal.size; i++,
y+=ht) <br>
{ <br>
sprintf(pval, <br>
"palette[%02d]: 0x%02X", i, <br>
pal.colors[i]); <br>
outtextxy(0, y, pval); <br>
} <br>
} </p>
<p>/* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
</p>
<p>函数名: getpass <br>
功 能: 读一个口令 <br>
用 法: char *getpass(char *prompt); <br>
程序例: </p>
<p>#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
char *password; </p>
<p> password = getpass("Input a
password:"); <br>
cprintf("The password is: %s\r\n", <br>
password); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: getpixel <br>
功 能: 取得指定像素的颜色 <br>
用 法: int far getpixel(int x, int y); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> <br>
#include <dos.h> </p>
<p>#define PIXEL_COUNT 1000 <br>
#define DELAY_TIME 100 /* in milliseconds */ </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int i, x, y, color, maxx, maxy, <br>
maxcolor, seed; </p>
<p>/* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<p>/* read result of initialization */ <br>
errorcode = graphresult(); <br>
/* an error occurred */ <br>
if (errorcode != grOk) <br>
{ <br>
printf("Graphics error:
%s\n", <br>
grapherrormsg(errorcode)); <br>
printf("Press any key to
halt:"); <br>
getch(); <br>
/* terminate with an error code */ <br>
exit(1); <br>
} </p>
<p> maxx = getmaxx() + 1; <br>
maxy = getmaxy() + 1; <br>
maxcolor = getmaxcolor() + 1; </p>
<p> while (!kbhit()) <br>
{ <br>
/* seed the random number generator */ <br>
seed = random(32767); <br>
srand(seed); <br>
for (i=0; i<PIXEL_COUNT; i++) <br>
{ <br>
x =
random(maxx); <br>
y =
random(maxy); <br>
color =
random(maxcolor); <br>
putpixel(x, y,
color); <br>
} </p>
<p> delay(DELAY_TIME); <br>
srand(seed); <br>
for (i=0; i<PIXEL_COUNT; i++) <br>
{ <br>
x =
random(maxx); <br>
y =
random(maxy); <br>
color =
random(maxcolor); <br>
if (color ==
getpixel匇? ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;h;(;);;;
;e;t;p;s;p;(;););;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;e;s;e;t; ;t;o;
;s;e;g;m;e;n;t; ;o;f; ;t;h;e; ;P;S;P; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
; ; ; ; ; ; ; ; ; ; ; ; ; ;i;n;e; ;i;s; ;l;o;c;a;t;e;d; ;a;t;
;o;f;f;s;e;t; ;0;x;8;1; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
; ; ; ;t; ;o;f; ;P;S;P; ; ; ; ; ; ; ; ; <br>
</p>
<p>函数名: gets <br>
功 能: 从流中取一字符串 <br>
用 法: char *gets(char *string); <br>
程序例: </p>
<p>#include <stdio.h> </p>
<p>int main(void) <br>
{ <br>
char string[80]; </p>
<p> printf("Input a string:"); <br>
gets(string); <br>
printf("The string input was: %s\n", <br>
string); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: gettext <br>
功 能:
将文本方式屏幕上的文本拷贝到存储区 <br>
用 法: int gettext(int left, int top, int right, int
bottom, void *destin); <br>
程序例: </p>
<p>#include <conio.h> </p>
<p>char buffer[4096]; </p>
<p>int main(void) <br>
{ <br>
int i; <br>
clrscr(); <br>
for (i = 0; i <= 20; i++) <br>
cprintf("Line #%d\r\n",
i); <br>
gettext(1, 1, 80, 25, buffer); <br>
gotoxy(1, 25); <br>
cprintf("Press any key to clear
screen..."); <br>
getch(); <br>
clrscr(); <br>
gotoxy(1, 25); <br>
cprintf("Press any key to restore
screen..."); <br>
getch(); <br>
puttext(1, 1, 80, 25, buffer); <br>
gotoxy(1, 25); <br>
cprintf("Press any key to quit..."); <br>
getch(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: gettextinfo <br>
功 能: 取得文本模式的显示信息 <br>
用 法: void gettextinfo(struct text_info *inforec); <br>
程序例: </p>
<p>#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
struct text_info ti; <br>
gettextinfo(&ti); <br>
cprintf("window left
%2d\r\n",ti.winleft); <br>
cprintf("window top
%2d\r\n",ti.wintop); <br>
cprintf("window right
%2d\r\n",ti.winright); <br>
cprintf("window bottom
%2d\r\n",ti.winbottom); <br>
cprintf("attribute
%2d\r\n",ti.attribute); <br>
cprintf("normal attribute
%2d\r\n",ti.normattr); <br>
cprintf("current mode
%2d\r\n",ti.currmode); <br>
cprintf("screen height
%2d\r\n",ti.screenheight); <br>
cprintf("screen width
%2d\r\n",ti.screenwidth); <br>
cprintf("current x
%2d\r\n",ti.curx); <br>
cprintf("current y
%2d\r\n",ti.cury); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: gettextsettings <br>
功 能: 返回有关当前图形文本字体的信息 <br>
用 法: void far gettextsettings(struct textsettingstype
far *textinfo); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>/* the names of the fonts supported */ <br>
char *font[] = { "DEFAULT_FONT", <br>
"TRIPLEX_FONT", <br>
"SMALL_FONT", <br>
"SANS_SERIF_FONT", <br>
"GOTHIC_FONT" <br>
&n
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -