int main(void) { /* request autodetection */ int gdriver = DETECT, gmode, errorcode; void *arrow; int x, y, maxx; unsigned int size;
/* 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 */ }
maxx = getmaxx(); x = 0; y = getmaxy() / 2;
/* draw the image to be grabbed */ draw_arrow(x, y);
/* calculate the size of the image */ size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);
/* allocate memory to hold the image */ arrow = malloc(size);
/* grab the image */ getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);
/* repeat until a key is pressed */ while (!kbhit())
{ /* erase old image */ putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
x += ARROW_SIZE; if (x >= maxx) x = 0;
/* plot new image */ putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); }
/* clean up */ free(arrow); closegraph(); return 0; }
void draw_arrow(int x, int y) { /* draw an arrow on the screen */ moveto(x, y); linerel(4*ARROW_SIZE, 0); linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); linerel(0, 2*ARROW_SIZE); linerel(2*ARROW_SIZE, -1*ARROW_SIZE); }
函数名: initgraph 功 能: 初始化图形系统 用 法: void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver); 程序例:
int main(void) { clrscr(); cprintf("INSLINE inserts an empty line in the text window/r/n"); cprintf("at the cursor position using the current text/r/n"); cprintf("background color. All lines below the empty one/r/n"); cprintf("move down one line and the bottom line scrolls/r/n"); cprintf("off the bottom of the window./r/n"); cprintf("/r/nPress any key to continue:"); gotoxy(1, 3); getch(); insline(); getch(); return 0; }
函数名: installuserdriver 功 能: 安装设备驱动程序到BGI设备驱动程序表中
用 法: int far installuserdriver(char far *name, int (*detect)(void)); 程序例:
函数名: intdos 功 能: 通用DOS接口 用 法: int intdos(union REGS *inregs, union REGS *outregs); 程序例:
#include <stdio.h> #include <dos.h>
/* deletes file name; returns 0 on success, nonzero on failure */ int delete_file(char near *filename) { union REGS regs; int ret; regs.h.ah = 0x41; /* delete file */ regs.x.dx = (unsigned) filename; ret = intdos(®s, ®s);
/* if carry flag is set, there was an error */ return(regs.x.cflag ? ret : 0); }
int main(void) { int err; err = delete_file("NOTEXIST.$$$"); if (!err) printf("Able to delete NOTEXIST.$$$/n"); else printf("Not Able to delete NOTEXIST.$$$/n"); return 0; }
函数名: intdosx 功 能: 通用DOS中断接口 用 法: int intdosx(union REGS *inregs, union REGS *outregs, struct SREGS *segregs); 程序例:
#include <stdio.h> #include <dos.h>
/* deletes file name; returns 0 on success, nonzero on failure */ int delete_file(char far *filename) { union REGS regs; struct SREGS sregs; int ret;
/* if carry flag is set, there was an error */ return(regs.x.cflag ? ret : 0); }
int main(void) { int err; err = delete_file("NOTEXIST.$$$"); if (!err) printf("Able to delete NOTEXIST.$$$/n"); else printf("Not Able to delete NOTEXIST.$$$/n"); return 0; }
/* use func 8 to determine if the default drive is removable */ stat = ioctl(0, 8, 0, 0); if (!stat) printf("Drive %c is removable./n", getdisk() + 'A'); else printf("Drive %c is not removable./n", getdisk() + 'A'); return 0; }