📄 026.htm
字号:
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<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> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* get the mode range for this driver */
<BR> getmoderange(gdriver, &low, &high);
<BR>
<P> /* convert mode range info. into strings */
<BR> sprintf(mrange, "This driver supports modes %d..%d", low,
high);
<BR>
<P> /* display the information */
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR> outtextxy(midx, midy, mrange);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getpalette
<BR>功 能: 返回有关当前调色板的信息
<BR>用 法: void far getpalette(struct palettetype far *palette);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<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;
<BR>
<P>/* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<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> }
<BR>
<P>/* grab a copy of the palette */
<BR> getpalette(&pal);
<BR>
<P>/* convert palette info. into strings */
<BR> sprintf(psize, "The palette has %d \
<BR> modifiable
entries.", pal.size);
<BR>
<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> }
<BR>
<P>/* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<P>函数名: getpass
<BR>功 能: 读一个口令
<BR>用 法: char *getpass(char *prompt);
<BR>程序例:
<BR>
<P>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> char *password;
<BR>
<P> password = getpass("Input a password:");
<BR> cprintf("The password is: %s\r\n",
<BR> password);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: getpixel
<BR>功 能: 取得指定像素的颜色
<BR>用 法: int far getpixel(int x, int y);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>#include <dos.h>
<BR>
<P>#define PIXEL_COUNT 1000
<BR>#define DELAY_TIME 100 /* in milliseconds */
<BR>
<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;
<BR>
<P>/* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<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> }
<BR>
<P> maxx = getmaxx() + 1;
<BR> maxy = getmaxy() + 1;
<BR> maxcolor = getmaxcolor() + 1;
<BR>
<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> }
<BR>
<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>
<BR>
<P>函数名: gets
<BR>功 能: 从流中取一字符串
<BR>用 法: char *gets(char *string);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>
<P>int main(void)
<BR>{
<BR> char string[80];
<BR>
<P> printf("Input a string:");
<BR> gets(string);
<BR> printf("The string input was: %s\n",
<BR> string);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: gettext
<BR>功 能: 将文本方式屏幕上的文本拷贝到存储区
<BR>用 法: int gettext(int left, int top, int right, int bottom,
void *destin);
<BR>程序例:
<BR>
<P>#include <conio.h>
<BR>
<P>char buffer[4096];
<BR>
<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>
<BR>
<P>函数名: gettextinfo
<BR>功 能: 取得文本模式的显示信息
<BR>用 法: void gettextinfo(struct text_info *inforec);
<BR>程序例:
<BR>
<P>#include <conio.h>
<BR>
<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>
<BR>
<P>函数名: gettextsettings
<BR>功 能: 返回有关当前图形文本字体的信息
<BR>用 法: void far gettextsettings(struct textsettingstype far *textinfo);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<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>
};
<BR>
<P>/* the names of the text directions supported */
<BR>char *dir[] = { "HORIZ_DIR", "VERT_DIR" };
<BR>
<P>/* horizontal text justifications supported */
<BR>char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" };
<BR>
<P>/* vertical text justifications supported */
<BR>char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" };
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> struct textsettingstype textinfo;
<BR> int midx, midy, ht;
<BR> char fontstr[80], dirstr[80], sizestr[80];
<BR> char hjuststr[80], vjuststr[80];
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<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> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* get information about current text settings */
<BR> gettextsettings(&textinfo);
<BR>
<P> /* convert text information into strings */
<BR> sprintf(fontstr, "%s is the text style.", font[textinfo.font]);
<BR> sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
<BR> sprintf(sizestr, "%d is the text size.", textinfo.charsize);
<BR> sprintf(hjuststr, "%s is the horizontal justification.",
<BR> hjust[textinfo.horiz]);
<BR> sprintf(vjuststr, "%s is the vertical justification.",
<BR> vjust[textinfo.vert]);
<BR>
<P> /* display the information */
<BR> ht = textheight("W");
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR> outtextxy(midx, midy, fontstr);
<BR> outtextxy(midx, midy+2*ht, dirstr);
<BR> outtextxy(midx, midy+4*ht, sizestr);
<BR> outtextxy(midx, midy+6*ht, hjuststr);
<BR> outtextxy(midx, midy+8*ht, vjuststr);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<P>函数名: gettime
<BR>功 能: 取得系统时间
<BR>用 法: void gettime(struct time *timep);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <dos.h>
<BR>
<P>int main(void)
<BR>{
<BR> struct time t;
<BR>
<P> gettime(&t);
<BR> printf("The current time is: %2d:%02d:%02d.%02d\n",
<BR> t.ti_hour, t.ti_min,
t.ti_sec, t.ti_hund
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -