📄 王大刚--c语言编程宝典--i.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/028.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->I</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 I" name=keywords>
<META content="王大刚 - C语言编程宝典 - I" name=description>
<STYLE>#page {
LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
FONT: 9pt/12pt "宋体"
}
.tt2 {
FONT: 12pt/15pt "宋体"
}
A {
TEXT-DECORATION: none
}
A:hover {
COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
<TBODY>
<TR>
<TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/029.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/027.htm">前一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD>
<TD class=tt2 width="84%" bgColor=#f5f8f8>
<CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷体_GB2312
color=#ff6666>I</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<P>函数名: imagesize <BR>功 能: 返回保存位图像所需的字节数 <BR>用 法: unsigned far
imagesize(int left, int top, int right, int bottom); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>#define ARROW_SIZE 10 <BR>
<P>void draw_arrow(int x, int y); <BR>
<P>int main(void) <BR>{ <BR> /* request autodetection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
void *arrow; <BR> int x, y, maxx; <BR> unsigned
int size; <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> maxx = getmaxx(); <BR> x = 0; <BR>
y = getmaxy() / 2; <BR>
<P> /* draw the image to be grabbed */ <BR>
draw_arrow(x, y); <BR>
<P> /* calculate the size of the image */ <BR>
size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); <BR>
<P> /* allocate memory to hold the image */ <BR>
arrow = malloc(size); <BR>
<P> /* grab the image */ <BR> getimage(x,
y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); <BR>
<P> /* repeat until a key is pressed */ <BR> while
(!kbhit()) <BR> { <BR> /* erase
old image */ <BR> putimage(x, y-ARROW_SIZE,
arrow, XOR_PUT); <BR>
<P> x += ARROW_SIZE;
<BR> if (x >= maxx)
<BR> x = 0; <BR>
<P> /* plot new image */
<BR> putimage(x, y-ARROW_SIZE, arrow,
XOR_PUT); <BR> } <BR>
<P> /* clean up */ <BR> free(arrow);
<BR> closegraph(); <BR> return 0; <BR>} <BR>
<P>void draw_arrow(int x, int y) <BR>{ <BR> /* draw an arrow
on the screen */ <BR> moveto(x, y); <BR>
linerel(4*ARROW_SIZE, 0); <BR> linerel(-2*ARROW_SIZE,
-1*ARROW_SIZE); <BR> linerel(0, 2*ARROW_SIZE);
<BR> linerel(2*ARROW_SIZE, -1*ARROW_SIZE); <BR>} <BR>
<BR> <BR> <BR>
<P>函数名: initgraph <BR>功 能: 初始化图形系统 <BR>用 法: void far
initgraph(int far *graphdriver, int far *graphmode, <BR>
char far *pathtodriver); <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>
<P> /* initialize graphics mode */ <BR>
initgraph(&gdriver, &gmode, ""); <BR>
<P> /* read result of initialization */ <BR>
errorcode = graphresult(); <BR>
<P> 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);
/* return with error code */ <BR> } <BR>
<P> /* draw a line */ <BR> line(0, 0, getmaxx(),
getmaxy()); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: inport <BR>功 能: 从硬件端口中输入 <BR>用 法: int inp(int protid);
<BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <dos.h> <BR>
<P>int main(void) <BR>{ <BR> int result; <BR> int
port = 0; /* serial port 0 */ <BR>
<P> result = inport(port); <BR> printf("Word read
from port %d = 0x%X\n", port, result); <BR> return 0; <BR>}
<BR> <BR> <BR>
<P>函数名: insline <BR>功 能: 在文本窗口中插入一个空行 <BR>用 法: void
insline(void); <BR>程序例: <BR>
<P>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> clrscr(); <BR>
cprintf("INSLINE inserts an empty line in the text window\r\n");
<BR> cprintf("at the cursor position using the current
text\r\n"); <BR> cprintf("background color. All lines
below the empty one\r\n"); <BR> cprintf("move down one line
and the bottom line scrolls\r\n"); <BR> cprintf("off the
bottom of the window.\r\n"); <BR> cprintf("\r\nPress any key
to continue:"); <BR> gotoxy(1, 3); <BR> getch();
<BR> insline(); <BR> getch(); <BR>
return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: installuserdriver <BR>功 能: 安装设备驱动程序到BGI设备驱动程序表中 <BR>用
法: int far installuserdriver(char far *name, int (*detect)(void));
<BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>/* function prototypes */ <BR>int huge detectEGA(void); <BR>void
checkerrors(void); <BR>
<P>int main(void) <BR>{ <BR> int gdriver, gmode; <BR>
<P> /* install a user written device driver */
<BR> gdriver = installuserdriver("EGA", detectEGA); <BR>
<P> /* must force use of detection routine */ <BR>
gdriver = DETECT; <BR>
<P> /* check for any installation errors */ <BR>
checkerrors(); <BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<P> /* check for any initialization errors */ <BR>
checkerrors(); <BR>
<P> /* draw a line */ <BR> line(0, 0, getmaxx(),
getmaxy()); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR>
<P>/* detects EGA or VGA cards */ <BR>int huge detectEGA(void) <BR>{
<BR> int driver, mode, sugmode = 0; <BR>
<P> detectgraph(&driver, &mode); <BR> if
((driver == EGA) || (driver == VGA)) <BR> /*
return suggested video mode number */ <BR>
return sugmode; <BR> else <BR>
/* return an error code */ <BR> return
grError; <BR>} <BR>
<P>/* check for and report any graphics errors */ <BR>void
checkerrors(void) <BR>{ <BR> int errorcode; <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -