- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(g开头)</FONT></B></FONT></P>. g% `; {' x! \: L
4 ]2 M* B4 W3 U1 S+ I, y) D* ?3 S4 ^# [- v& p
<p>0 Z8 G; c; X$ O* p% w0 M& a
< ><FONT color=#ff0000>函数名: gcvt </FONT>
$ f- d8 a X! u! L功 能: 把浮点数转换成字符串 / ^% w: c4 e/ a) Y
用 法: char *gcvt(double value, int ndigit, char *buf);
! \7 y& c2 c) J" z程序例: </P>
4 r) n: [6 m! t0 _< ><FONT color=#0000ff>#include <STDLIB.H>
; e, N% i5 M) q [8 t#include <STDIO.H></FONT></P>
0 m; [/ X: |% G( ?# r< ><FONT color=#0000ff>int main(void) 5 D0 D( I1 J" Z# Y8 ]8 Y% @
{
# `0 P' U3 Q2 h2 \1 I" h$ ^& qchar str[25]; - j( C( A/ \; o D X
double num;
- r4 Z5 W. \: ? B+ N6 qint sig = 5; /* significant digits */ </FONT></P>
0 G) H+ k, O s: { ~" a3 d" J< ><FONT color=#0000ff>/* a regular number */ * s+ ? g6 R0 i7 h
num = 9.876;
- ]* {: _; g M1 Ngcvt(num, sig, str); % r2 T: r# S/ U7 _. D
printf("string = %s\n", str); </FONT></P>
) P7 N5 Z1 D2 [9 U6 f% U; r9 f9 Y< ><FONT color=#0000ff>/* a negative number */ $ Z; L. C3 e5 ]0 x0 x# ^& t
num = -123.4567; 7 F; z& |, o- F/ x" y8 e- V9 i
gcvt(num, sig, str); ' r! t: @9 a+ E9 x4 y/ l6 a
printf("string = %s\n", str); </FONT></P>1 Z/ c' z8 Q1 ?! _2 v
< ><FONT color=#0000ff>/* scientific notation */
. F n7 p v4 I, W& B( m$ D5 Mnum = 0.678e5; : I: D: a% h4 h5 ?& Q$ e0 h
gcvt(num, sig, str);
/ U( {! ~2 |% |3 z& u. Kprintf("string = %s\n", str); </FONT></P>
" d) Q' y/ A8 y0 _6 [! D' ]( Q< ><FONT color=#0000ff>return(0);
8 o, L9 D& Q8 r* y% |) M2 o}
$ |' H4 `9 I3 {- Q6 J" G( \& J- t3 }. v0 }
</FONT>6 u4 A& k" L5 n" a6 H8 X9 r
</P>
3 J9 D4 b+ F9 C" U3 k; g0 i3 x< ><FONT color=#ff0000>函数名: geninterrupt </FONT>
' ^1 X3 h0 g! U功 能: 产生一个软中断 # L* n! o0 d$ X- R* V% H
用 法: void geninterrupt(int intr_num); ^0 @; t- y- b- W
程序例: </P> r1 U3 u( `& h( ^; @9 W
< ><FONT color=#0000ff>#include <CONIO.H>
0 T' F% n& x9 o0 G! o#include <DOS.H></FONT></P> E) @$ @0 L7 g9 l6 O5 Y5 N
< ><FONT color=#0000ff>/* function prototype */ . h+ B+ @- `( ?* E% y0 U [/ k
void writechar(char ch); </FONT></P>3 }( A L+ D- k2 S
< ><FONT color=#0000ff>int main(void)
5 d/ O/ l- u6 i{
. [" ` M X' ^* ^/ D2 B! eclrscr();
" h4 t9 p$ j5 J3 L/ x8 igotoxy(80,25);
0 x/ j1 d% d- |writechar('*'); 3 @3 s" U( [8 U. Q) Q$ }7 x
getch(); 0 I6 S3 R0 z! z9 Z! L
return 0; # S4 K% K9 V& n) m2 S
} </FONT></P>
; p$ u7 A$ N' ]4 c7 m& X! E< ><FONT color=#0000ff>/*
) B; P! b) B l: M: Poutputs a character at the current cursor 3 a ]$ I- k$ Y; e* X+ s
position using the video BIOS to avoid the 3 J& w$ i0 {8 T9 V
scrolling of the screen when writing to , {' `2 u$ N0 C
location (80,25).
0 \5 a: N H( j0 @; H! c*/ </FONT></P>
+ {8 P, k( b3 Z8 M< ><FONT color=#0000ff>void writechar(char ch) " ?& ^0 T z2 F! F6 s% p
{
# c/ g2 {4 g) s! X* w4 X9 X3 [- fstruct text_info ti; 5 R7 ~* g) \7 ]9 k$ z( P
/* grab current text settings */ $ n( g, L( I8 w0 Q- M+ w9 r
gettextinfo(&ti); ( G1 L: c% S6 V0 \
/* interrupt 0x10 sub-function 9 */ K! _- p5 W8 |
_AH = 9;
6 q& D8 R7 |3 {. x5 g/* character to be output */ ' T& ~ K9 [. |/ u! E* Y# Q7 {! z3 [
_AL = ch; 7 E6 @0 O% }2 Q5 \/ ~: A O
_BH = 0; /* video page */
9 s r4 e6 h" m) u$ Q2 O_BL = ti.attribute; /* video attribute */
8 i9 L. e: s5 f$ p. O_CX = 1; /* repetition factor */
, e5 g+ L) G" L' y( `2 m6 }geninterrupt(0x10); /* output the char */ 7 f l* ]' I p& r2 u
}
, W$ U7 w5 P% i+ U+ x0 C: o</FONT>! k% f2 e' X ?% f- H2 x7 N
</P>
i+ r0 b, U' C$ A( _< ><FONT color=#ff0000>函数名: getarccoords </FONT>+ g, c# G: E% W% f- U" j
功 能: 取得最后一次调用arc的坐标
2 Y$ T# v$ C! A5 _. W! S用 法: void far getarccoords(struct arccoordstype far *arccoords);
0 G) w- Z0 v3 a程序例: </P>
! ^$ P$ P: N0 p" z< ><FONT color=#0000ff>#include <GRAPHICS.H>
: s+ k7 h9 x, `7 ~#include <STDLIB.H> j6 X, g! S$ l/ w, C' D1 e* i
#include <STDIO.H>0 j7 ]. |2 D) m2 y
#include <CONIO.H></FONT></P>
+ a7 }! `( a6 s! E< ><FONT color=#0000ff>int main(void)
% W' R* F8 m& H0 ?{ 5 w5 X3 B4 {% I. H# V5 A
/* request auto detection */ " P3 \3 A6 R {0 p3 @
int gdriver = DETECT, gmode, errorcode; # e% T6 y& ~& k- B* G* K
struct arccoordstype arcinfo; " Q& N: |2 j" I5 Y
int midx, midy;
& n9 t3 A* s( Y+ ?7 ]$ A$ Lint stangle = 45, endangle = 270; 6 l1 L5 e" {9 ?2 s* ^
char sstr[80], estr[80]; </FONT></P>3 v t; n% [$ U5 Q: f
< ><FONT color=#0000ff>/* initialize graphics and local variables */
: d: G/ }3 p2 a! B: W# Qinitgraph(&gdriver, &gmode, ""); </FONT></P>' J* w) n) `8 Q8 `* J
< ><FONT color=#0000ff>/* read result of initialization */
% u9 Z; n& f5 y. ^7 m berrorcode = graphresult();
6 {; X+ e/ N# {; c. V% `/* an error occurred */
2 b( x4 E! n1 T+ ^% S0 rif (errorcode != grOk) 3 Z8 f/ R/ j2 \1 Q' A. y2 N, U* W
{ 0 ]# q/ M, ?3 j
printf("Graphics error: %s\n", - Y7 |4 z+ \9 h/ P5 t8 P. E
grapherrormsg(errorcode)); : ~1 F& W/ \3 j. `1 r% j
printf(" ress any key to halt:");
( K! J; Q( @4 E0 F7 q+ d$ Dgetch();
& {; c& G8 [1 ]! F9 @& S5 b4 z/* terminate with an error code */
- ~7 f, r8 }" p' n/ m- P- d# x, ?: Jexit(1); : ?/ i4 t6 o9 W% @, i# _1 h# r9 r
} </FONT></P>. a& k8 l% q% i6 b
< ><FONT color=#0000ff>midx = getmaxx() / 2;
& F4 ]0 U8 ?' d% pmidy = getmaxy() / 2; </FONT></P>& Z: e9 i7 n+ K. u
< ><FONT color=#0000ff>/* draw arc and get coordinates */
* k# L8 M; }6 @% Q$ rsetcolor(getmaxcolor()); ! j3 H% }7 ?8 J9 V
arc(midx, midy, stangle, endangle, 100);
; {3 i! j3 f0 {( g- H; h% k `0 [getarccoords(&arcinfo); </FONT></P>7 W, b$ d8 C$ n" O
< ><FONT color=#0000ff>/* convert arc information into strings */ $ |; G/ H( R: s, o
sprintf(sstr, "*- (%d, %d)", . o! R+ l) x1 M2 ^8 a
arcinfo.xstart, arcinfo.ystart);
# |* Z- g+ N0 a i/ g0 ?6 Bsprintf(estr, "*- (%d, %d)", * ]. S2 {# `' p A( E
arcinfo.xend, arcinfo.yend); </FONT></P>0 U" { S) L) ?
< ><FONT color=#0000ff>/* output the arc information */ 1 M9 u% J, r0 l6 t4 E
outtextxy(arcinfo.xstart,
" B; \( X6 k) x7 q" V3 [arcinfo.ystart, sstr); # u' k+ L8 T) ^: `1 T) c
outtextxy(arcinfo.xend,
6 H& D% q+ ]4 @7 Harcinfo.yend, estr); </FONT></P>' R2 G# N9 J$ N U; v- b9 [
< ><FONT color=#0000ff>/* clean up */
" Q; d- y8 @( N9 y7 C& Vgetch();
' r5 T/ U8 o( x) }closegraph();
; U$ A) x) g* E0 `. ^ Mreturn 0;
$ V8 c2 D: A: Y+ n: J& P}
P! M# V9 t& o+ L! D3 I/ q5 V</FONT>
1 ]9 h9 u# s5 p( j3 h: R8 c
' C8 v: q3 c4 o! S9 t8 T5 z</P>6 [7 m O3 p: U& V% ~
< ><FONT color=#ff0000>函数名: getaspectratio </FONT>6 E! O7 d+ u" R( F
功 能: 返回当前图形模式的纵横比 ( [( s) x l* |7 m& y
用 法: void far getaspectratio(int far *xasp, int far *yasp); r3 \& O( H" F3 N+ R% p
程序例: </P>$ ]& g- C8 ^7 L% b( ?( c
< ><FONT color=#0000ff>#include <GRAPHICS.H>( L/ ~- ?# y+ A" [+ B
#include <STDLIB.H>
& x/ \1 }; p0 R7 F% p" w/ Z$ T#include <STDIO.H>
+ R& u9 q) d. h( x; u; D# x2 [" j#include <CONIO.H></FONT></P>
) R7 F# ~# y/ ~< ><FONT color=#0000ff>int main(void) . }+ L u9 U) r& {% U
{
$ E" r5 ^4 `6 \, B. f' E/* request auto detection */ % j; V. c |* @9 z( S7 M4 I3 E
int gdriver = DETECT, gmode, errorcode; 7 F7 @* y0 g. z
int xasp, yasp, midx, midy; </FONT></P>; N5 E7 x5 j5 W) v# ~
< ><FONT color=#0000ff>/* initialize graphics and local variables */
) U" k) A+ I, K9 }7 G; O7 `9 f0 ^initgraph(&gdriver, &gmode, ""); </FONT></P>
0 b0 k9 h% q) _/ j< ><FONT color=#0000ff>/* read result of initialization */ ) b; X7 r+ m/ o( a4 u7 T6 U5 X j! C3 P
errorcode = graphresult();
3 U, d& k" _+ _/* an error occurred */ $ G+ U& f+ m, B, u2 k
if (errorcode != grOk)
" g6 S& t) f8 n5 w# a' S1 ~( V{
8 C7 G6 n- z% J# u& Bprintf("Graphics error: %s\n", P7 h, p$ _9 c/ P& E
grapherrormsg(errorcode));
- ]( e1 M! a/ ]8 ^9 j4 ?printf("Press any key to halt:");
7 D$ Z. n& E) d# F! k/ G/ [getch(); ; c! l% h9 H# @+ Q. H0 x
/* terminate with an error code */
8 u4 |5 F# h6 V3 }0 X* oexit(1);
( k3 k, ?* J/ N W. K0 J} </FONT></P>- a" w. D; ?" G5 C: P- j# ]- Y
<P><FONT color=#0000ff>midx = getmaxx() / 2; : w0 s0 I* W2 H
midy = getmaxy() / 2; 3 A9 { W+ ]/ B
setcolor(getmaxcolor()); </FONT></P>
) w! l8 }2 X0 [6 T<P><FONT color=#0000ff>/* get current aspect ratio settings */ 5 l( g7 f" P J/ N7 N# ^+ v2 J
getaspectratio(&xasp, &yasp); </FONT></P>
; G! y% A* {6 E# D1 l0 U- N<P><FONT color=#0000ff>/* draw normal circle */
8 C4 @. F$ N5 l! Ucircle(midx, midy, 100); + s; H; _" M+ k! Z/ h
getch(); </FONT></P>
5 c) |& _5 P4 Y! K) z<P><FONT color=#0000ff>/* draw wide circle */
8 ]8 W! E8 q( f6 C6 ^6 Acleardevice();
' e0 ^/ f; D- A- r) p; nsetaspectratio(xasp/2, yasp); ' D8 d3 r( s; C" |) D0 m* L
circle(midx, midy, 100); ; r0 s2 d, l! V/ o% \% R
getch(); </FONT></P>% Z- k1 V- K f& Z( |) |
<P><FONT color=#0000ff>/* draw narrow circle */ * d6 D, R3 _; b& g7 }
cleardevice();
3 r8 a& W5 Q1 S9 Q0 a( osetaspectratio(xasp, yasp/2);
4 [% m- {% U; `& f2 {. ^circle(midx, midy, 100); </FONT></P>
& X* w1 N$ q6 B# V) x0 L a0 B<P><FONT color=#0000ff>/* clean up */ $ u2 B( r. k9 z8 A
getch();
3 a. z! |+ ]4 e0 h, C- \! Fclosegraph();
- ]2 C2 V% _% i* A1 Kreturn 0;
: G/ R7 ` p1 _, o1 U' i, C}
( ~" o5 E5 U7 E0 B</FONT>
+ L. c$ d8 J* c/ ~6 [! S! t/ _8 R) @
$ V+ c5 D5 y2 }! J( [6 I</P>$ o0 t( K/ j; k' n
<P><FONT color=#ff0000>函数名: getbkcolor </FONT>
' K# i. b0 x& w( T- V功 能: 返回当前背景颜色
& V3 F3 ~% {9 @; \8 x用 法: int far getbkcolor(void); 1 e) a/ J& I% b
程序例: </P>
. Z6 r4 f/ c& E! ?- }- r<P><FONT color=#0000ff>#include <GRAPHICS.H>
# J; K* K) P' ~#include <STDLIB.H>
9 ]4 q. [6 Z" b+ M#include <STRING.H>
9 p( P$ C8 x6 n, i4 P, ~( A/ E y#include <STDIO.H>3 n5 O/ s& q2 _ u" B6 H0 `
#include <CONIO.H></FONT></P>7 H7 ] Y6 P* b: C
<P><FONT color=#0000ff>int main(void) * r% N: ]4 u# E( K* m n; E; e; w7 e7 r
{
/ F* D! Q7 h& Y1 e2 S/* request auto detection */
8 E- F! A d( r/ s1 gint gdriver = DETECT, gmode, errorcode;
' F" j" H! E$ H* H5 J o/ M; Fint bkcolor, midx, midy;
( u8 j" Y( n5 ]4 O1 ychar bkname[35]; </FONT></P>
0 x! Q7 y" I/ w* h% a! o<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ h+ k: g9 X0 r; qinitgraph(&gdriver, &gmode, ""); </FONT></P>5 S8 C: Y* v, G$ f- ~1 G
<P><FONT color=#0000ff>/* read result of initialization */
- P' E. [. {) V/ j. X. E+ aerrorcode = graphresult(); # S8 T4 c5 C, p' H. w) D* ^
/* an error occurred */
& H8 G8 l2 l: @$ cif (errorcode != grOk) 5 c% y% s+ ~% I& Q1 Q
{
: z p8 N& N5 ^2 ?( Lprintf("Graphics error: %s\n",
: F4 B" L3 L! T+ jgrapherrormsg(errorcode)); ; {5 a" @! u# v& w
printf("Press any key to halt:");
: s0 E; M- C3 | t6 Egetch(); + y# z; P& L: w3 R
/* terminate with an error code */
: ?) w9 e' [, m5 @3 k- b: h- ]exit(1);
7 U: C; [* `. v# L6 c# C} </FONT></P>
A7 N: M$ J! K A: ?! o" B) c<P><FONT color=#0000ff>midx = getmaxx() / 2; : c/ ~3 v) o5 J { i) p2 n
midy = getmaxy() / 2; 4 h* \- S6 z5 {# `5 Y1 F$ m2 P6 n# n$ s
setcolor(getmaxcolor()); </FONT></P>
! `/ ?% g3 l! M7 b5 [7 A+ I( _/ A<P><FONT color=#0000ff>/* for centering text on the display */ # [" q6 g. g$ M) a
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>9 |! t9 V6 |8 j# M0 T. ]" B
<P><FONT color=#0000ff>/* get the current background color */ / P' q H" [# l
bkcolor = getbkcolor(); </FONT></P>
* a$ |. h# B$ w( y6 H<P><FONT color=#0000ff>/* convert color value into a string */ + ^+ O! Y$ G! `5 x
itoa(bkcolor, bkname, 10);
8 j$ V, j6 _' m" ?strcat(bkname, 1 C- x+ e* H' l, ~ r& h
" is the current background color."); </FONT></P>1 u! O* e/ _# y& L. D8 h2 j
<P><FONT color=#0000ff>/* display a message */ ( n4 K8 g3 W# P8 q0 P9 d' ~
outtextxy(midx, midy, bkname); </FONT></P>( n5 Z( n% S0 s
<P><FONT color=#0000ff>/* clean up */
* L& r6 [6 v4 R$ e! x" {getch();
' Y8 x0 |$ ^" ~" X. Dclosegraph(); , q0 J8 }: v3 I# B' o- B0 d
return 0;
% l4 v/ G8 y2 P( O9 {} 5 }! Q& R B8 t# K7 G; b( m
7 @4 w3 L( c: D1 x* f</FONT>3 B( o0 P- n2 E9 |8 q) V( d7 ?% Y
</P>1 |$ G- \1 q5 A, d' M. S! Q0 f
<P><FONT color=#ff0000>函数名: getc </FONT>, o# V+ o: s9 U5 W( Z" e
功 能: 从流中取字符
Z' d' Z2 n0 @; ]# M- ^( A. \ @用 法: int getc(FILE *stream); ~$ H+ g1 l! I( o! w. z
程序例: </P>
2 r* W5 d/ }0 |' `' ?. y/ j0 i<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>, L6 Y6 ~) k& K6 d4 L
<P><FONT color=#0000ff>int main(void) . Q5 n$ o& X4 G2 J7 s# m
{
, ~$ M% X2 f8 ?- V0 w: xchar ch; </FONT></P>
* m7 x% R K' B% X1 }/ N<P><FONT color=#0000ff>printf("Input a character:"); $ Q* T) u$ w. m1 r* t
/* read a character from the
7 F1 X. V6 O1 U9 astandard input stream */
, _# J$ Y- e' o% d& T- ?9 P. Pch = getc(stdin); ( o { i4 k* L
printf("The character input was: '%c'\n", k5 Y6 ?6 Y7 Y, h4 z
ch);
3 ~& n) M! u' Q' ?/ n O7 greturn 0;
, ~6 g) ~ c& d2 Y! z) Q} # d! ~2 e. f2 n; Z0 J. y
( Q: Q* x3 \( C& _" P</FONT>
+ ^# [5 ~" [ Y7 Y" R</P>
2 R( w1 h/ R/ c3 n/ U/ f<P><FONT color=#ff0000>函数名: getcbrk </FONT>
; p5 k# K2 F# Q- n0 G功 能: 获取Control_break设置
* }5 g1 Z! o5 q( o5 ?! b, g/ ?: `用 法: int getcbrk(void);
) i9 u. |: l6 Q l, X8 X- ]程序例: </P>
" v5 G7 G! [; b: n<P><FONT color=#0000ff>#include <STDIO.H>+ b6 d) M0 P# \+ d6 V; H
#include <DOS.H></FONT></P>6 }% n6 |9 o' @5 U) G3 L' R! K
<P><FONT color=#0000ff>int main(void)
h/ v9 @: o* D. M) [' h{ $ x& K0 k. S+ Z: Z
if (getcbrk()) ( F$ ]0 c5 K$ u/ U$ G6 B; D
printf("Cntrl-brk flag is on\n");
0 |# D) y7 d. Felse
7 c- g5 ]8 w) q qprintf("Cntrl-brk flag is off\n"); </FONT></P>
) o8 x+ [) O9 f: x<P><FONT color=#0000ff>return 0; ( _8 D1 D1 L: n' }7 E
} </FONT>" p3 R+ A; n. ^2 `/ x5 A
' X! {9 F3 W! y</P>( X% x9 S8 k) P, m @
<P><FONT color=#ff0000>函数名: getch </FONT># d0 w7 l+ z5 e( o9 O
功 能: 从控制台无回显地取一个字符
4 \1 l' ^1 d2 z6 M0 y2 M1 z用 法: int getch(void);
: d( C! p3 ` \$ e7 t# d+ k程序例: </P>7 y5 s. P- o0 ]. G
<P><FONT color=#0000ff>#include <STDIO.H>' W4 H- v8 R" M
#include <CONIO.H></FONT></P>
8 |' P. S I' d) x) k! ^# E<P><FONT color=#0000ff>int main(void) . J9 L* t, Y. x& j
{ - G# ?. d4 x( b0 C/ J
char ch; </FONT></P>/ J! _6 s/ A& _; g( F. y
<P><FONT color=#0000ff>printf("Input a character:");
, k! a2 E5 J9 m% ]3 _% hch = getche();
* W y" T3 N$ u9 R& uprintf("\nYou input a '%c'\n", ch);
% k; K9 A& w! _return 0;
6 t+ Q* m) ]. b! b' U/ T} ' r1 @/ z. z& }* R$ L2 B
, E: O2 i" c- Z8 y</FONT></P>
k4 S% P- @8 H( w. g+ g- N<P><FONT color=#ff0000>函数名: getchar </FONT>9 w: b6 K! i: o* ~
功 能: 从stdin流中读字符
! z |4 q4 X: e; \用 法: int getchar(void);
& K J" R; T* M. }. u程序例: </P>
, e. x- l: @6 A$ x; P. E. F<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
# q' u( |, i8 y/ Y. j<P><FONT color=#0000ff>int main(void) * }) b: e: d, N7 `' c2 e. U* L: `- _
{ # D2 ^8 {) Q& w# t
int c; </FONT></P>; M4 H0 l2 n) c# p
<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
1 o/ f5 i# i# C8 ?& lis line buffered; this means it will ! r6 u4 s( q) U1 Z
not return until you press ENTER. */ </FONT></P>
; Z2 [3 P& o) N<P><FONT color=#0000ff>while ((c = getchar()) != '\n') 7 n# C. P9 c Y% `
printf("%c", c); </FONT></P>
D2 \$ D8 B2 G% H0 l5 p- ?<P><FONT color=#0000ff>return 0; - R# ~+ ~; c' v' [! |
}
5 s4 w, ~, p: I2 Q/ G% a/ X</FONT>" z9 P; K9 C! a. [
</P>, Y% n+ V8 L$ W
<P><FONT color=#ff0000>函数名: getche </FONT>
1 m9 c/ _; o1 A) {" E功 能: 从控制台取字符(带回显)
# H7 |; z ]7 D% ^$ C' r用 法: int getche(void); 4 q. p! y# Z6 k2 H& w
程序例: </P>
# K. z5 D3 T G- @2 W<P><FONT color=#0000ff>#include <STDIO.H>/ r, _0 r5 }4 ^3 F' I! ^- B2 x# c
#include <CONIO.H></FONT></P>
+ [$ ]* E3 V; ?* Z; S+ Y<P><FONT color=#0000ff>int main(void)
c3 _- C3 L6 ]6 I{
3 r( u- t2 m4 K4 z$ O1 x {- mchar ch; </FONT></P>
$ a' A2 a- E2 h2 \4 ]/ I- W<P><FONT color=#0000ff>printf("Input a character:");
1 ~4 |5 w2 Z" P- J& sch = getche(); " `+ G- V6 Z6 c! Q9 i
printf("\nYou input a '%c'\n", ch);
' W1 `+ |* C! I; z; P& jreturn 0; 0 |# F3 C' [& b* Z, Q
}</FONT>
6 i0 y6 R2 R: Q8 ~* U! e2 _
' ~! Y* u$ }7 Z @4 h, ~</P>
. ^+ d3 l8 c3 b8 a+ M, ^& U9 i<P><FONT color=#ff0000>函数名: getcolor </FONT>
. J3 T" f- l3 f2 G2 M功 能: 返回当前画线颜色
" o5 h) d+ L' L8 w2 y7 T6 t8 _6 [7 X用 法: int far getcolor(void); ; j$ v3 j$ g- }( n+ {7 |. |
程序例: </P>
5 E! K$ p/ F% Y- B7 s3 j; b/ \/ f<P><FONT color=#0000ff>#include <GRAPHICS.H>
! ^0 p% o5 C( ?% g8 w) D#include <STDLIB.H>
7 B, }: g0 y# A# K1 v#include <STRING.H>
8 c6 R. Y9 u7 H0 K0 ?#include <STDIO.H>
3 @& W2 N8 U& g2 h3 ~#include <CONIO.H></FONT></P>
! B/ a0 @" x, Y" l4 ^# k: h<P><FONT color=#0000ff>int main(void) 0 [1 p2 R, \( K, }0 w
{ % T+ H1 C4 t& U. ~- N9 l
/* request auto detection */ 5 o% @5 x" D J/ l
int gdriver = DETECT, gmode, errorcode;
X3 q9 y9 J: Z! I# N0 ?% c$ ?" Oint color, midx, midy;
: ~/ N' [4 x/ d3 ]+ j) g% }char colname[35]; </FONT></P>8 _; N$ S( O( E. o) i% F/ K* M
<P><FONT color=#0000ff>/* initialize graphics and local variables */ . D5 L5 r0 ^) D+ A7 }
initgraph(&gdriver, &gmode, ""); </FONT></P>4 J( p/ {2 u s4 W
<P><FONT color=#0000ff>/* read result of initialization */
3 c: h' M4 s9 U/ l: c perrorcode = graphresult();
7 Q5 h# \0 A' I1 G4 W4 ~% s8 h' E/* an error occurred */
# ^1 r( c2 z& N7 O# zif (errorcode != grOk) , U. o D' G' T6 L. N& ]- k# a
{
1 |2 y, A; ]) x; V# }- yprintf("Graphics error: %s\n",
0 o$ V$ L9 I- ?. C" P% Bgrapherrormsg(errorcode));
6 m1 D! T* _* K! l1 S% Kprintf("Press any key to halt:");
; C/ r3 y4 B% Z @6 X0 y! w3 `getch(); 7 s; w, n& _ ^6 B
/* terminate with an error code */
0 ]- T3 y6 r5 C4 Z" n' uexit(1); C8 ?7 e# s2 j. @
} </FONT></P>; X2 A6 v% y( w$ R
<P><FONT color=#0000ff>midx = getmaxx() / 2;
; {# g/ R, w* M5 rmidy = getmaxy() / 2;
3 n5 S$ s6 F xsetcolor(getmaxcolor()); </FONT></P>* z8 {0 @2 D# B0 z) \( B+ J
<P><FONT color=#0000ff>/* for centering text on the display */
/ h# w5 B7 I) h/ asettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P> N `! y; F Y! M6 I6 F% q4 B
<P><FONT color=#0000ff>/* get the current drawing color */
( ~% H- z% W C$ ~- S. H4 E& e# ?, hcolor = getcolor(); </FONT></P>
7 v, l9 {; H( y4 o& o8 |<P><FONT color=#0000ff>/* convert color value into a string */ $ A& Y Y9 U3 V7 j( y( a0 R
itoa(color, colname, 10);
2 `( ~$ T" y$ nstrcat(colname,
( ?- u$ G7 i7 y) c" is the current drawing color."); </FONT></P>9 t* A/ J; w D* `+ V7 V6 D% E
<P><FONT color=#0000ff>/* display a message */ / W; S! r! M7 O' j
outtextxy(midx, midy, colname); </FONT></P>
& O# p8 b: X" G<P><FONT color=#0000ff>/* clean up */ / q. I+ k2 P I0 Z5 H
getch();
C) K4 A& J9 Sclosegraph();
, ?, `& x" m! T0 o( [return 0;
# w, c3 o8 _) j M" O7 ~5 h2 i} ) f! r1 I& W; { e- W; h9 g$ ?, \1 p
</FONT>
7 x2 A; E% j* ?: c" d</P>
, N; Z; J% B% `5 B<P><FONT color=#ff0000>函数名: getcurdir </FONT>
$ V m r' N z2 V: e功 能: 取指定驱动器的当前目录 # b, ^! b% ^0 l, J
用 法: int getcurdir(int drive, char *direc);
: N8 n M5 O/ I" O# @: V* J程序例: </P>5 q0 \5 h' t* ]9 \$ T/ n. I
<P><FONT color=#0000ff>#include <DIR.H>2 J' ~& {1 F8 }! y( ?
#include <STDIO.H>
( N: [# t+ l8 h1 S#include <STRING.H></FONT></P>
* B0 J0 ~3 r+ J0 J+ ` J# r<P><FONT color=#0000ff>char *current_directory(char *path) : h+ |: {$ u7 U, b+ S0 O
{
. P5 s% i; R6 H, e J5 hstrcpy(path, "X:\\"); /* fill string with form of response: X:\ */ + n! {# [2 d# L+ W. c3 T# H
path[0] = 'A' + getdisk(); /* replace X with current drive letter */ 0 n; X; Q$ f; g& \/ r+ t' E* y
getcurdir(0, path+3); /* fill rest of string with current directory */ ( a- ?9 n6 f! e5 U( u5 }$ @
return(path); , K* T9 B* W1 m9 C1 t
} </FONT></P>% g9 q/ g7 a0 O+ q4 L
<P><FONT color=#0000ff>int main(void)
8 t% z! D5 N& \6 z* K; N8 A' L{ 8 p# U, f6 E) x9 R5 g. W5 s0 `
char curdir[MAXPATH]; </FONT></P>( f. [! R" x; e3 |/ [ N
<P><FONT color=#0000ff>current_directory(curdir);
' v- @$ N0 a, g7 L3 c+ ~printf("The current directory is %s\n", curdir); </FONT></P>1 n/ p* r+ v8 j! ]
<P><FONT color=#0000ff>return 0; ! S6 ~) u8 v. ?& |$ l; g$ {
} . h# Y' {: ?! a' B; Z9 E# V
</FONT>4 h# l. ]+ ?. Z/ W7 W
</P>
9 N: E( w& O: G<P><FONT color=#ff0000>函数名: getcwd </FONT>! y4 J3 ~# ]1 ^: Q- B' k+ b$ y
功 能: 取当前工作目录
* {' G/ }( a4 E( x$ L用 法: char *getcwd(char *buf, int n); ; _8 i- U0 z9 T9 H! R
程序例: </P>7 s: E; s6 n' R- t) T
<P><FONT color=#0000ff>#include <STDIO.H>
8 K0 r- ^" T0 m. M#include <DIR.H></FONT></P>
: F' i/ v$ O* U<P><FONT color=#0000ff>int main(void) ' Z' h6 L- x3 C) c: ^& D
{
) z) f; z- h6 \7 z0 W: N$ ?: s! dchar buffer[MAXPATH]; </FONT></P>! L& d3 p& b& v" `7 b
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH);
# e* C* b, Z4 R# mprintf("The current directory is: %s\n", buffer);
# z( A( |1 Z6 W5 _( Z; B2 r/ b! ~return 0;
. L/ {1 P/ _" H1 H+ z# i} </FONT>* P: c3 ]! M4 P$ h# V6 D+ a( a
9 O: C2 T6 h( H$ h) y1 [2 a! O
</P>7 n( @9 f/ ]0 i/ }. {* J1 H
<P><FONT color=#ff0000>函数名: getdate </FONT>1 P3 d3 ~/ ]7 ?- s9 q
功 能: 取DOS日期
4 M7 g: ?: r$ r3 J2 X用 法: void getdate(struct *dateblk);
# r) U! @% i" j3 z' e5 Y/ f程序例: </P>
; x+ Q* f8 v3 f" }<P><FONT color=#0000ff>#include <DOS.H>
2 X0 p! a7 p' t8 y#include <STDIO.H></FONT></P>
5 i7 t5 o6 E$ K7 H4 W6 D. L<P><FONT color=#0000ff>int main(void)
* Q5 Z/ e. p6 q) b- F5 D0 H( R{
( R* A2 z6 V/ z5 \struct date d; </FONT></P>
& ?4 o) [; N5 R$ H/ T; c# Q6 P<P><FONT color=#0000ff>getdate(&d); ; ?5 S0 G/ w8 S# F
printf("The current year is: %d\n", # ~1 Q; d- j: s5 _. g, w
d.da_year);
7 T; V( z* Y! Uprintf("The current day is: %d\n",
|% a9 H1 T: ~9 Id.da_day);
+ O* s: t, k4 L( U: Vprintf("The current month is: %d\n", & m3 y. a ~/ x: s' q+ ?2 D
d.da_mon);
$ C8 |, J( b" J8 Greturn 0;
" H9 F6 O* Z! o& T} 1 u2 N) W" L+ [' s! T7 e
</FONT>
& i0 E. K q9 x1 r</P>, _! k6 }0 _7 J; v; \! d% T
<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>
$ y7 f! v! ] u# A功 能: 返回调色板定义结构 - \9 s5 L1 ~/ M% [* h& D$ Y
用 法: struct palettetype *far getdefaultpalette(void);
) X; T* x& {3 Y% t' Q I: g程序例: </P>
( U( I- ~$ f3 h<P><FONT color=#0000ff>#include <GRAPHICS.H>; ^! z1 l' V/ M8 w; b
#include <STDLIB.H>' p* o9 P) ?, s- L$ l& L
#include <STDIO.H>0 N4 t* H6 ?) m- |3 v
#include <CONIO.H></FONT></P>
7 {2 y/ k/ b8 W( g# G) k# w+ O<P><FONT color=#0000ff>int main(void) 3 }% n1 o2 P+ N: N: T4 F
{ # m1 w A7 q$ ^( H/ V& b
/* request auto detection */ ! V+ |* e, [4 N7 y" @
int gdriver = DETECT, gmode, errorcode;
5 f- l2 n! ?9 d$ V: t* Mint i; </FONT></P>
! {% s. x: K/ L" Y) o5 u4 S<P><FONT color=#0000ff>/* structure for returning palette copy */ $ P$ p7 c3 [& M% e) m; N, S
struct palettetype far *pal=(void *) 0; </FONT></P>
6 z" ~0 l+ N1 G% G% L<P><FONT color=#0000ff>/* initialize graphics and local variables */
W0 |3 M8 o$ C; `6 H: S8 iinitgraph(&gdriver, &gmode, ""); </FONT></P>& n; F: ~: w3 I% a: t, e0 V
<P><FONT color=#0000ff>/* read result of initialization */
* w4 i: D4 C0 d P! D' S' Y$ Werrorcode = graphresult(); 9 W: _( \& ^1 P* }$ Y; |. ?+ \" r1 y
/* an error occurred */
- s+ c; s% ?" P2 N, s, Gif (errorcode != grOk)
; R5 _: _0 Y ]{ 3 n; F! B7 d0 [% x( F6 I( O' @/ P( D
printf("Graphics error: %s\n", " S6 }. _5 ^& M; e
grapherrormsg(errorcode));
/ e: G6 V8 z' o9 j5 \( Vprintf("Press any key to halt:");
0 o) t& R7 K/ K( cgetch();
+ r' I: _$ ]2 o5 q/* terminate with an error code */
, K. u1 @' k5 R: V. h d1 }$ V0 |exit(1);
0 F$ g" q3 `7 } s- p} </FONT></P>
4 v g0 ]2 F: F- M0 T<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
9 V1 x- m# |5 T6 m9 G1 O) [<P><FONT color=#0000ff>/* return a pointer to the default palette */ 9 A8 z# I$ Y$ }1 r
pal = getdefaultpalette(); </FONT></P>
& {3 Q- ~; H9 k4 G<P><FONT color=#0000ff>for (i=0; i<16; i++) & J# O U; e4 Y; a$ Y1 C
{ 4 G4 I* ?, j. X8 k
printf("colors[%d] = %d\n", i,
& a2 e4 [; {! ~" x9 k' {! j) [pal->colors); 5 U( _1 u. Z6 `# y/ D* @
getch();
' E% k9 j/ J8 T4 j/ c6 g# h* u4 F} </FONT></P>
1 X$ h) i2 K% Y( r' x6 y/ O<P><FONT color=#0000ff>/* clean up */
+ ?+ b5 N- w, n, i/ Qgetch(); 6 x1 s( ^& N& c* A: X; B6 L
closegraph(); % c9 |, o/ ^* E
return 0; 7 v; T: ~3 M1 d# k$ u+ L0 p
}
9 V. x5 b' o4 k; b</FONT>
2 u6 S0 S3 G7 G. H$ s$ j4 a0 X</P>
. S& D1 ~& P3 J1 C. v# p# \* h" h8 a<P><FONT color=#ff0000>函数名: getdisk </FONT>
2 v' i) W+ i/ K) w' t功 能: 取当前磁盘驱动器号
2 M! ?7 ^8 f: b用 法: int getdisk(void); ; Y4 p" A: i- _2 b8 i p) X$ P- e
程序例: </P>" C8 {7 d0 w$ X# ^9 b
<P><FONT color=#0000ff>#include <STDIO.H>" r. V! u2 f- E
#include <DIR.H></FONT></P>7 W& W" c# m7 V0 c+ M Z: f
<P><FONT color=#0000ff>int main(void)
$ f. l0 {2 m% n{ / o" p) u: x& T
int disk; </FONT></P>
8 e* i# y1 y7 `* W+ h9 e7 s<P><FONT color=#0000ff>disk = getdisk() + 'A'; J. y9 d! f3 ?% Z$ T+ z
printf("The current drive is: %c\n",
3 r" W- a& Z! d4 V i3 V- Bdisk);
8 C3 y& |& t6 I& {, B. Hreturn 0;
9 S. S V( a" R/ u o* r}
+ B: j& f3 c1 V4 t$ |: y7 e V- y% M; c8 l
</FONT>
% Y `2 c) L( @3 i$ \</P>+ S9 j( M$ L" D9 z$ l6 L$ h/ y! k* B5 x
<P><FONT color=#ff0000>函数名: getdrivername </FONT>! D' t# y! h* P3 X
功 能: 返回指向包含当前图形驱动程序名字的字符串指针
% Y4 O; h3 l( ?用 法: char *getdrivename(void); & e; u& D8 q' H4 j0 j( t
程序例: </P>
% o& x$ H4 w% s3 `& s<P><FONT color=#0000ff>#include <GRAPHICS.H>9 x) k \7 g. A2 Z& m
#include <STDLIB.H>
6 v. v1 z% i$ D v% B#include <STDIO.H>+ K+ r# R4 b6 L, @0 Z4 M
#include <CONIO.H></FONT></P>
5 ?1 K. i% `. [: H, `& _" b5 B( w<P><FONT color=#0000ff>int main(void)
( g/ r7 O$ q; B( w+ g$ {{ 6 E& W# k0 n6 Z9 A
/* request auto detection */ : X& e, g2 x" e$ o$ Y) O
int gdriver = DETECT, gmode, errorcode; </FONT></P>
+ }" G3 x: r! g% b1 h- {- E<P><FONT color=#0000ff>/* stores the device driver name */
+ ]+ ]) T) e. i2 g3 I! A. P6 }- {$ echar *drivername; </FONT></P> i& c; T9 c% I$ o' Q
<P><FONT color=#0000ff>/* initialize graphics and local variables */ Z! p0 j0 Y8 o; V8 c! ]
initgraph(&gdriver, &gmode, ""); </FONT></P>
1 h' f5 \. t! }' Y I<P><FONT color=#0000ff>/* read result of initialization */ ( e+ L8 m/ }/ T8 f y/ r
errorcode = graphresult();
$ I3 w0 i; {2 X6 D1 g/* an error occurred */
( \9 T# O8 P8 Sif (errorcode != grOk) , X# z Q0 x, Z, q" B
{ ! m8 J1 F3 `/ x- G! ~
printf("Graphics error: %s\n",
( w& g* g7 J, Z1 U) tgrapherrormsg(errorcode)); 7 _# ^& P$ S* [
printf("Press any key to halt:"); - z7 m$ A( s8 j1 G+ {& w
getch(); 5 h2 v ]% ?- y; D& w0 o7 N3 X
/* terminate with an error code */ 2 d* W& v& R" K& E p: u! n
exit(1); ! H% P" _/ X. j' m* ~
} </FONT></P>
, J' x, L% I/ c, b4 v) C2 z<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>8 q9 E+ x5 ]$ G
<P><FONT color=#0000ff>/* get name of the device driver in use */ 4 f% [/ p0 t' e% ?8 I u
drivername = getdrivername(); </FONT></P>
6 O2 N+ f0 \: l' |& g. h. J<P><FONT color=#0000ff>/* for centering text on the screen */
! L. B/ G1 T3 q" u3 [: ?# Nsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
d" _8 I: m" B& C9 e) t<P><FONT color=#0000ff>/* output the name of the driver */ ; K& K# Y' A2 s- |
outtextxy(getmaxx() / 2, getmaxy() / 2,
& t; A8 L0 e0 v% ^6 t5 idrivername); </FONT></P>: \# Q2 O5 v! Q0 S7 _
<P><FONT color=#0000ff>/* clean up */ & H. T& M% x2 v: v( T, E
getch(); " F6 C6 v5 k! B% p( K
closegraph();
$ x5 v t7 q+ G7 y/ c: u7 P+ }6 @return 0; 4 ]: w$ z; l. Y# N! R! m* J
} ( w- y. S5 F; X/ p( e6 G4 z1 W2 h
</FONT><FONT color=#990000>' `% N0 ?1 I7 d w1 g, C
</FONT></P>
( E; B" D% \& W1 j2 q<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>
4 ~7 u) x* h# Y/ w<FONT color=#000000>功 能: 取磁盘传输地址 & X1 l: |1 F' J( `" x7 O
用 法: char far *getdta(void); ) q7 E+ a) r/ O( K# X* q' u
程序例: </FONT></FONT></P>9 ~2 L C7 D4 V2 d9 l Z% X# [
<P><FONT color=#0000ff>#include <DOS.H>
6 R6 y: F7 F' Q; V# M$ x#include <STDIO.H></FONT></P>) _! p2 S3 c( d/ W; O
<P><FONT color=#0000ff>int main(void) 5 k: h6 W/ F3 x% Q+ R9 h) x5 F
{
( R3 y7 G+ Y8 T1 |/ C+ Vchar far *dta; </FONT></P>
( @: P3 d6 M. F% P8 \# ~3 V5 i, V; F<P><FONT color=#0000ff>dta = getdta(); 9 N9 I r# V% T( L
printf("The current disk transfer \ . N; A: @' U& L/ ~6 i% O* r+ a
address is: %Fp\n", dta);
, S, }* {0 s* R, U8 S' c9 N, sreturn 0; 2 Z6 I' N4 h: k( C
} . C8 b' r' n' D) v5 M
</FONT><FONT color=#990000>" B2 n" c' [4 b+ R' I! @
</FONT></P>7 R) y) b1 B1 r: C7 F
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>: d: X9 P) b! i. v( J2 Z3 D2 S! N8 s
<FONT color=#000000>功 能: 从环境中取字符串
. O6 z( o g O) t1 J1 q用 法: char *getenv(char *envvar); : `) ~8 l( ~$ z9 D u2 D, q4 l
程序例: </FONT></FONT></P>3 P% |# _& n+ `5 l7 a5 u. {. v- X
<P><FONT color=#0000ff>#include <STDLIB.H>+ {" [% t0 E: E' O5 I* J
#include <STDIO.H>( t0 _5 P/ F" o- P i- M
</FONT></P>- a, Y: H& d9 ?2 v* o8 C
<P><FONT color=#0000ff>int main(void) ( c& @& l n O
{ 9 O+ v0 Z/ h0 M1 `. l4 T
char *s; </FONT></P>
- y# p2 {* p8 i" ]% @% z- b<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */
% ^1 X" W# ?8 g* v$ [+ G( ]printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>
^& f; d8 u. f" R' [3 }3 @0 ?<P><FONT color=#0000ff>return 0; ) G( t; p6 y) p9 n9 \, X: Q
} </FONT><FONT color=#990000>) C. V7 U8 G4 k% \
; `7 K# U* R O& Y0 u/ i, ~' \3 J- p+ g4 Y" t& U
</FONT></P>9 `3 Y1 @/ b' Y/ |! q, F
<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT> ^ ]7 l) M+ W' ]6 Y# j
功 能: 取文件分配表信息
a# G1 _# q/ ]1 v4 b; W" H用 法: void getfat(int drive, struct fatinfo *fatblkp);
: F- B4 M: l8 D9 u6 `) g程序例: </P>9 y0 `& x# ^+ K4 I1 D0 E" A9 ?- f
<P><FONT color=#0000ff>#include <STDIO.H>2 @% b. j+ U% }
#include <DOS.H></FONT></P>
* g) W2 t$ t+ U) W<P><FONT color=#0000ff>int main(void)
0 K0 i, F/ E2 L: F% f" V8 f# r. |{ ! w6 \: `$ R% G: w0 F- G
struct fatinfo diskinfo; " {0 f x% w5 v& p
int flag = 0; </FONT></P>: ~ n) E- e2 z5 {/ C7 h
<P><FONT color=#0000ff>printf("Please insert disk in drive A\n");
/ _* B; I1 f5 I! K& g7 V5 V: cgetchar(); </FONT></P>
) W( U' o$ G3 k. A; A5 B8 Y! E<P><FONT color=#0000ff>getfat(1, &diskinfo);
B& P9 o* J2 N. H5 ]* ^/* get drive information */ </FONT></P>1 `$ h6 e+ u1 {3 o d. I6 l6 {6 D
<P><FONT color=#0000ff>printf("\nDrive A: is ");
* @9 \. `5 q" vswitch((unsigned char) diskinfo.fi_fatid) ' L. M; x1 x! s
{ 9 T; }$ d2 g( ]# u* C5 I; M
case 0xFD: ) m2 Q# Z. \6 n$ y/ L
printf("360K low density\n");
4 W$ ]( A/ r* u# V0 c9 c5 hbreak; </FONT></P>
" a) d& G z5 t t8 b: r<P><FONT color=#0000ff>case 0xF9:
4 C9 y0 I! ?' ?+ d* h/ Lprintf("1.2 Meg high density\n");
$ l8 @, H) ~. K4 T/ `3 P7 obreak; </FONT></P>" t# i" b+ F5 r F& I6 g" t' k% j
<P><FONT color=#0000ff>default: * M0 b4 A) b0 n0 h- L9 G" g! r' ^
printf("unformatted\n");
- K3 u- q; [0 A5 I+ x0 w0 o8 \8 c3 \flag = 1;
0 |5 k1 H$ ~: R* e) c} </FONT></P>
`$ w8 W! o+ P6 w" k7 l<P><FONT color=#0000ff>if (!flag)
; }2 Y) G3 E; L7 k0 Z [; H{ * n0 S2 {' x, U$ w+ s
printf(" sectors per cluster %5d\n",
- @3 r" G0 Q7 s7 h1 W" `diskinfo.fi_sclus); 2 c' i1 b5 _3 e, }# I
printf(" number of clusters %5d\n",
2 ` f5 [9 @0 }8 z, zdiskinfo.fi_nclus);
& l1 T5 R( ^ Pprintf(" bytes per sector %5d\n",
* ]1 D( P V1 ]8 G8 d! d# l' Sdiskinfo.fi_bysec);
3 D5 n$ [, N/ @5 ~8 S} </FONT></P>3 n5 G* F# b3 m$ a
<P><FONT color=#0000ff>return 0;
0 F8 A$ T# J: D/ ]& `8 H} 5 z6 H) _. \+ h" N
</FONT>3 l: i+ v$ Q) `+ U
</P>
P( N6 Y3 t Q5 h' Q+ {<P><FONT color=#ff0000>函数名: getfillpattern </FONT>
, l, r# \' I% d' c( u; C0 p9 K1 }1 i功 能: 将用户定义的填充模式拷贝到内存中 % m! H1 D+ {. f o, I
用 法: void far getfillpattern(char far *upattern); + _) g9 {6 n$ n, C
程序例: </P>8 s* e: V q4 P/ A9 G/ ]
<P><FONT color=#0000ff>#include <GRAPHICS.H>, [! b' Y0 u* e+ a
#include <STDLIB.H>0 Q; { c2 X' e+ Q$ [: w/ o0 l
#include <STDIO.H>
+ P5 E( q0 W5 X5 F' F5 {1 i#include <CONIO.H></FONT></P>
3 s/ c# m5 b" h, j& x L' {<P><FONT color=#0000ff>int main(void) ; n- F2 C3 S$ \' L( |% ?4 h
{ ! s ^- D7 Q1 ]/ W0 A6 U! B7 J
/* request auto detection */
. o2 w* [: o& x! Gint gdriver = DETECT, gmode, errorcode; - \+ o0 P; ~$ e$ U- R# P
int maxx, maxy;
8 M9 a- y2 m5 M/ f3 U9 Q2 jchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>8 a/ F* @+ U% h5 z
<P><FONT color=#0000ff>/* initialize graphics and local variables */ . |% [0 u% Y6 ~- X8 e, @. M* E
initgraph(&gdriver, &gmode, ""); </FONT></P>& h# v7 S7 J9 w( D
<P><FONT color=#0000ff>/* read result of initialization */
7 p6 A0 T: i4 a- s5 y. E3 B& Werrorcode = graphresult(); - P, R0 h% `2 c4 u
if (errorcode != grOk) /* an error occurred */ 0 o o# {+ E$ {, d! b0 _ _
{
4 K+ H; |( X6 H) z4 b# bprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 y# d9 F, t; K1 ?$ z
printf("Press any key to halt:"); ; `6 l+ Q& g3 N0 q& e
getch(); + k8 a5 {5 \6 j) K! @
exit(1); /* terminate with an error code */ . W: V2 c* k: z8 {( T% q: D8 M
} </FONT></P>
4 K9 P$ ^% c- ?$ n9 J+ |<P><FONT color=#0000ff>maxx = getmaxx();
/ N' v/ z4 ~2 G" {8 D4 T# Gmaxy = getmaxy();
# m- f2 v% M4 s' f5 M" Wsetcolor(getmaxcolor()); </FONT></P>
+ Q9 D1 e8 _0 o/ t% t+ y: }<P><FONT color=#0000ff>/* select a user defined fill pattern */ + x9 \0 F$ T' J0 m% {
setfillpattern(pattern, getmaxcolor()); </FONT></P>- D) E; ^5 f# m) R/ E1 r+ }1 ?" o
<P><FONT color=#0000ff>/* fill the screen with the pattern */ $ p. p2 V5 o% E( m5 B X1 g2 a) U& Z
bar(0, 0, maxx, maxy); </FONT></P>9 F& t8 m; f0 P t; u
<P><FONT color=#0000ff>getch(); </FONT></P>- x/ h# X! ~( K5 O* m/ z/ V
<P><FONT color=#0000ff>/* get the current user defined fill pattern */
\2 Q2 k+ G9 ngetfillpattern(pattern); </FONT></P>3 O. b3 t5 |3 z
<P><FONT color=#0000ff>/* alter the pattern we grabbed */ # x6 W; F5 l- c
pattern[4] -= 1; 1 ~8 i1 K( h5 x! D
pattern[5] -= 3;
1 _# A) h. i% Y5 v4 d% ]pattern[6] += 3;
5 \: s7 g# H) z) P$ N' Npattern[7] -= 4; </FONT></P>9 A& L6 l4 d( i3 i$ T! {* f- c4 |
<P><FONT color=#0000ff>/* select our new pattern */ 8 ^/ ~4 P0 w6 X: L
setfillpattern(pattern, getmaxcolor()); </FONT></P>
! F- U- I% H- _/ V. e% Q3 `<P><FONT color=#0000ff>/* fill the screen with the new pattern */ ) G1 @5 |' X( h$ e; o) `% e
bar(0, 0, maxx, maxy); </FONT></P>2 x) L8 _* K! q4 z" d+ ]6 x: l
<P><FONT color=#0000ff>/* clean up */
) I; t+ @3 F2 }% G$ Cgetch();
7 \1 y. v. V( v! ?0 pclosegraph();
$ @% D- e6 ]0 P% K, \$ G" E6 Lreturn 0;
; Q$ l( \6 H* q4 E# ^} : \, n) i6 U: G) O& Z
</FONT>9 z6 h0 B# \! L8 H% F; i t& B
</P>
+ {- a6 |/ j$ w+ f: W8 Z# E5 S<P><FONT color=#ff0000>函数名: getfillsettings </FONT>! R% p5 `- g1 U: B
功 能: 取得有关当前填充模式和填充颜色的信息
. X& |8 e2 i+ X用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
0 i0 D* X. ]/ r6 f- {4 I: W4 e程序例: </P>6 Z8 K2 ?- `# v/ Z5 p; T
<P><FONT color=#0000ff>#include <GRAPHICS.H>% Q" w5 ^$ t7 d# o
#include <STDLIB.H>
) w& j R$ |+ X- D$ @#include <STDIO.H>
0 h7 o* q# s$ z* C7 \, V#include <CONIO.H></FONT></P># w+ ?3 i) J6 E1 e8 s1 b+ U
<P><FONT color=#0000ff>/ the names of the fill styles supported */ + K& `2 F$ S& b" H M9 ~
char *fname[] = { "EMPTY_FILL", W+ b1 u. B$ D2 _# h
"SOLID_FILL",
8 n7 |; n1 ~4 \* Z"LINE_FILL",
$ n( e% d' |9 q7 G1 W% S"LTSLASH_FILL",
3 w- ^# w8 y, Y! U4 R1 X+ {"SLASH_FILL", 6 w2 a2 p5 K% E2 W8 f S6 a
"BKSLASH_FILL",
, v5 ]4 l0 s; B+ x# K. e"LTBKSLASH_FILL",
6 F A- `& m9 o# }"HATCH_FILL", + j5 z8 d, {& `3 g$ j2 b
"XHATCH_FILL", % x# s6 ?8 ~% W3 w' F4 |
"INTERLEAVE_FILL", 4 b2 j* g2 g1 M3 c
"WIDE_DOT_FILL",
0 s1 C# y, L. I) S% _+ e"CLOSE_DOT_FILL",
+ k }! q" g0 p/ y2 _9 Y4 X* v9 m"USER_FILL" ) i6 k, W# i% T* C
}; </FONT></P>
1 K& a' G3 k, J; y8 M- k<P><FONT color=#0000ff>int main(void)
" w9 ^- c/ t! W% ]' C7 x) m. R+ ?{ % d! Y v( A4 }. m
/* request auto detection */ 1 Y* i2 w7 K0 o1 T0 B! J, ?
int gdriver = DETECT, gmode, errorcode;
+ p4 X) @9 Q; T; j2 M2 ]struct fillsettingstype fillinfo;
' I# j% L0 ^$ F. U' kint midx, midy; , N4 |& C0 F" r0 S9 I* F o1 f
char patstr[40], colstr[40]; </FONT></P>; r: X+ c: P8 _6 S. P
<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 t2 X+ I5 S% k' E5 Winitgraph(&gdriver, &gmode, ""); </FONT></P>' p* i1 T% e; `. u* D
<P><FONT color=#0000ff>/* read result of initialization */ ) l. K3 w1 K3 W' x1 I& H
errorcode = graphresult();
0 \$ p1 a+ S# c9 B% Iif (errorcode != grOk) /* an error occurred */ # x/ J2 f8 o9 E# _
{ 3 o5 `0 R3 W$ v
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 u1 s! f! C. r& c- e
printf("Press any key to halt:"); ; ?# j D+ Y2 j; F3 R5 h9 L+ F2 T" K
getch();
! ?8 a* C7 V) @. mexit(1); /* terminate with an error code */ : X8 L- G, I# z, k( o
} </FONT></P>
% j- T) h) f6 X<P><FONT color=#0000ff>midx = getmaxx() / 2; % G: w# K+ p2 u: P0 _# J7 B
midy = getmaxy() / 2; </FONT></P>
0 Y9 R% L' d6 ~: t& |% ~9 @, |6 F3 `: Y<P><FONT color=#0000ff>/* get information about current fill pattern and color */
/ r5 t) s. v2 N4 f0 Lgetfillsettings(&fillinfo); </FONT></P>
: t5 \5 m* ^4 u1 M) b<P><FONT color=#0000ff>/* convert fill information into strings */ ( G' `" J- X) k
sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
1 O0 S' O( F7 R2 k4 t1 ssprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>2 `' L, [, {* C! ^5 J
<P><FONT color=#0000ff>/* display the information */ 5 H" Y: s$ r* d) e# u- ?, b/ W
settextjustify(CENTER_TEXT, CENTER_TEXT); ' } G. C, f" X. g
outtextxy(midx, midy, patstr); 1 _( O" v( T; W8 j7 i: {
outtextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>; c q% v- K/ a) t8 V
<P><FONT color=#0000ff>/* clean up */ 2 m0 |) n" L, Q% s) w7 x, S, w
getch(); # b; Z k6 K& x
closegraph();
* w# L- a2 R1 x' |return 0;
" m0 r2 u) j2 l, _0 O+ N7 M}
5 q1 y# x/ ~; n8 ~</FONT>! N# h v$ J- t2 k$ s
; I6 ~+ I3 X) s$ P9 E9 V
</P>
: t7 |; J6 q) T% J q<P><FONT color=#ff0000>函数名: getftime </FONT>
) F. x! R5 w/ S, M功 能: 取文件日期和时间 ; S0 I/ U7 k( q# b
用 法: int getftime(int handle, struct ftime *ftimep); ' k" L4 F, i& Y3 g: b; W( ~
程序例: </P>+ K5 F0 q: X: d9 ]# D
<P><FONT color=#0000ff>#include <STDIO.H>4 u" E6 y8 k% Y# z& Z4 X& G8 C( n7 p
#include <IO.H></FONT></P>2 d; u$ N) T' V# Y A' o
<P><FONT color=#0000ff>int main(void)
, V* e3 }' L1 _: K1 q{
+ U" k& D7 j2 W( PFILE *stream;
* F6 ]& K/ ?: m+ _1 s& Zstruct ftime ft; </FONT></P>
, b1 [0 n; v/ I5 G5 T. y6 r4 v<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", 7 A- {2 f/ o& [3 B; p9 m, n" u7 v
"wt")) == NULL)
7 J; W, a, E! L. S% k2 ~0 q" w7 B{ # ~7 O+ j. n! | Q, Q3 f
fprintf(stderr,
; N' W. A5 q: f! H"Cannot open output file.\n");
5 H9 |* U% Y9 W# U, h) \8 Mreturn 1; 3 A; K0 i" d: P' D; s
}
9 w1 y# t9 R1 zgetftime(fileno(stream), &ft); 6 ]( d! y! ~# R( `6 Z8 }( V! s/ i
printf("File time: %u:%u:%u\n",
' g4 J( ~, A$ m K5 I4 A Nft.ft_hour, ft.ft_min, 5 q4 G- ]" i; M
ft.ft_tsec * 2);
( F) _; r9 e6 u9 n# \; Kprintf("File date: %u/%u/%u\n",
" e+ j" F4 p/ I2 c, o$ h2 K! [) Rft.ft_month, ft.ft_day,
1 `2 F6 S# M( e3 @! A, Dft.ft_year+1980); : I7 `7 u9 R2 A0 u5 f" Y1 e
fclose(stream);
, p+ \4 E1 _4 f* q' N, Ireturn 0; & X# ]( m* j; d4 ^! v
} ' l& h9 f! [; d8 f0 A
</FONT>
, a" ?) r# ]8 e: c; Q
. c7 v- N R4 i( X7 p$ i# T</P>! i6 _( m3 v/ A; D
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>! \! {1 {/ ^1 h, }1 I* X( Z! P- N' \. M
功 能: 返回当前图形模式 4 T9 I4 B1 w9 o( f9 t
用 法: int far getgraphmode(void);
: T# v! q, g8 W/ k程序例: </P>5 ]+ @1 L3 q( J) S) J
<P><FONT color=#0000ff>#include <GRAPHICS.H> h( O9 D* r+ M1 G
#include <STDLIB.H>
: R4 x# K. k: k% `! s9 |- b6 f4 j#include <STDIO.H>( ~. s2 Q2 r$ v! n' V) `, n
#include <CONIO.H></FONT></P>
! Y* m, a) i0 c9 r5 k4 B<P><FONT color=#0000ff>int main(void)
. y, Z- u5 u5 Y{
; ?8 M) d7 T3 S5 B/* request auto detection */
7 t; [: b- A E$ Q3 Nint gdriver = DETECT, gmode, errorcode; 6 I; Y6 B% z* t4 z2 Z
int midx, midy, mode;
, x% b% G: k% n: @! B$ H! j: h: zchar numname[80], modename[80]; </FONT></P>
, q( E6 k0 `. z H4 p7 t9 G<P><FONT color=#0000ff>/* initialize graphics and local variables */
: j- c( J# C s3 Y" \, u7 ]6 _initgraph(&gdriver, &gmode, ""); </FONT></P>; h* |5 f, Q8 d# Q6 I8 z
<P><FONT color=#0000ff>/* read result of initialization */ " D0 L: `6 u8 u9 T0 J+ [# K
errorcode = graphresult();
# B/ {# F2 {1 j1 t& ^ _4 o) x/* an error occurred */
- L& d! S) h" [; r; Eif (errorcode != grOk)
; M/ f/ B2 u% L* n{ + H" B% z+ f2 \0 N0 B
printf("Graphics error: %s\n",
, X( ^. p8 F$ J* R* E3 V8 h! Igrapherrormsg(errorcode));
o$ c, D+ w* `! @8 P- C; S7 L5 Jprintf("Press any key to halt:");
$ z8 n4 \7 J3 \" p- Vgetch();
9 U! n" ]# ~' `* k/ u4 D/* terminate with an error code */
' q h V/ _: t0 c; fexit(1); $ t6 S/ f. n. {* h% a- B* f
} </FONT></P>; \ L5 m% M0 E- E' |* z# S
<P><FONT color=#0000ff>midx = getmaxx() / 2; 1 L6 u* R- ^. }% X" E# y& j
midy = getmaxy() / 2; </FONT></P>) t/ t1 ]# V4 z9 q/ r; {! A" F. F
<P><FONT color=#0000ff>/* get mode number and name strings */ 6 Q' I3 K, ~- M* U* n
mode = getgraphmode();
7 g0 u1 U% f5 ]& p4 ^0 I# Usprintf(numname, + J% ]; P% E0 Q+ ]. v* x
"%d is the current mode number.",
: u2 Q( H/ @1 \0 Z+ j* |mode); 8 w0 F# q% J' |/ u' c
sprintf(modename, ; V2 ~7 M+ q% y
"%s is the current graphics mode",
k6 J0 K; Q ^getmodename(mode)); </FONT></P>
6 s# X r0 {5 S) ]/ u& f1 z J! Q<P><FONT color=#0000ff>/* display the information */
4 Q" O/ ^) |( K0 vsettextjustify(CENTER_TEXT, CENTER_TEXT);
* ~% N2 K: E2 v0 L2 z: ^% J( e; qouttextxy(midx, midy, numname);
' k$ K/ D% f7 A7 R; p6 y( Youttextxy(midx, midy+2*textheight("W"),
* ?9 {# z' [& Q( M: Rmodename); </FONT></P># J3 O$ W' s2 l4 g5 w" ?
<P><FONT color=#0000ff>/* clean up */ ) _" i5 U, Y* r* I7 ], m8 `
getch(); ( o% x8 y/ N+ h! R% B- T3 `/ v
closegraph(); ' Q2 Y+ G7 M2 V; R
return 0;
' ^% H0 w; J+ E* [} </FONT>* s/ z/ z: I7 f1 K y( e
- _ @5 E$ M! ]8 Z- A! M) q6 @</P>/ l( @6 _- l1 G" O) O; \" I1 |
<P><FONT color=#ff0000>函数名: getftime </FONT>
( W8 K0 h$ _$ a6 O: q功 能: 取文件日期和时间 2 h9 v0 ?4 q& D+ a2 G, d2 ^4 G
用 法: int getftime(int handle, struct ftime *ftimep); 2 T' O" ]# {/ u5 ^
程序例: </P>
2 v [6 Z" F. w6 s- X6 C<P><FONT color=#0000ff>#include <STDIO.H>* @7 X/ g$ ]1 V& [) H9 d
#include <IO.H></FONT></P>% G+ S' h8 J3 I% U
<P><FONT color=#0000ff>int main(void)
9 Y8 C6 k* m- L) ^( X9 o# c{ ; Y' c3 G: i3 M+ I8 t2 b
FILE *stream; + n. u4 k$ s. s6 O$ j; Q9 l
struct ftime ft; </FONT></P>
, g$ u. `+ f4 w7 ~* g0 _$ w, v& L<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", " _0 Z4 v# b+ b9 V: l ~( H* j% K
"wt")) == NULL) : F" W+ l7 z; q7 r! _. [% {
{
' f7 K, B. F- w; p; G2 e& {fprintf(stderr, & a5 k B: A, K$ m1 C/ o
"Cannot open output file.\n");
. W7 I7 N2 s9 O7 u# \return 1;
1 Y! y" I$ v% ]; F5 U. |# b}
2 g$ X0 `8 T; N2 E- b$ ]/ jgetftime(fileno(stream), &ft); " x5 s) N3 R( l3 G2 f
printf("File time: %u:%u:%u\n", 2 `) |! I0 ]- S8 O! c4 v( h
ft.ft_hour, ft.ft_min,
% e1 f1 l- \7 V1 N" E; W @1 ift.ft_tsec * 2);
& f- P/ B1 X) F7 k/ s% ~printf("File date: %u/%u/%u\n",
; }2 M6 B! J* W/ o7 _* S1 Tft.ft_month, ft.ft_day,
5 s4 n; x J: @' |3 }+ n: U9 ^ft.ft_year+1980); & P2 H; k0 h D1 h
fclose(stream); ! X- a$ \8 H( d% G2 l
return 0; 9 B9 m! |0 j% ?3 i* i I
} </FONT>
4 i* i* `9 S8 m' Z- Z4 M5 j
s R$ g. U( p" {- N2 c l7 _
& ], o% q; Y1 M0 f$ V</P>- [, |4 u% h5 T: n& L. ~
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
! P9 ]$ H! h) l# s功 能: 返回当前图形模式 ; J8 K8 x3 }% a) @4 I; x% F$ _
用 法: int far getgraphmode(void); . U* k U7 G/ G0 r, `) m
程序例: </P>7 A. i0 I, h G+ A% u
<P><FONT color=#0000ff>#include <GRAPHICS.H>& N2 O# V( X: z! w5 I( y/ g
#include <STDLIB.H>
$ b5 }% D5 I6 |9 w9 H) \; P#include <STDIO.H>
; c! }7 ^- U1 q#include <CONIO.H></FONT></P>3 n' h( `: X _5 A \) k
<P><FONT color=#0000ff>int main(void)
; d/ _) v1 W" Y. g- k; y* c$ r{
1 p( Y( U+ a* Y- {% T/* request auto detection */ , q) `2 ]+ x8 ]8 J' q" x
int gdriver = DETECT, gmode, errorcode; n) e3 H+ J6 q' C" ]
int midx, midy, mode; - P+ }2 ]* w' u6 W) l: \8 t
char numname[80], modename[80]; </FONT></P>+ C4 S; ?% s7 r" u# Z* U C
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; E7 ^+ g$ C6 @* o" A8 R& [1 a% f
initgraph(&gdriver, &gmode, ""); </FONT></P>
- J) |2 e- ^7 Y1 G6 b* F<P><FONT color=#0000ff>/* read result of initialization */ # N% x0 ~ y8 J
errorcode = graphresult();
4 ?- ~' r# y" U. W- L' A, b/* an error occurred */
; F* a( C' x/ M$ I( u: `2 Hif (errorcode != grOk) ' |# ? o$ M% k7 L) a8 n: n! V& F
{
* O$ H% {, S+ d0 }) M/ x/ Eprintf("Graphics error: %s\n", 6 O0 D/ M, d# f3 z0 d- j* y& U
grapherrormsg(errorcode));
, Y s3 B: K! \- Yprintf("Press any key to halt:"); 2 Z; P) f4 N( l! [9 Q' u
getch(); ) j: E9 l; J$ t- O/ ~
/* terminate with an error code */ * B$ T% K* \. D4 \9 d# u. z( i2 B
exit(1);
% J. K2 s4 {3 b8 s+ H' Y1 N} </FONT></P>; l/ @1 z& D/ N
<P><FONT color=#0000ff>midx = getmaxx() / 2; 7 y/ {* r9 y; t9 Q+ D
midy = getmaxy() / 2; </FONT></P>
, ], P: a' Z6 k. P<P><FONT color=#0000ff>/* get mode number and name strings */
8 ` B) Z2 p0 n$ smode = getgraphmode(); ( h7 }1 f N( `1 N) E6 p
sprintf(numname, - @8 h+ [/ e; |- f& ~( v
"%d is the current mode number.",
* U, [+ c" @: p X6 R' y9 U4 Zmode); 7 b4 @5 Y0 h- t+ s( _! n' `( Q
sprintf(modename,
7 ?4 L0 }" k5 Q" V( p"%s is the current graphics mode", 4 w0 t1 W; R6 j
getmodename(mode)); </FONT></P>
' {% e& A% P6 R0 w<P><FONT color=#0000ff>/* display the information */
4 @, S! g5 ?( l2 `# j' ^settextjustify(CENTER_TEXT, CENTER_TEXT); ; ?* L' F1 t' u& t L
outtextxy(midx, midy, numname);
! Z6 w. i7 L x6 x6 i$ W Z1 P1 Gouttextxy(midx, midy+2*textheight("W"),
: g; R4 H+ h; K) C- ^/ c# Jmodename); </FONT></P>3 n. C7 r5 a0 ]% f/ h2 I7 o
<P><FONT color=#0000ff>/* clean up */ ! ~. I7 V$ B* Q, O( I5 ^" @( v
getch();
+ h a: e$ k9 ?closegraph();
1 {( s, Y3 v% \; T+ [return 0;
" z; W9 f) J$ |0 p# j} , t$ c! }, H. k+ U8 d6 K
</FONT>
2 [% C& v. V6 a" O+ T$ ^. z) r</P>9 y+ S; _4 x' u" e( c8 P" W1 \
<P><FONT color=#ff0000>函数名: getimage </FONT>6 R6 B+ X* {5 n1 Q4 [+ a
功 能: 将指定区域的一个位图存到主存中 , Y: s4 \; U5 y- q( l
用 法: void far getimage(int left, int top, int right, int bottom, 9 I& o7 k- \7 `' @
void far *bitmap);
( n. E( D" g3 W, i) i程序例: </P>
0 h+ o) [: ]5 C" S" d<P><FONT color=#0000ff>#include <GRAPHICS.H>7 K2 K% |: A2 w/ i3 O/ S* d$ K
#include <STDLIB.H>, N6 P$ d# ? W$ n# X5 S+ ^3 K
#include <STDIO.H>
5 e8 E7 r, ]/ n#include <CONIO.H>+ \. { w. W% t% c
#include <ALLOC.H></FONT></P>9 I% R* x( W) J( T. {& t3 b
<P><FONT color=#0000ff>void save_screen(void far *buf[4]);
' r7 l& P- P( xvoid restore_screen(void far *buf[4]); </FONT></P>7 e7 i. c1 E0 N' k+ n# N
<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>, h, H. F ~6 C# B( f, r
<P><FONT color=#0000ff>int main(void)
2 ]9 C2 H9 A' t1 y{ 9 w- Q% Q3 I, _# ]# M" C( u4 p
int gdriver=DETECT, gmode, errorcode; # h8 \ O, }6 V
void far *ptr[4]; </FONT></P>% d% k# q2 q0 r/ R
<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */
& w9 _7 G8 m7 winitgraph(&gdriver, &gmode, "");
& M2 G3 w1 N ]9 zerrorcode = graphresult(); /* check for any errors */
, b' k" s% c0 v# T$ J, Oif (errorcode != grOk)
+ y1 Z* ~9 x8 p5 C7 g{
! |2 K4 s$ H4 `# M# X8 Oprintf("Graphics error: %s\n", grapherrormsg(errorcode));
0 x' j1 Q7 z m! Bprintf("Press any key to halt:");
8 l" k: N; V. r1 b- d! y# j C( Xgetch();
7 e6 T9 u' d0 \5 @exit(1);
/ Z3 i0 p2 b- T+ A' G! ?9 J}
8 q' n- u, X6 |" O& Nmaxx = getmaxx(); 3 }$ z+ a+ I/ F- R. ~" V
maxy = getmaxy(); </FONT></P>
5 C4 J, h3 X/ m/ U" U<P><FONT color=#0000ff>/* draw an image on the screen */
% o9 E( r( B9 p2 {rectangle(0, 0, maxx, maxy);
) E6 h. c7 g9 Uline(0, 0, maxx, maxy);
f3 }) ]0 i, T( i6 [; iline(0, maxy, maxx, 0); </FONT></P>' \, p3 z: t1 h
<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */
% R F5 Q: Y- L% K7 a' K( g% f N6 [getch(); /* pause screen */
1 d8 x1 r8 s- Y: ?/ d, Scleardevice(); /* clear screen */ + n: W: [+ q" B6 D
restore_screen(ptr); /* restore the screen */ " ^6 @4 w# o! }
getch(); /* pause screen */ </FONT></P>3 M, h$ p# F! e
<P><FONT color=#0000ff>closegraph(); 8 Y5 a0 K8 J5 q$ g) s4 F
return 0; 7 E5 P0 w; e5 G0 t
} </FONT></P>: F2 Q3 {! q9 v+ }0 h$ \: j1 d
<P><FONT color=#0000ff>void save_screen(void far *buf[4])
( ]* f( v# w$ ?; [{
% p5 M2 g$ R" ~unsigned size;
m4 M9 j D7 z$ P# Iint ystart=0, yend, yincr, block; </FONT></P># D H; q) A. W* V$ T6 F) ]
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
* d# j. P5 @* e5 I/ m9 r4 s4 R7 ?yend = yincr;
' t- k& U9 s* G# d( K, Ssize = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>% D! w" u6 ]1 V3 m3 m
<P><FONT color=#0000ff>for (block=0; block<=3; block++)
& Q& } N, q. D0 v{
. h/ O5 V' f L/ J7 q3 V2 N1 Zif ((buf[block] = farmalloc(size)) == NULL)
. g7 m7 ~. f' h{ 6 i8 W2 {7 |! N' V4 k% Y$ L' u8 Y
closegraph();
6 f- Y0 U( h9 k6 m6 ?printf("Error: not enough heap space in save_screen().\n"); ( C5 C# {! e5 U/ A
exit(1);
( a$ R7 _) o$ d* E1 T% }} </FONT></P>
, E3 g1 L' l$ u<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
3 O) S* I* y+ D/ k# f/ U) _ystart = yend + 1;
1 I( w J/ I! K& q L: i5 a+ Qyend += yincr + 1; 1 f5 V9 G1 X8 Y" b4 s
} $ `6 j* _2 R7 T4 o% E" {2 u
} </FONT></P>( b9 l( ?6 K Z' T) V
<P><FONT color=#0000ff>void save_screen(void far *buf[4])
- D' i/ y( L; H+ l/ G3 u5 A4 ~{ 0 y3 L4 t9 R# N X+ T
unsigned size;
; Z) p# B s; m' F- B" qint ystart=0, yend, yincr, block; </FONT></P>) c: }6 Q: F4 |) Y+ f3 Z1 h i
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
: g2 i( V J N" I7 Tyend = yincr; , Z6 m. @9 o' r& G1 r! v
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>3 i4 W( @' w" T+ e. H
<P><FONT color=#0000ff>for (block=0; block<=3; block++) 8 ^3 i+ E2 ]( X# w( f3 L7 ?
{ ; Z7 V: o$ i5 g0 G% P( {+ x
if ((buf[block] = farmalloc(size)) == NULL)
3 Y3 ?' B$ q- }# A0 d( C4 f! _{ & o/ K; c! Z9 J m" @8 w, q! ]8 l- B
closegraph(); 9 B0 b/ ^% F6 `' f( Z z; y
printf("Error: not enough heap space in save_screen().\n"); / b# M3 Z3 K% v& U/ h
exit(1); 9 j. T. o) Q% p$ U' y& \1 L8 Z
} </FONT></P>( k- ?# n- u1 ?5 J
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
6 y; M& b, J* fystart = yend + 1; 5 T* ?$ L4 D% C& l3 r) I* b
yend += yincr + 1; ) F ^1 x1 n( I0 @- y
}
+ e1 Z7 k3 N- u: w; ~% u# ^0 r} </FONT></P>/ D" ~; k* V) V n5 k
<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) : u! f% I" v; N
{ & ~ C; u- P8 B6 U( {% M/ k
int ystart=0, yend, yincr, block; </FONT></P>' j# F9 y" P: z; Z. W
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; C2 s% e& ^& S- o# L/ M
yend = yincr; </FONT></P>
; d. R$ Q/ S& \( h8 k<P><FONT color=#0000ff>for (block=0; block<=3; block++) 7 b7 Q. T D b# |- y p
{
# p; z: W. O5 q' s: f1 L r# Jputimage(0, ystart, buf[block], COPY_PUT);
- i1 a g0 k! J {9 d4 [farfree(buf[block]); ; O/ K2 ^1 A, P3 G6 B
ystart = yend + 1; 8 ^% m5 ~! `& V" B" v6 V5 m
yend += yincr + 1; % ~# a T9 I1 y5 ?2 E
}
! T0 W% Z# B3 @+ T7 t} </FONT>
4 ^" B% `+ L: r6 I9 n9 H6 V$ Q<FONT color=#ff0000>
/ L: y& `0 |' p1 {4 O9 X. \</FONT></P>- p D" Q+ b7 o6 R% {6 N
<P><FONT color=#ff0000>函数名: getlinesettings </FONT>
/ ^. N: v/ s: w2 z功 能: 取当前线型、模式和宽度
8 p/ W8 ]& x( ^用 法: void far getlinesettings(struct linesettingstype far *lininfo):
0 g- ?7 E9 H1 N# s2 f2 P. [. B程序例: </P>6 u9 T& \, N4 A% T q4 p
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; G) V# r' ~* h- M#include <STDLIB.H>
3 T- M% E- c' U5 Y1 F; [" Q9 ?2 W#include <STDIO.H>2 V! ~% j9 {0 [( @" N) p
#include <CONIO.H></FONT></P>2 t' p3 I9 P7 a) c' ^5 E/ q
<P><FONT color=#0000ff>/* the names of the line styles supported */
/ y0 K4 q9 E5 M; [char *lname[] = { "SOLID_LINE", * K J5 f1 x* S: D
"DOTTED_LINE",
! U8 W; C: Z) g5 ~- X' f% r; H# l"CENTER_LINE",
2 v- H" Y" c" s6 Z, Z( D- l"DASHED_LINE", " m D8 S) W7 J( x
"USERBIT_LINE"
% k1 j5 n8 S0 \ A# y}; </FONT></P>2 w9 w4 _6 C" c4 d- ]3 |7 y, c: P
<P><FONT color=#0000ff>int main(void) . s0 o# R6 n* L: m
{ ! V* }- g! G1 A! G. D+ _
/* request auto detection */ # g, }; A5 y( q E
int gdriver = DETECT, gmode, errorcode;
0 @/ ^5 h; s! H: _4 G+ H: d0 h7 Estruct linesettingstype lineinfo; 1 B- Q1 b8 v/ m2 J, s( h5 {3 o% I; v
int midx, midy; $ K1 {+ A' b6 E- u
char lstyle[80], lpattern[80], lwidth[80]; </FONT></P>
. s" |% V9 T( C<P><FONT color=#0000ff>/* initialize graphics and local variables */ % }# l j% ?& }4 q) O
initgraph(&gdriver, &gmode, ""); </FONT></P>
8 }: t8 t/ s. d8 a2 ]<P><FONT color=#0000ff>/* read result of initialization */ & H1 i- c4 } R
errorcode = graphresult();
' _' q! J- k( [6 v8 N9 C: N7 z" oif (errorcode != grOk) /* an error occurred */ 7 W( h2 F; `4 l' I
{ 5 } X6 O/ o8 M9 t- v+ i& G) f( d% T
printf("Graphics error: %s\n", grapherrormsg(errorcode));
) N v, C) ]2 x! @' Q' yprintf("Press any key to halt:"); . t3 \2 [0 L. f" i! f8 x
getch();
" C A% L3 m! \exit(1); /* terminate with an error code */ ' }# y1 P7 ]1 g% v
} </FONT></P>
/ `6 y+ B( l1 M) p, h<P><FONT color=#0000ff>midx = getmaxx() / 2;
8 x! K& m# a2 V" S9 l( Hmidy = getmaxy() / 2; </FONT></P>, p6 s/ D4 _, u9 i/ ^* H5 t
<P><FONT color=#0000ff>/* get information about current line settings */
- b$ I& {! W, w. v9 hgetlinesettings(&lineinfo); </FONT></P>: n* a! s1 e) k/ L7 J
<P><FONT color=#0000ff>/* convert line information into strings */
4 S+ J/ U' Z3 Y isprintf(lstyle, "%s is the line style.",
& d7 `. R: o" O; e1 r0 y) j- Rlname[lineinfo.linestyle]);
3 V$ d6 z0 j) ?- L8 r7 hsprintf(lpattern, "0x%X is the user-defined line pattern.", ( y& d& U+ k2 ?. p6 ?- A
lineinfo.upattern); & ~% v- e; l7 P! X. |" L! o+ E
sprintf(lwidth, "%d is the line thickness.",
7 [% N2 G( U5 _! f Q' Q+ g; xlineinfo.thickness); </FONT></P>
! A; C- n% s. {# ] R+ I<P><FONT color=#0000ff>/* display the information */
- W" { [, v* o5 v) c) d* Usettextjustify(CENTER_TEXT, CENTER_TEXT);
+ n/ [: |* ^/ X5 V! w! Aouttextxy(midx, midy, lstyle); + `: p' v3 k6 L0 ]
outtextxy(midx, midy+2*textheight("W"), lpattern);
/ I' y0 y* a2 n7 ~" i' K3 Qouttextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
- b, ^& G' C3 S- k<P><FONT color=#0000ff>/* clean up */
- ^. h; q+ c( tgetch(); 6 V9 s5 F) `. H* X' Y. Z. E6 Z
closegraph(); : N8 n8 [: ?6 Z# O2 t. ~
return 0;
. O8 a! N1 Y& r' ]} </FONT>
% l5 w, n3 T! I3 G% c# _' d2 h; j) A# p7 H0 M: e* m' n
</P>5 S; u* }* w5 S" U0 u
<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>, m9 o% [) l* R! }2 M, H$ c" O) E
功 能: 返回可以传给函数setcolor的最大颜色值
7 J% k! w3 M Q% |; B4 A$ A用 法: int far getmaxcolor(void);
; K3 Z& n5 E% n/ w7 T程序例: </P>* k% s) }; e% K! V; y0 j
<P><FONT color=#0000ff>#include <GRAPHICS.H>
, F* L' r5 {* q3 u) V& I6 {5 U9 c#include <STDLIB.H>* x3 d2 g( x% A$ U% c8 B, F
#include <STDIO.H>
2 Y! c& o* _& ]( m#include <CONIO.H></FONT></P>( J; _ k! v" u* N/ u8 C4 h5 y
<P><FONT color=#0000ff>int main(void) . Q a2 s8 R) r$ q
{
6 w% C/ L4 N5 W! D+ j2 f1 U3 C+ ^& k/* request auto detection */
/ Y4 n5 m$ T1 g/ D& x0 r% W7 N `int gdriver = DETECT, gmode, errorcode;
7 U! M: k3 u- [; C4 F; @. M9 Vint midx, midy; ; v. R; N( M u' a. N
char colstr[80]; </FONT></P>: E1 J$ f$ M) E& J. w! u. N8 c
<P><FONT color=#0000ff>/* initialize graphics and local variables
0 C; ~2 S) x: r*/ initgraph(&gdriver, &gmode, ""); </FONT></P>& _2 w; |) {" k5 ^3 f1 k# a
<P><FONT color=#0000ff>/* read result of initialization */
7 ]& e/ N( T1 o# L7 \: ?errorcode = graphresult(); , |' o2 c& e" }8 g/ `6 p* z
if (errorcode != grOk) /* an error occurred */
5 k1 H3 Y, A- X6 D, w1 A c{ * X6 s% ]4 ^0 T& D! _
printf("Graphics error: %s\n", grapherrormsg(errorcode));
% W" X p* R0 t+ O5 S. dprintf("Press any key to halt:"); $ M$ U# Q7 X/ {9 o& l" r7 J
getch(); ; I- y/ y! h8 a4 i0 {& O
exit(1); /* terminate with an error code */
7 a5 [% M3 f [- d$ q} </FONT></P>0 Z' p, }4 B! x5 T6 q& m3 o
<P><FONT color=#0000ff>midx = getmaxx() / 2;
+ v4 ?) ~% d6 G N; S/ J. K: Y0 Dmidy = getmaxy() / 2; </FONT></P>$ r- Q! L* a& U
<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */
& F3 L$ j5 I5 y* ?2 p+ j$ h; psprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>
{) `1 c. R) c$ a; M! e/ q7 L<P><FONT color=#0000ff>/* display the information */ ) W: p- @: X8 Q0 h/ ~( A# g* K& U
settextjustify(CENTER_TEXT, CENTER_TEXT); 3 _' C3 w0 R/ p! B
outtextxy(midx, midy, colstr); </FONT></P>' F9 m1 B9 P' {: o5 }
<P><FONT color=#0000ff>/* clean up */
; { z7 R# Y ?- K6 Hgetch(); 6 a4 ^0 x6 h+ ~5 I2 F
closegraph(); l; T0 w2 [2 a5 v
return 0;
0 o" K9 X5 B9 `/ ~' x} </FONT>
9 @- s" ]4 ^3 x1 K/ C9 |" E* ]4 m4 Z$ S
* D M6 p1 V/ X) e4 Q5 S* i$ x/ D</P>; Y; p6 Q. d: \7 c. `
<P><FONT color=#ff0000>函数名: getmaxx </FONT>
' | U# z% ?2 p7 M `功 能: 返回屏幕的最大x坐标 1 W7 i" D+ g! B) v4 g2 ]
用 法: int far getmaxx(void);
+ l" P. L/ Q( n6 k, N1 A3 J+ M$ j' K/ q程序例: </P>0 L& i! o% ]* m8 s8 W
<P><FONT color=#0000ff>#include <GRAPHICS.H>
# J% d3 N. e2 s2 O8 u+ O#include <STDLIB.H>
) [" s9 J& X" }. Q#include <STDIO.H>+ W- m! `7 V- K3 b* B) [
#include <CONIO.H></FONT></P>2 `% e: V* f1 ~! `
<P><FONT color=#0000ff>int main(void)
! ?- J- d. R8 s* ]# X{
6 w! j1 x+ T9 F0 y. A w/* request auto detection */ " r+ I8 E) ]" U6 `, B4 v, Q5 e Y
int gdriver = DETECT, gmode, errorcode; 4 H Q1 [" r p% D- P
int midx, midy;
) {# Q! w3 B$ G* h7 ]char xrange[80], yrange[80]; </FONT></P>2 Q2 Y" M! q$ S; _& P
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 x6 V" Q0 d" J- h. V% Y, A
initgraph(&gdriver, &gmode, ""); </FONT></P>/ o" J9 l6 B$ T4 ]3 \8 g! q
<P><FONT color=#0000ff>/* read result of initialization */ : ^ H5 ^# q/ r( O
errorcode = graphresult();
% J* r. o- u5 o8 ]if (errorcode != grOk) /* an error occurred */ . a4 k, w; C! G5 `
{
- @, O1 A4 t* V( y0 nprintf("Graphics error: %s\n", grapherrormsg(errorcode)); . ^5 ?4 T% N9 M4 k: M& I
printf("Press any key to halt:");
7 w' b3 i5 Q5 d% j" ^/ O2 ~getch();
5 I3 T" R8 R0 ~exit(1); /* terminate with an error code */ . w% [$ i0 O, b
} </FONT></P>, G* A4 J& v* }/ T" ]
<P><FONT color=#0000ff>midx = getmaxx() / 2;
- {- l% I4 Q1 d( w3 m+ t* omidy = getmaxy() / 2; </FONT></P>0 _0 s5 z" Q2 q0 R5 e5 B4 K! V
<P><FONT color=#0000ff>/* convert max resolution values into strings */
( H$ g+ |5 K* F) A3 J, Z! hsprintf(xrange, "X values range from 0..%d", getmaxx()); ( N' G4 M6 C5 y9 f; @9 i& v5 A0 e5 m
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
. h' U' w8 w/ h, X6 b4 u( G<P><FONT color=#0000ff>/* display the information */ 0 @) ^- d" \; h3 B
settextjustify(CENTER_TEXT, CENTER_TEXT); 6 }' G, U" f) ~8 F) }" h
outtextxy(midx, midy, xrange);
, A: L. x* S+ Z) Uouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
! V, T8 I; q- W G4 ]4 c<P><FONT color=#0000ff>/* clean up */
6 s) h/ M' L5 vgetch();
! `& ?! v! F0 b- x$ C& vclosegraph(); 3 B* L% q, Z9 w' L) {) w) B% ?
return 0; ) G; c1 ?, l9 Y! z/ L. y9 m( A M9 F
}</FONT> ; ]. ?4 d$ s* [+ w m
9 C2 a0 _2 z% D+ J" g" J. n- r$ r
</P>
/ z# z+ I3 D- K! v: ^<P><FONT color=#ff0000>函数名: getmaxy </FONT>
/ g6 C- w$ u' r$ [功 能: 返回屏幕的最大y坐标
) [# {3 j5 o/ s8 A& v9 X用 法: int far getmaxy(void); $ ~% ]: W) S9 m% F4 K
程序例: </P>6 Q/ a8 O! O' i6 F2 u
<P><FONT color=#0000ff>#include <GRAPHICS.H>( K7 y1 ]: z! ~ A% j% e) t
#include <STDLIB.H>
) k" Q; N/ T: U5 D9 |- U& |#include <STDIO.H>7 B1 S+ _5 C) k+ x
#include <CONIO.H></FONT></P>
0 L, r, }' ^1 J1 |9 z" R5 D<P><FONT color=#0000ff>int main(void) 3 V+ H, k4 S. P9 D5 ^/ X7 c
{ , A* {9 l; l' U: N+ \/ O. @
/* request auto detection */ % I8 C6 `( J* q( O, U3 P
int gdriver = DETECT, gmode, errorcode;
( Q1 S6 ]( Q sint midx, midy;
8 p. b5 O- f# I0 W/ f. e& Nchar xrange[80], yrange[80]; </FONT></P>
! T" s7 o* v. C7 K) v" M" k3 }1 x<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; b1 ~6 n6 N7 ^; U
initgraph(&gdriver, &gmode, ""); </FONT></P>& i* H7 P! K* l0 a. D
<P><FONT color=#0000ff>/* read result of initialization */
6 W$ g1 ~% o4 k9 P3 [errorcode = graphresult(); $ x0 |& S2 q9 Q! X% q, H) A) R
if (errorcode != grOk) /* an error occurred */ : L0 i$ X/ K1 o6 e' g
{ / J" Z5 N# e/ ~' t1 }
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ) V6 H& P8 Z, c- _
printf("Press any key to halt:");
( w# i5 R- F: v" O2 ~' c. r8 q- wgetch();
i* d8 f/ h/ D9 Pexit(1); /* terminate with an error code */ 3 W$ @. d; k" n2 K: F7 ~
} </FONT></P>
0 E/ A, E* O' |; ^! a# g<P><FONT color=#0000ff>midx = getmaxx() / 2; ' ~4 S, ]) w `0 c& J, b! \
midy = getmaxy() / 2; </FONT></P>
. W. `" ]/ K! Z5 @4 B+ W<P><FONT color=#0000ff>/* convert max resolution values into strings */
8 S( U+ e* g& T( g: b* e0 [; D+ K9 _sprintf(xrange, "X values range from 0..%d", getmaxx()); 3 T9 C% Y* I8 ^+ Z4 {- w. g
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>9 h: w6 x! U4 y V/ _; w5 o9 f/ S
<P><FONT color=#0000ff>/* display the information */ 2 A/ R+ x( J" E# l, L$ ~! H
settextjustify(CENTER_TEXT, CENTER_TEXT);
( s( t! {$ D+ q+ i" Couttextxy(midx, midy, xrange);
' @, Q! Y! I: J9 F, o5 F2 Louttextxy(midx, midy+textheight("W"), yrange); </FONT></P> a- U9 O' w# |1 V' y& s! x
<P><FONT color=#0000ff>/* clean up */
' C3 x# W5 c: K* h7 W# E: pgetch();
# H, C1 n6 c6 }6 g- {/ R, S7 L Xclosegraph();
9 A: }8 }0 n$ } M2 ?return 0;
9 \: U. I/ l/ h9 x: r} </FONT>; j8 K9 a- U; z8 X
</P>" \& C9 D, M( x
<P><FONT color=#ff0000>函数名: getmodename </FONT>
( j3 j: j- H- X0 ?1 ~; C功 能: 返回含有指定图形模式名的字符串指针
$ z, i; Y# m+ V N0 a# E用 法: char *far getmodename(int mode_name); 1 q+ L' }0 p( N) k! F
程序例: </P># o. q6 F; ~+ }4 ?4 ]. k. q+ V
<P><FONT color=#0000ff>#include <GRAPHICS.H>5 B6 n$ E2 Y7 q. e; f; Y8 G
#include <STDLIB.H>3 U! b2 J$ Z" I' {
#include <STDIO.H>
+ J& e+ n7 ?1 t; S" h: l#include <CONIO.H></FONT></P>
2 a1 i0 |( d# k" X( _/ J<P><FONT color=#0000ff>int main(void) ; h1 Z9 n2 o) i# B+ }+ l4 f# }" l2 S
{ * E# O( s) w0 F0 p8 y$ F
/* request autodetection */
0 A2 _1 w7 F4 F( X! Xint gdriver = DETECT, gmode, errorcode;
$ z1 q0 I& @+ b& m" uint midx, midy, mode; & _# ]4 ~. m0 p% r: R+ \& \% Z! b
char numname[80], modename[80]; </FONT></P>" Q$ i7 }* G7 ?, S' {( K3 }
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! s x! e7 I1 G" p! |
initgraph(&gdriver, &gmode, ""); </FONT></P>: D8 }3 A8 ?# Q2 L8 i; G) E+ M
<P><FONT color=#0000ff>/* read result of initialization */
, b9 C# t# b: q- c7 qerrorcode = graphresult();
4 M9 l# ~& Z5 K; Q. yif (errorcode != grOk) /* an error occurred */
2 ^" ^; R! I) v7 U& \1 o. \' y1 M" \{
* O1 `! H5 k" O( Q6 D- Xprintf("Graphics error: %s\n", grapherrormsg(errorcode));
; ^* \2 e" d# p# s: @printf("Press any key to halt:");
( `& i. ^' p! c. J0 I3 Vgetch();
% E' s& q4 n- Y9 e" jexit(1); /* terminate with an error code */ 5 Y% l% c, e6 f- n
} </FONT></P>
" _- V7 j( y9 J$ a& J<P><FONT color=#0000ff>midx = getmaxx() / 2; 0 U* `. H- P6 {+ E* |
midy = getmaxy() / 2; </FONT></P>
, a; e3 E- q& a9 h0 o# F/ o# X ]0 h<P><FONT color=#0000ff>/* get mode number and name strings */ 2 K6 q# s8 d' W3 ? j, W' V ^
mode = getgraphmode(); % @3 |8 u7 b6 I. a, v# B
sprintf(numname, "%d is the current mode number.", mode);
) j( }! \) v E. Msprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>$ T: Y# H8 U4 U. w P& d8 c
<P><FONT color=#0000ff>/* display the information */
8 a3 v, u) P3 ^. bsettextjustify(CENTER_TEXT, CENTER_TEXT); - v. r. ~ _* ~; U6 r4 w
outtextxy(midx, midy, numname); / y8 @$ I+ k$ R# n; N v
outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>
% P) n( r) Y& x* a8 a" D<P><FONT color=#0000ff>/* clean up */ ( u. ^( ]( B% {1 ^) |
getch();
4 @2 O7 q C7 h% K) k& oclosegraph();
1 D# I$ w1 O3 a" vreturn 0; + i7 m3 Q0 D: }) ^* k! \. s
} </FONT>8 O. Z M- A' {1 z( P
5 h# F+ q6 w; o: {</P>
* n# U3 q6 n% U8 o# F3 ]# c" W<P><FONT color=#ff0000>函数名: getmoderange</FONT>
! W6 }/ ~7 K4 @" H) D) ]功 能: 取给定图形驱动程序的模式范围 8 A. u: N! f9 ^
用 法: void far getmoderange(int graphdriver, int far *lomode, 9 V/ v! N6 y& Z7 w$ v% F# N$ S
int far *himode);
$ x$ w6 P! b8 x' H程序例: </P>
/ X' M5 ?$ u8 i' u. R% ]# r: T<P><FONT color=#0000ff>#include <GRAPHICS.H>
- ^7 N7 z6 j7 Q#include <STDLIB.H>
) r2 X, N ^! V& t#include <STDIO.H>$ J `9 e$ y! H2 e# P {2 k8 R
#include <CONIO.H></FONT></P>/ ^) R% z0 l2 j; G! [
<P><FONT color=#0000ff>int main(void)
3 L3 R: H3 d. n' N2 Z9 i% Z{
4 p( K6 Z# `) C4 ^0 {8 i1 {/* request auto detection */
8 d8 m9 W+ A( G- Zint gdriver = DETECT, gmode, errorcode;
* g6 ]7 n4 U* M% W3 rint midx, midy;
) p, P( k9 I# K4 v8 Y$ ]int low, high; 5 Q' [* z7 \! i6 K3 Y
char mrange[80]; </FONT></P>
! a6 U& `: C% B6 n% Q9 F' g; b<P><FONT color=#0000ff>/* initialize graphics and local variables */ : i2 M. N1 G. j$ ~' _: H
initgraph(&gdriver, &gmode, ""); </FONT></P>
) t5 M7 o# _7 F, s<P><FONT color=#0000ff>/* read result of initialization */ 8 f. I, A% [( ~9 L) ^; V5 {' i
errorcode = graphresult();
" y d0 c1 o( V' _' g2 g# `if (errorcode != grOk) /* an error occurred */
3 w. S! e- ~. J) g2 J{
! Q ]$ r m- @. X! a$ Eprintf("Graphics error: %s\n", grapherrormsg(errorcode));
. N4 ~2 ~+ H& e7 q2 A- S, \' {4 eprintf("Press any key to halt:");
& D/ C5 N6 q) b1 a* `/ {4 Tgetch();
( l9 T9 X3 e6 H7 C% U) Eexit(1); /* terminate with an error code */ ' `" `( s7 y8 Y5 q2 O
} </FONT></P>
! r! a$ y4 H2 ^0 z<P><FONT color=#0000ff>midx = getmaxx() / 2;
$ }; ?9 Z& T" K( a' I; Dmidy = getmaxy() / 2; </FONT></P>
* u; g( p0 G% m/ ]6 P4 {<P><FONT color=#0000ff>/* get the mode range for this driver */ & R2 g! K4 H+ y6 j0 E {
getmoderange(gdriver, &low, &high); </FONT></P>
+ c' M2 M, y* K7 g* n3 H6 M [<P><FONT color=#0000ff>/* convert mode range info. into strings */ . T! i& ^5 R# h% r) U
sprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
* a2 R' _& u1 c* R0 E<P><FONT color=#0000ff>/* display the information */
7 q8 b; i: ?( }5 w/ ~settextjustify(CENTER_TEXT, CENTER_TEXT);
* Y( W Z' P! |5 iouttextxy(midx, midy, mrange); </FONT></P>8 D' `- N& K& e% p9 H3 V5 \
<P><FONT color=#0000ff>/* clean up */
, y% v' M( i8 t3 Y3 Vgetch();
# w L1 w, k- @1 ~: pclosegraph(); 6 _1 h1 h7 O" b- W
return 0; 8 [6 y, h3 O9 Y' I p& x3 w! J
} " S: J. R; m- c8 ?: ]
</FONT>3 X* `+ D9 e4 |9 W, k) M, ~
</P>3 G8 b# J8 `3 m' q1 C' E+ t' J/ B
<P><FONT color=#ff0000>函数名: getpalette </FONT>6 s% d( r# u& x; P! N/ E
功 能: 返回有关当前调色板的信息 + K7 H6 Q9 x9 X9 A4 s$ c0 D% d1 G
用 法: void far getpalette(struct palettetype far *palette); / V% S* x6 A8 N& O& k
程序例: </P>
! C$ P9 R; I! m+ f; X1 Y<P><FONT color=#0000ff>#include <GRAPHICS.H>/ a: h" Z/ A- _4 u9 l5 H3 p5 E
#include <STDLIB.H>
& X7 F: {8 T- F9 k0 L' t* u#include <STDIO.H>) R6 ]% v/ P1 B: N/ M6 d' b
#include <CONIO.H></FONT></P>
. H* A0 n7 P8 y6 P; a" H1 F<P><FONT color=#0000ff>int main(void) 6 g# e# G" w7 H
{ 6 _, }* x4 N: U# ?! D6 V# f# F1 k
/* request auto detection */ + \- w- f/ c" y/ e. t! q8 I
int gdriver = DETECT, gmode, errorcode;
7 |$ x" b2 f& U H# Rstruct palettetype pal;
L% m. j$ j8 P+ b9 t" ochar psize[80], pval[20]; ; z, O- A$ S- C6 G
int i, ht; # M- O" k9 O& F9 q4 x' L3 p
int y = 10; </FONT></P>/ ?$ V, r* x3 b' j9 N8 m
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 2 O& r- W5 w6 H% k7 G0 c/ F7 ]
initgraph(&gdriver, &gmode, ""); </FONT></P>5 O) l& n2 X$ v# @
<P><FONT color=#0000ff>/* read result of initialization */ # y; O3 u" V$ S) ~: a$ @0 _
errorcode = graphresult(); % c$ P7 d* J! F$ x4 f, X9 M
/* an error occurred */ 1 N% ]8 G5 T! y0 B( y
if (errorcode != grOk)
) N2 y/ b' ^: |8 |# x, _+ v{ ) W/ L+ A* t. I, X1 _
printf("Graphics error: %s\n", & F5 T9 T! Z/ `$ Z' w0 j1 Z' N/ O5 l
grapherrormsg(errorcode));
3 l! Y" R5 \2 x3 F4 F$ oprintf("Press any key to halt:"); . c" j/ y% ?/ y' K) z
getch();
! C+ Y" {0 Y( ^3 ]/* terminate with an error code */ + \* Y8 i7 e4 E
exit(1);
/ H& B/ p' B2 t4 o} </FONT></P>
# V% a( U( _ h) u0 g: n# v<P><FONT color=#0000ff>/* grab a copy of the palette */
1 U8 E. Y8 {6 |3 F( ~getpalette(&pal); </FONT></P>
& k4 x0 g- z' F, J) p' m<P><FONT color=#0000ff>/* convert palette info. into strings */ " E4 t+ T2 E& G3 }: E9 R
sprintf(psize, "The palette has %d \ / V# a8 w4 a. _3 g H, Q; W
modifiable entries.", pal.size); </FONT></P>4 B8 Z* w$ B' J0 X5 x! w' n5 Q
<P><FONT color=#0000ff>/* display the information */ : G6 F4 M/ T" h* {
outtextxy(0, y, psize);
8 ~* x/ g$ t6 G4 H( Z1 Xif (pal.size != 0) 0 T- ~- h9 u3 [
{ 5 y, Q) E8 _# e
ht = textheight("W"); % ^! A6 h; ?8 E; n) Z
y += 2*ht;
, j6 R) E6 q! [3 R, K: ^( G+ t4 Routtextxy(0, y, "Here are the current \ E! m5 H/ s( X* I5 J0 r# x
values:");
% l: r- Q8 t- l3 w% oy += 2*ht; 2 }3 j$ l1 s7 I; z; D& h" e2 C3 }
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> {
2 q* E7 r! k, M5 q1 t4 csprintf(pval, ; g7 g( K7 d X; q, S" r' c3 j! E
"palette[%02d]: 0x%02X", i,
6 H6 \+ j3 u) \1 u, Ipal.colors); ' E; l$ d6 h. _# Z, W8 U
outtextxy(0, y, pval);
9 e+ [5 Q, {. X9 U}
% f% h. |$ x7 D! O: y* m( Z6 D- z} </FONT></P>) C* D8 c3 [) Z1 z0 F: b
<P><FONT color=#0000ff>/* clean up */
% J2 C3 V1 p% B$ ?+ Kgetch();
) \5 e8 |/ ` {5 E9 v: {2 ^& v4 cclosegraph(); </FONT>
' w, l' v2 q) E n<FONT color=#0000ff>return 0; : j# h' i0 }8 \5 G
} 4 L/ g- B! Y# Y; F9 G& o
</FONT></P>
9 c |& T: J- m0 q/ n \5 C<P><FONT color=#ff0000>函数名: getpass </FONT>
4 r1 @. K$ B* Q Q8 ~6 I: }功 能: 读一个口令
0 d. {% f4 E& F. @+ V用 法: char *getpass(char *prompt);
0 ~3 }! Q' _9 B- c程序例: </P>% w4 l( ~) k8 _! s1 K
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>1 n, S' C2 R/ f* b" p, |
<P><FONT color=#0000ff>int main(void) , ^5 F& r8 l6 ?0 A" u6 n- e# p
{ 6 Y6 {. i7 e% i2 p" V
char *password; </FONT></P>
M) g' h8 A% N9 E+ D, D; }<P><FONT color=#0000ff>password = getpass("Input a password:"); 5 E& C- U9 `1 \& c: S
cprintf("The password is: %s\r\n",
, J i4 B0 M( h; }" L, |' @1 Upassword); % [ O4 ]9 A3 q7 [' d
return 0; % @3 f( P0 p7 q: ]2 O
}
/ D Z1 b7 ~# V1 _% X9 t. F9 b% \</FONT>) v8 U& ^6 q7 s4 [3 e% o+ Q- q
4 y( C& e: w. G/ n5 {$ _2 C</P>
! }/ E2 [# g# L2 e<P><FONT color=#ff0000>函数名: getpixel </FONT>
4 R4 g0 Y+ m V/ o: _9 L1 o功 能: 取得指定像素的颜色 - y, [/ }- [2 P" m+ ^
用 法: int far getpixel(int x, int y); 7 D1 u' T) f1 X' a
程序例: </P>
' |* y+ ]/ J+ z [# T* a% u {<P><FONT color=#0000ff>#include <GRAPHICS.H>- e2 b& }1 y# L/ a, c, i) m
#include <STDLIB.H>+ F9 N) A$ c3 l: k& ^
#include <STDIO.H>4 { n: L U- l* W' `# L. d5 l& U5 G' C
#include <CONIO.H>
Q3 X4 u# o# j5 Q+ t#include <DOS.H></FONT></P>
4 o5 |) i8 \% w/ T6 g<P><FONT color=#0000ff>#define PIXEL_COUNT 1000
( J, `9 k$ {0 x#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>
' S# ?- I- V" |<P><FONT color=#0000ff>int main(void)
- i# O! s, \! B9 \: ]: K& G. R{ % L3 D/ S, D# ~5 a( p! J
/* request auto detection */
0 l& h, p5 N! s6 V+ W0 `int gdriver = DETECT, gmode, errorcode;
! d" v# O9 @& @! s& Zint i, x, y, color, maxx, maxy,
, _; @6 ?# M# ?' x" R. Y. w% Xmaxcolor, seed; </FONT></P>6 ? e# u% t* S
<P><FONT color=#0000ff>/* initialize graphics and local variables */
+ {$ r1 E. M- U2 ~5 `initgraph(&gdriver, &gmode, ""); </FONT></P>
/ y$ E8 ?9 A |+ h$ D' S4 n2 `0 Y<P><FONT color=#0000ff>/* read result of initialization */
3 |: [0 N, S) n' eerrorcode = graphresult(); , M K& N2 a3 |. m7 ?8 ^
/* an error occurred */ ' U. z. [: a) S5 A) ]% [1 Z
if (errorcode != grOk) " R. D+ X+ C6 d9 u& ?
{
% y( [0 n K- H$ r( h- M0 Xprintf("Graphics error: %s\n", x+ a# z3 O3 O8 q' t
grapherrormsg(errorcode));
# F1 s( f! x# a6 d4 S/ M& c; Lprintf("Press any key to halt:"); # _* b7 S- p$ B& G5 E
getch(); 9 _6 r) J4 }+ w. M p
/* terminate with an error code */ 2 B. u3 [' i% S# V+ p( k
exit(1); $ [& r2 h' g+ c; P; v# H% T
} </FONT></P>
& b" E% \9 r7 f<P><FONT color=#0000ff>maxx = getmaxx() + 1; ) i, _$ a! d9 D8 U9 b; k
maxy = getmaxy() + 1; 3 O# `$ t I/ I9 a8 q
maxcolor = getmaxcolor() + 1; </FONT></P>
9 m- x: e8 D' v* T<P><FONT color=#0000ff>while (!kbhit())
E- @& b' X) Z1 s3 d0 e+ B{
2 Q6 k: m0 B: V/* seed the random number generator */ 1 | g" e& q8 J0 K" q7 s2 g
seed = random(32767);
5 q: x6 B; N: _, ]& rsrand(seed);
1 m: P7 {% H# J6 [7 vfor (i=0; i<PIXEL_COUNT; <br i++)> {
% ~1 Y; n# q$ J& Wx = random(maxx);
* U: D( a, m8 g" M5 |$ k% ky = random(maxy); # C+ M w' o3 R1 ^) q( N- ^8 H
color = random(maxcolor);
: p w. Z( M; {) K$ F- cputpixel(x, y, color); 0 Y* p/ U& Z6 Q3 p( i y
} </FONT></P>
1 S! Y; C0 E3 }9 z<P><FONT color=#0000ff>delay(DELAY_TIME); * C) J% L8 q1 z$ `! ~
srand(seed); , Y3 p1 H/ |1 H$ w
for (i=0; i<PIXEL_COUNT; <br i++)> { / V9 D8 R7 i9 N2 w$ _" i, K. \
x = random(maxx); $ L; ]6 R4 }4 N6 j& v- y
y = random(maxy); / j1 P! ~# }6 x0 |4 v6 H# b3 f6 n
color = random(maxcolor);
7 }- ?! B$ x. n0 Z0 z4 f5 }& pif (color == getpixel)</FONT> </P>8 j+ l, L! X5 I/ e* R& U& a
<P><FONT color=#ff0000>函数名: gets</FONT>
4 e% R8 u9 d) X6 ]2 l3 p) T功 能: 从流中取一字符串
" K: I2 O7 B1 ]* {3 z `用 法: char *gets(char *string);
* \8 f' `! c& N程序例: </P>
8 x) D* L- q* p; r' H+ E<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>3 q3 R3 S: I3 t! \8 n- n5 A
<P><FONT color=#0000ff>int main(void) + V& A0 _& h0 d8 D, f
{ 5 Z3 g0 \+ Y/ D. g+ b
char string[80]; </FONT></P>
0 q f7 C. L. j c. U5 B m<P><FONT color=#0000ff>printf("Input a string:");
2 k3 m1 A" e m$ F9 l) jgets(string);
/ _* M, o+ j4 _8 }2 J- j( ~- vprintf("The string input was: %s\n", # _3 t4 }* j( ^9 W$ |( i' V
string);
# A; H1 \/ V4 `7 {1 @9 m/ y, breturn 0;
8 y/ ], j2 s k" y' u* Y4 J} : e& m q. T, s( q; c
! ^+ U5 O. S1 P6 m2 b4 P</FONT></P>0 ]7 k' `7 c0 I% }% r P
<P><FONT color=#ff0000>函数名: gettext </FONT>
- N' j/ L5 M/ R7 W+ z* G2 O功 能: 将文本方式屏幕上的文本拷贝到存储区 ' {! C) s8 u6 I; ]6 C
用 法: int gettext(int left, int top, int right, int bottom, void *destin); 4 F+ |3 A. v1 H1 O/ r) Q
程序例: </P>) k) H. f( t* x5 l( w' [
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
& d! _# G, g: ~( G<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>& w: b2 Z2 q; N9 _8 G" f
<P><FONT color=#0000ff>int main(void) : v( n3 ]& T# T' C% I# Q* X' k* I
{
7 H# z) P4 j/ J, y2 }( C3 a* M& ^% b8 ?: c& Uint i;
[0 f8 l/ `* X1 @7 g8 B2 h4 B8 U* Hclrscr(); ) j& [( q9 p! _: g+ d" x G9 X2 q
for (i = 0; i <= 20; i++) ) T" | n% e( I5 k# C
cprintf("Line #%d\r\n", i);
# X; z5 N! e+ @9 m% o. x, \gettext(1, 1, 80, 25, buffer);
) t- n) m& n+ o( e9 Bgotoxy(1, 25); 3 n% S# f2 a5 M. D" @7 N4 Y! E: y
cprintf("Press any key to clear screen...");
) |6 S s% E7 ogetch(); 6 ^& M- H/ t( O8 l9 ^/ T) j1 P
clrscr(); 5 f' l8 H! s" _8 ^9 `$ I8 @% P
gotoxy(1, 25);
+ U" S" B$ t. q) Q# l6 Y% xcprintf("Press any key to restore screen...");
+ S4 R3 q4 V4 K3 i5 j0 u6 bgetch();
: R1 u3 W' o( ? C7 `5 p- @puttext(1, 1, 80, 25, buffer);
" U# X: [* a% ~6 `8 z" Ogotoxy(1, 25); 9 ~- O0 n. |3 r2 ?; o% x2 ?
cprintf("Press any key to quit..."); : y( s6 ^+ e- C; J/ E# z
getch();
- H% F4 n# e: {3 }- t5 d7 ^return 0; - x/ U3 E1 F) d
}
z" P7 V& x' R q</FONT>
, Q) A) T5 t- Y$ u6 \ j" `4 D</P>) e2 C1 b/ c9 m1 E: Z
<P><FONT color=#ff0000>函数名: gettextinfo</FONT> ) x/ L0 P3 X* P
功 能: 取得文本模式的显示信息
+ Q+ T+ `. Z1 \% T [. H1 A用 法: void gettextinfo(struct text_info *inforec);
# [! x2 e5 q3 D: u( l程序例: </P>
9 ?. d8 E) p; `' a& H<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
" G! B( q& T' q/ A<P><FONT color=#0000ff>int main(void)
8 D& w& u4 e1 Y{
9 j% l# ?) A' S+ I2 P' y+ V+ g- Estruct text_info ti; 3 W6 @3 T+ g( \# C
gettextinfo(&ti); 0 d" v! R2 g' x3 b
cprintf("window left %2d\r\n",ti.winleft); + I9 U& h9 E9 V& _" f! r
cprintf("window top %2d\r\n",ti.wintop);
6 W$ J& h# e- y0 G5 l3 J4 ~cprintf("window right %2d\r\n",ti.winright);
6 R Q5 P3 a1 t0 Q, qcprintf("window bottom %2d\r\n",ti.winbottom); % e: y- ]* @9 q
cprintf("attribute %2d\r\n",ti.attribute);
7 T3 T4 k$ y" ]* Y( ^' H5 E. h1 Wcprintf("normal attribute %2d\r\n",ti.normattr); % j* r0 N) Q; j/ D& h+ T. t3 M
cprintf("current mode %2d\r\n",ti.currmode);
& L q( Z3 [% `cprintf("screen height %2d\r\n",ti.screenheight); 5 _1 g8 \3 P: x
cprintf("screen width %2d\r\n",ti.screenwidth);
! q$ x6 \ @3 u$ {, e' Icprintf("current x %2d\r\n",ti.curx);
, N$ V. H1 b' G5 F: Scprintf("current y %2d\r\n",ti.cury);
* T, Q2 g" }- P) x S8 W6 Wreturn 0;
. ] G# D2 C. Y- A! c& Q: \} : Q0 [3 |8 p1 I5 E: _8 e! J
</FONT>, m1 n; j2 H+ \
</P>' K. y1 `. K2 ~; ~# P; H" @
<P><FONT color=#ff0000>函数名: gettextsettings </FONT>0 A% S* j: g8 t; l; A7 v5 j4 {
功 能: 返回有关当前图形文本字体的信息 6 Y/ O: s+ X. F& d, Z
用 法: void far gettextsettings(struct textsettingstype far *textinfo); ( }" u- b% H5 [9 g
程序例: </P>
9 N/ W$ f: T, X/ ?) V1 ~5 c2 i' W" G<P>#include <GRAPHICS.H><FONT color=#0000ff>
; k; x0 R' C) z* ~: w0 ]* b& z#include <STDLIB.H>
& M- j8 x- q4 i1 }" d#include <STDIO.H>
# w* s0 m9 R L% E. h#include <CONIO.H></FONT></P>- q8 j* ~, r7 C5 W
<P><FONT color=#0000ff>/* the names of the fonts supported */ 5 r7 @% x2 v5 q$ A. L( n# @/ o% s7 Z
char *font[] = { "DEFAULT_FONT", % S- s* }# i m
"TRIPLEX_FONT",
3 J' ^$ M9 A+ R; D"SMALL_FONT",
1 Q+ }4 u; g% D8 p, ]4 c' I"SANS_SERIF_FONT", 6 ^" W" l8 A6 u/ h! o1 Q% O, V; K
"GOTHIC_FONT" , u' H0 A( [4 D0 l2 d, X
}; </FONT></P>
* x6 C. R: ?+ t7 \- \# x" Q7 @2 h: |<P><FONT color=#0000ff>/* the names of the text directions supported */
- A5 T( m$ z: s7 m' i. Schar *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>
3 l5 b/ I" y; \: R<P><FONT color=#0000ff>/* horizontal text justifications supported */
$ g& A0 T* L/ Z- S* {8 f achar *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>
- }8 j! {$ C8 x0 m) V6 v8 J<P><FONT color=#0000ff>/* vertical text justifications supported */ ! X$ z! r. t, }2 `5 k' S. f& o
char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>$ n* Z; g) L2 z O; l6 a2 U
<P><FONT color=#0000ff>int main(void)
" l, N* V o+ J0 y0 E2 _{
4 d% f& N& l# J) M/* request auto detection */
! D- v, E8 C* g; v" Z. ]int gdriver = DETECT, gmode, errorcode;
& V! k, `- c2 Y$ g! @4 fstruct textsettingstype textinfo; - w" R- ?! u, z6 \& L7 R4 X
int midx, midy, ht; ( _ E6 b9 F! w6 o) Z& |
char fontstr[80], dirstr[80], sizestr[80];
, K- n9 a0 k$ j* V/ D7 W( bchar hjuststr[80], vjuststr[80]; </FONT></P>
0 v* V( J! ~0 p3 C<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 Y9 x, \( s) R! Z: p4 kinitgraph(&gdriver, &gmode, ""); </FONT></P>, D3 Z/ a) A: H% w' o- Z' f* k
<P><FONT color=#0000ff>/* read result of initialization */
& x {9 u% x& S+ E8 A; X# g7 cerrorcode = graphresult(); , F( T1 m1 K. t1 S
if (errorcode != grOk) /* an error occurred */ * r! c4 o6 l! K8 v
{
V9 O, \$ C2 \0 r2 ^printf("Graphics error: %s\n", grapherrormsg(errorcode));
" K3 K* A2 |% u2 |: C: l" kprintf("Press any key to halt:"); 5 N/ L" P) e, l. M9 n
getch();
* {/ T3 j: E4 _9 f8 ^exit(1); /* terminate with an error code */ % z7 d5 n" s5 [+ L# ^2 P
} </FONT></P>
F# v7 M: N2 f6 P; z8 m9 J<P><FONT color=#0000ff>midx = getmaxx() / 2;
1 k% A. z( D, {8 bmidy = getmaxy() / 2; </FONT></P>
1 m5 l/ {& h6 |) F) `$ A<P><FONT color=#0000ff>/* get information about current text settings */ ) L- V% k( `; K( G) ~* ~; R C+ r
gettextsettings(&textinfo); </FONT></P>
2 M- W( s, r2 E0 J I" ~! o1 x<P><FONT color=#0000ff>/* convert text information into strings */ 1 P6 [ x! J" P4 c9 B* j
sprintf(fontstr, "%s is the text style.", font[textinfo.font]);
! K- @$ ?; ` ?4 hsprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
3 H1 J u* D5 Tsprintf(sizestr, "%d is the text size.", textinfo.charsize);
2 U: ^3 r' C6 gsprintf(hjuststr, "%s is the horizontal justification.",
/ I" B! Z2 ]. M5 i2 nhjust[textinfo.horiz]); N! a* J! r! ^, U( V( H
sprintf(vjuststr, "%s is the vertical justification.", 4 F( T: z' x" l8 C2 l# M" F# f
vjust[textinfo.vert]); </FONT></P>* Q, k5 m, r9 r& N
<P><FONT color=#0000ff>/* display the information */ 9 S" i( X! ^+ f/ U( } W
ht = textheight("W");
. `# i! e4 R) g l0 U x; \/ |settextjustify(CENTER_TEXT, CENTER_TEXT);
) Q2 }" [. a5 u) h9 ?7 Q6 touttextxy(midx, midy, fontstr);
2 }, J, ?, f0 |outtextxy(midx, midy+2*ht, dirstr);
6 S; c( d4 V& B9 U+ Louttextxy(midx, midy+4*ht, sizestr); # ~0 I* u- |4 O3 N2 l: {
outtextxy(midx, midy+6*ht, hjuststr);
# c; m& p/ C& J1 W5 Xouttextxy(midx, midy+8*ht, vjuststr); </FONT></P>+ B+ z+ C$ ] H! q% r/ O7 p9 _) E. P6 i
<P><FONT color=#0000ff>/* clean up */
k; Q( z# c* t# m( Jgetch(); - S/ m5 E0 w* P% D1 W
closegraph(); 3 M( r9 k$ f/ F! [5 F2 J0 D6 m
return 0;
- { n5 F) B) u% I6 |* A- [} </FONT>7 P9 H0 [# \) U7 b( e
</P>! j! D8 a# V M9 x
<P><FONT color=#ff0000>函数名: gettime </FONT>; p& ]/ Q' L' h" K. x$ {' B; r
功 能: 取得系统时间 # R$ Z& s3 B. ~6 f
用 法: void gettime(struct time *timep); ) E8 M: D- S# F6 h2 N- H
程序例: </P>$ |! X7 {7 \' Z7 x8 F$ R" p
<P><FONT color=#0000ff>#include <STDIO.H>
3 P# t* r! J% N$ B* V8 h#include <DOS.H></FONT></P>$ B8 P$ I. S, U% z& k8 j
<P><FONT color=#0000ff>int main(void)
. c, S1 r) K2 y; W{ : \) A0 u! H) @$ M) d
struct time t; </FONT></P>; g6 c2 x0 Z% g# [6 N& y
<P><FONT color=#0000ff>gettime(&t); 2 s1 `7 H3 n4 I5 M7 j' Z1 S# j; w
printf("The current time is: %2d:%02d:%02d.%02d\n", ! t* v0 s8 l- y. Z
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); & q" g* H& \+ Y# S: x* S
return 0; , k% U6 _* S. ]7 R3 {7 ^' C9 t
} " A% `: |+ H$ e' J ]
# }& {9 ~0 e$ R
</FONT>6 V) R; P$ ^) P& ?
</P>
: R9 }& _: i8 j) J3 z! @5 e' s<P><FONT color=#ff0000>函数名: getvect </FONT>
0 V8 [/ p0 W$ b4 | w" a功 能: 取得中断向量入口 5 v- J" Q1 d, \+ v) r+ L# c
用 法: void interrupt(*getvect(int intr_num)); , C* Q6 J- a! s
程序例: </P>
+ y1 j( L' k$ L) e, K<P><FONT color=#0000ff>#include <STDIO.H>+ S4 M, i1 I. _4 h1 t: {
#include <DOS.H></FONT></P>
! r0 L/ }- g- u1 D8 a<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>) D' n) v" x& \% w5 Z+ Y+ G
<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */
% i. G( c2 @" R3 F0 K6 d5 Bint looping = 1; </FONT></P>
1 A3 j8 C2 F$ o. r<P><FONT color=#0000ff>int main(void)
@: w' |- P X$ A: s{ + A' j. U& D+ n6 U
puts("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>
% A, a, g4 [9 q& S<P><FONT color=#0000ff>/* save the old interrupt */ / [; o* E# i6 Z
oldfunc = getvect(5); </FONT></P>
$ z$ ]6 J% T$ D, k) `<P><FONT color=#0000ff>/* install interrupt handler */ 4 s8 x5 A4 t+ ~3 w
setvect(5,get_out); </FONT></P>. m% `& P# N7 Y3 H9 v H6 V& x" S) n
<P><FONT color=#0000ff>/* do nothing */
% m, k% M$ C l6 C) Y, h$ P* hwhile (looping); </FONT></P>
0 U' u0 n' g# ]! ~<P><FONT color=#0000ff>/* restore to original interrupt routine */ % q# s) U' E* F% d7 _2 ]# J, R
setvect(5,oldfunc); </FONT></P>2 ^! U) g4 r6 T2 r' {5 z
<P><FONT color=#0000ff>puts("Success"); ! C* F) O, \- i5 s. H7 v8 u
return 0; 2 p9 z- Y5 [) L2 q1 V0 A9 y
}
x* S. M5 t9 N: G( bvoid interrupt get_out()
- P6 A1 F+ F6 o1 }) Y8 x{ - a1 u' F& J8 j) U0 k# \* v: X
looping = 0; /* change global variable to get out of loop */
S4 f% [/ P# a3 c- n} 9 ~3 N/ y$ T* d [0 @
</FONT>
2 L3 }; S5 `$ R" f( e</P>9 q9 A4 Y+ ~$ r/ \# q6 W
<P><FONT color=#ff0000>函数名: getverify </FONT>8 R' U: W& }- ?0 l0 x1 a
功 能: 返回DOS校验标志状态 . v7 [ G$ @) n! P" J
用 法: int getverify(void); $ j% H0 |! c( u0 r
程序例: </P>
" ^ z! L r6 M% R4 y$ e( V8 l<P><FONT color=#0000ff>#include <STDIO.H>! e& s, {% ]1 a( f
#include <DOS.H></FONT></P>
" P2 O3 o" a: T<P><FONT color=#0000ff>int main(void) : C/ y5 @$ F1 e; V4 O% y
{
3 t; b' v0 R i* L! ]. rif (getverify()) ; ]9 c) M3 N7 z" I' o2 W6 M( X
printf("DOS verify flag is on\n"); 9 t% V+ Z% k1 `0 n/ d
else
3 h+ t' E% i7 d& \$ ~- z+ e, Iprintf("DOS verify flag is off\n"); 2 R n5 \& U' B/ p7 D/ s3 t
return 0; ! v8 Z& N, u7 ~/ Q0 z
}
9 w4 n8 e& ]# P; _+ _, O9 V</FONT></P>
, T# L9 E$ `, ~5 W<P><FONT color=#ff0000>函数名: getviewsetting </FONT>( z' n. s3 _/ p8 ^1 A
功 能: 返回有关当前视区的信息 & g% d# Z( t3 A& @. Q- i
用 法: void far getviewsettings(struct viewporttype far *viewport); 0 G5 S1 q$ L7 U2 J9 d0 e) w5 h' p* r# K
程序例: </P>
" C) ^* |" C: c6 _0 l" W* E- f<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 l- \: P6 x. s$ \: }#include <STDLIB.H>% V5 y3 q! @$ [! D+ l+ m) c
#include <STDIO.H>
3 z" O% w* i F0 E: H! {#include <CONIO.H></FONT></P>
7 ?; o! t6 x3 o<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
& E; ]" |4 a. S# _1 f. d<P><FONT color=#0000ff>int main(void)
8 |0 C- t/ W# ~9 Y{ 9 M9 G0 T2 b/ P
/* request auto detection */
% z6 X2 }/ v6 a: E: K* M8 m+ Yint gdriver = DETECT, gmode, errorcode;
9 J/ }9 S7 L0 ?struct viewporttype viewinfo; ; F$ o3 _+ y- O- l% ^* t
int midx, midy, ht; ; Q% Z' j3 _9 D8 ]. X4 Z
char topstr[80], botstr[80], clipstr[80]; </FONT></P>
7 f9 n/ v$ b% ]* H. v4 U, `<P><FONT color=#0000ff>/* initialize graphics and local variables */ & G, _2 ]6 |6 W7 a) j
initgraph(&gdriver, &gmode, ""); </FONT></P>% g4 m# z+ W! e( p% q6 ^
<P><FONT color=#0000ff>/* read result of initialization */
0 D8 A0 ^; z1 Qerrorcode = graphresult(); C) F3 l9 N- m2 Z4 V! F7 }
if (errorcode != grOk) /* an error occurred */
! D% L0 d' Z8 `0 c/ ~3 n{ 9 U. e" G: B2 _7 I1 q2 k. Q
printf("Graphics error: %s\n", grapherrormsg(errorcode));
8 @( d- k% D$ \' ]! a' B/ B1 K7 Cprintf("Press any key to halt:"); : t8 ^2 y- V( {5 |/ S& X7 X0 T3 G$ q
getch();
& \7 o) \/ v4 I- [4 s$ Sexit(1); /* terminate with an error code */ 2 H( |7 ^* K5 @
} </FONT></P>, n& u$ j) `* Q3 Z( S/ f
<P><FONT color=#0000ff>midx = getmaxx() / 2; $ _) W Y! h0 |& k
midy = getmaxy() / 2; </FONT></P>8 W9 k, M/ ~; V! I: D ]
<P><FONT color=#0000ff>/* get information about current viewport */ 3 o/ N0 Y8 t9 f+ X& X0 w# e5 O. z
getviewsettings(&viewinfo); </FONT></P>5 ?+ Z0 I ^2 P! }8 V
<P><FONT color=#0000ff>/* convert text information into strings */
+ T) O C7 x) S+ G0 f1 Y2 |sprintf(topstr, "(%d, %d) is the upper left viewport corner.", 3 J3 Z+ Q. d* @
viewinfo.left, viewinfo.top);
, f$ [$ ^ u9 K; x6 P8 [; r' S0 Msprintf(botstr, "(%d, %d) is the lower right viewport corner.",
( r) ~3 G( g( |: vviewinfo.right, viewinfo.bottom); & _$ U& v8 Q6 f/ ^
sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>
' _8 r" S2 \ \+ S<P><FONT color=#0000ff>/* display the information */ . w2 V* I5 R: z3 y9 I% |9 d
settextjustify(CENTER_TEXT, CENTER_TEXT);
( L6 h# L' w+ S: Y) E$ |0 v# S) x* _ht = textheight("W"); 0 V* k3 @) ]- ~ R. C0 [3 l) N
outtextxy(midx, midy, topstr); & v( u& n, x) d
outtextxy(midx, midy+2*ht, botstr); 0 j, _3 i# h8 Z' ?
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>6 q1 h2 X# h; [, _% l: F) f2 D
<P><FONT color=#0000ff>/* clean up */ & k, X% W4 m. _/ I0 `
getch(); ! {" M7 S+ m3 A: F& \% }
closegraph(); # z' U5 g% f3 s) u0 y4 v6 k# r
return 0;
3 o1 }7 K7 A1 X( u# }: p} </FONT>
1 G! r1 f+ t) Q9 U6 e) v/ ^$ @, n8 R" `: O8 o& v$ v
</P>
; H! L2 m9 f8 {/ i/ o. \<P><FONT color=#ff0000>函数名: getw </FONT>
$ F# \) P1 r9 P' B5 U- V功 能: 从流中取一整数 ) e+ h" S- F0 V7 t
用 法: int getw(FILE *strem);
; N* T1 A1 t6 C4 \程序例: </P>
, a1 ?* v2 `9 {& I. }<P><FONT color=#0000ff>#include <STDIO.H>
; q' _% E, p( ~6 l#include <STDLIB.H></FONT></P>4 c* _# H3 _! A: {# s# T
<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>7 A- \* c$ t1 V( ~1 R
<P><FONT color=#0000ff>int main(void)
$ k w, Y: J; c% u- t5 ?" k{ T# ~' x, h! O5 ?( k3 O
FILE *fp;
! }! a8 B. m [! d* ~% fint word; </FONT></P>
4 L+ N( V0 T( K. ~. G: |<P><FONT color=#0000ff>/* place the word in a file */ : [% r) h, y* C/ d
fp = fopen(FNAME, "wb");
5 z" w8 k e. `3 J3 ^; k+ t" Aif (fp == NULL) + o7 ]1 m! a/ G( K
{
6 m! G' G) B3 kprintf("Error opening file %s\n", FNAME);
* F: L9 R6 u9 A1 m( cexit(1);
0 v7 W2 h" V3 \8 O} </FONT></P>: p1 O' |" k; L
<P><FONT color=#0000ff>word = 94; 8 Z+ n8 z4 G+ z5 K' v
putw(word,fp); : b1 Z1 }$ K- t: E
if (ferror(fp)) ; q6 L d F6 C& n, L& n
printf("Error writing to file\n"); " n: u9 S4 s" x7 s$ V
else
4 [0 \" b4 y8 |- \; ?0 W, w/ Zprintf("Successful write\n");
7 [. z; t# ?5 L1 t4 F% @1 Efclose(fp); </FONT></P>7 G8 l* T8 x2 u: ?
<P><FONT color=#0000ff>/* reopen the file */ 5 `0 W d* W+ a* W5 Y
fp = fopen(FNAME, "rb");
- B5 G; d: y8 I5 z6 _if (fp == NULL) $ O' b2 g: F% r9 p! c
{
" ], m5 x5 j! }printf("Error opening file %s\n", FNAME); 5 s$ T2 n ]) X% N- ?9 d
exit(1);
- p* w0 a' z8 U} </FONT></P>7 K3 M: Z# V; r( V" l, F
<P><FONT color=#0000ff>/* extract the word */ / [4 Y! H2 }4 Z0 k0 V, N5 k
word = getw(fp);
% O- }" }; z- m# L# b7 @if (ferror(fp))
# r1 Z" B8 ]- w" C) X! |printf("Error reading file\n");
# i3 P# B* u& G H$ Gelse
p% j# u6 \ W+ F( A; gprintf("Successful read: word = %d\n", word); </FONT></P>! [& E/ s5 X* b( O7 R
<P><FONT color=#0000ff>/* clean up */
I7 Y* \# q: Z4 W- N5 Kfclose(fp); ( g. d" A" [* k. E ]
unlink(FNAME); </FONT></P>( t! W" f" }, e4 y; {/ P0 q' b/ x( U
<P><FONT color=#0000ff>return 0; 3 O# w5 u1 Q7 ~4 N2 J) M- S
} </FONT>) ^! w. |% Z: D3 R' ]% i3 t
) `0 Z4 @, k, E$ [, f5 [5 A' `2 C3 @
! e$ g% {- j$ y5 ]</P>1 F6 K5 ]9 _& A4 u/ e( j v
<P><FONT color=#ff0000>函数名: getx </FONT>
3 C" w3 z2 J k# {功 能: 返回当前图形位置的x坐标 * ^+ J s) Y0 q6 s4 b4 ]. u
用 法: int far getx(void); - I1 U1 n/ ]6 W! C+ `3 z( W T
程序例: </P>
; E0 R. d5 k6 [6 A/ @% B+ X) Y<P>#include <GRAPHICS.H><FONT color=#0000ff>
7 u- f. F$ \ K4 N" m#include <STDLIB.H>
0 e0 \% k3 g) s" T& v#include <STDIO.H>
# A* o4 b6 p/ w1 j+ ]* _#include <CONIO.H></FONT></P>
0 d1 [; V2 C! _7 t" Q<P><FONT color=#0000ff>int main(void)
% W# [$ r' A7 U% N+ G9 _1 X{ , _! N2 M6 Y2 f0 a. b
/* request auto detection */
1 R# l( v$ ~3 R3 V M Yint gdriver = DETECT, gmode, errorcode; 1 t2 i0 X! g: |1 W
char msg[80]; </FONT></P>$ u+ q# |# s2 B4 q( S# D8 K1 C' n
<P><FONT color=#0000ff>/* initialize graphics and local variables */
, U' u8 W/ {% ginitgraph(&gdriver, &gmode, ""); </FONT></P>
( c. a. ], t' [3 A3 r* U<P><FONT color=#0000ff>/* read result of initialization */
: i A" g3 n) O6 ?: @: Zerrorcode = graphresult();
- k. Q5 i$ n3 _, ?3 b- Hif (errorcode != grOk) /* an error occurred */ 3 ^! `4 W7 A' ]: K/ B$ E5 H
{ 5 }; U, o: y) L7 S1 @8 h* T
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 _0 E8 F. G" G+ F& X1 u
printf("Press any key to halt:");
: A4 Q. h% V( U% H, |2 Zgetch();
; L+ ]3 ]$ N# B% U0 z" @exit(1); /* terminate with an error code */
7 _$ B" Q! h0 E' v2 j} </FONT></P>
8 \$ ^4 D, R& W; j. g<P><FONT color=#0000ff>/* move to the screen center point */ ; e6 f) X, U* f) w, z5 A. N+ G
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>' v& o; }: B& W, p
<P><FONT color=#0000ff>/* create a message string */
( N9 J4 W, y- x, r+ k; B. Hsprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>$ s5 q) n* O! z" m* Y
<P><FONT color=#0000ff>/* display the message */ " l# ^3 N3 s" H7 Y# W& Q
outtext(msg); </FONT></P>) L/ i, n( G+ w( f' d0 {5 R
<P><FONT color=#0000ff>/* clean up */
" c% D) v7 H& @. j/ L9 rgetch();
- J7 R, Z' v( _5 \/ Zclosegraph();
8 z. W3 H: u+ z; P" P0 ?" \return 0;
: I% r% b# N+ e/ H, n& x$ q} </FONT>
9 `# ~- z& d$ y2 B: Q8 g4 o9 t) P7 D3 ^8 ]4 c& U' J7 n5 f
</P>3 W$ [ `: Z6 z6 V4 ~
<P><FONT color=#ff0000>函数名: gety </FONT>
, e$ ^) h5 X8 h4 f" k! z功 能: 返回当前图形位置的y坐标
! p7 s, m" `9 E% |8 w+ f4 O* _$ y用 法: int far gety(void);
- ~( z) M6 U- O. X& J* o' z) N2 I程序例: </P>
" s: H/ H) u2 g& A) L<P><FONT color=#0000ff>#include <GRAPHICS.H>
" _. o% T0 V5 c, b' I: f#include <STDLIB.H>
3 S2 r- F6 N) y% @) {" [% b0 x) x#include <STDIO.H>
# D7 u9 ?# ~8 L/ E! j' j6 x: @#include <CONIO.H></FONT></P>
8 {; u4 S8 u% a( D" T0 v; K& S! N<P><FONT color=#0000ff>int main(void)
, B* s; I* ?, _6 i! N; M% c9 b& J* O{ 4 O- N, b! X+ n9 ^
/* request auto detection */ 4 C$ m x) @: e7 H/ p/ |3 Q
int gdriver = DETECT, gmode, errorcode;
7 X- I3 l0 p& K% Xchar msg[80]; </FONT></P>
- @2 O7 v# o2 d0 |6 X" I1 B<P><FONT color=#0000ff>/* initialize graphics and local variables */
# S" ^9 H% Z) f) V |, Q% Sinitgraph(&gdriver, &gmode, ""); </FONT></P>5 z% f* r: b5 ?7 k/ V9 {# ~9 m
<P><FONT color=#0000ff>/* read result of initialization */
. h1 ~1 K& A( T6 O" I" j6 xerrorcode = graphresult();
, U' R ]- \ V5 K( G; L% Vif (errorcode != grOk) /* an error occurred */
- ~7 G u% w- ^9 p: A; j{ 3 ?5 y: e6 C! d1 j; k# I
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 Z. ]* Y1 \/ ?4 i0 b: Aprintf("Press any key to halt:"); * p0 Q% w7 f; V( A1 Q, x& A
getch();
; T" t' t$ D" Gexit(1); /* terminate with an error code */
/ e+ E" k$ M* K' V% `/ [/ c} </FONT></P>( J6 y+ c$ `9 N2 m
<P><FONT color=#0000ff>/* move to the screen center point */ ' K9 T& k6 ]. _# ?6 q
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>2 H8 }& ~- ?, W6 F" z
<P><FONT color=#0000ff>/* create a message string */
/ k1 V t" Q# O: r+ esprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>
* k- o( w: [# r& l" H<P><FONT color=#0000ff>/* display the message */ 7 P2 T0 U1 A/ u- Y; K
outtext(msg); </FONT></P>, s; @8 y6 X# C7 v
<P><FONT color=#0000ff>/* clean up */
8 U+ l6 w8 j5 X9 B( f+ ?getch(); # d% A+ ?+ t. {% b' N6 {: `* H" Q2 I
closegraph(); 1 y( y. A6 [9 S, _; m# Y
return 0; 7 x+ Y, e# I# f7 Y3 N
} </FONT>
( @. ^8 a$ m7 e7 w0 f
/ W; n+ x$ U& q' H</P>! `4 `+ E5 |' C6 q4 V
<P><FONT color=#ff0000>函数名: gmtime </FONT>" U1 n, o& ~+ {/ Y1 ?8 s2 u
功 能: 把日期和时间转换为格林尼治标准时间(GMT)
: l) O9 @; r( c用 法: struct tm *gmtime(long *clock); 3 y4 X0 `! \: V6 [ z8 @: H/ @9 c
程序例: </P>$ j& d, y% s# l- n; w
<P>#include <STDIO.H><FONT color=#0000ff>
- u8 t% H: E, w! U% Z#include <STDLIB.H>
* G$ G' l4 \% `3 Z# d" e#include <TIME.H>
& R$ C% b) S. W2 B#include <DOS.H></FONT></P>
; ?) a j% G) V1 V<P><FONT color=#0000ff>/* Pacific Standard Time & Daylight Savings */ 4 `0 v, z3 ^- Z, ?3 S+ V, R9 e! ?
char *tzstr = "TZ=PST8PDT"; </FONT></P>" W2 q0 Z( a9 q$ g4 v. R
<P><FONT color=#0000ff>int main(void)
' N; q! D8 z+ } o: N6 k{
' G% U# ^+ ?% }0 dtime_t t; 3 {+ C" }4 j5 v: j' N
struct tm *gmt, *area; </FONT></P>
& M3 T4 r# m+ w<P><FONT color=#0000ff>putenv(tzstr);
) [% j. o8 \5 n. \5 c& L3 w2 ` J2 Wtzset(); </FONT></P>3 q. I J. l5 y4 P1 `( I
<P><FONT color=#0000ff>t = time(NULL);
L& D' \. ~1 ~; Z) J/ uarea = localtime(&t); ( W; V, |( h5 u% E5 Z
printf("Local time is: %s", asctime(area)); & ]+ N$ b Q# K; H5 S
gmt = gmtime(&t);
0 {2 h/ W! ~ E! p9 L- L* z- \printf("GMT is: %s", asctime(gmt));
9 c4 u4 M8 c; @- |( M+ L5 Ereturn 0; ' ~8 [8 X5 _! ]. g0 ^/ _5 o- S* r
} </FONT>9 {' a7 y H0 l6 \
5 ?- y- o5 R/ M/ n" |9 m
</P>" H, o) ]) n7 m6 l3 O: E
<P><FONT color=#ff0000>函数名: gotoxy </FONT>" n8 i p) }6 t9 d* c
功 能: 在文本窗口中设置光标
/ d) m; K T; c* N2 W用 法: void gotoxy(int x, int y);
+ ^3 x# U2 f1 A7 [" U: d. ^6 C程序例: </P>
) Y( A$ B8 c r! i& Q: Q# ~5 N# [<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
/ s) i( _8 T9 {3 u: d# s<P><FONT color=#0000ff>int main(void)
/ W3 F) M( |! H: P, O) A{ * M3 y" z0 C$ E
clrscr(); 6 c) w6 ?% v }. [
gotoxy(35, 12); $ X0 N& y$ H& K1 U; y
cprintf("Hello world");
r' U! M0 X9 e% x9 Ngetch();
1 B9 D+ Y" |) q4 z8 M: G C2 T$ creturn 0;
) |3 b8 B" q; E# ]' f0 }% I0 _}</FONT> ; S( v. y! e% R" c- z- V0 r. ?
+ ~$ N5 [) l0 a
</P>8 F0 _* Y, S9 R7 Z+ D% n
<P><FONT color=#ff0000>函数名: gotoxy </FONT>
& t( R1 B$ a. n, R7 B功 能: 在文本窗口中设置光标 , g# w& l3 A$ s5 {9 O( i: Y/ T2 ~* i
用 法: void gotoxy(int x, int y);
$ j+ C. w: c9 D' F7 c7 l程序例: </P>
& U# D7 N$ _' i3 j8 l6 Z) f<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>. ?& j. ]3 y6 s" h! A) r
<P><FONT color=#0000ff>int main(void)
! D2 ^8 X* T; i5 m0 J$ I{ - d7 y* s3 ^7 G- r# E$ d& S
clrscr();
P+ W6 J, K5 K" H }gotoxy(35, 12); % V T7 Y' Y- r' A. S/ G: Q
cprintf("Hello world");
4 v. J& m9 b+ f9 {" Ogetch();
6 d' M& o0 e7 t' \return 0;
. t6 ^4 @* Z0 i( _} " H, I) J# V9 a6 P9 Z
</FONT>/ U, d* s% G# H! z4 S, l% z
</P>0 f+ o) Q% i: M6 U' e3 Y
<P><FONT color=#ff0000>函数名: graphdefaults </FONT>0 v9 L5 D* o% G+ X4 w; R
功 能: 将所有图形设置复位为它们的缺省值
# j: ~0 y* U0 w# ^( [ z用 法: void far graphdefaults(void); ; j& ?9 S+ k6 R5 g: U
程序例: </P>, Y9 T6 t. F8 m$ }0 y
<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ I2 k$ K) ?. r% j#include <STDLIB.H>
! I- ^% {7 i; O* L; u#include <STDIO.H>! ]! V7 c5 d8 S( f! N& |3 E! u# g
#include <CONIO.H></FONT></P>9 p b5 h+ x( J
<P><FONT color=#0000ff>int main(void) 0 L9 T4 I; k& S4 l7 R
{ 5 ]+ q/ d7 T) Z# J
/* request auto detection */
1 `0 ^& B. d4 v# M7 ]- d7 oint gdriver = DETECT, gmode, errorcode; 0 D; W" J) H+ M5 K( u, N) ^+ ~: y
int maxx, maxy; </FONT></P>) F$ k# r! m; l1 v4 n- D" R! z
<P><FONT color=#0000ff>/* initialize graphics and local variables */
; a6 A i9 C) u: k3 Yinitgraph(&gdriver, &gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>
4 E1 i! C" S5 ~8 v2 b<P><FONT color=#0000ff>/* read result of initialization */
# `1 Z2 J8 p. u# r1 [* _* _' r8 Derrorcode = graphresult();
* P }7 l, Q) F, d: b7 p7 K9 p$ Xif (errorcode != grOk) /* an error occurred */ 7 o7 E$ x/ @8 n1 o* t1 K
{
) `( [8 O7 s& M# N1 G; s1 tprintf("Graphics error: %s\n", grapherrormsg(errorcode)); & Y% V' P4 C) K! K& t% s' s) y
printf("Press any key to halt:");
1 Q! U, b' p% @getch(); 6 u& d; l% f( x- j! A/ O
exit(1); /* terminate with an error code */ ' Q9 \* h; W, i; {
} </FONT></P>
! h( m' G- w0 i5 m<P><FONT color=#0000ff>maxx = getmaxx();
# H4 d/ E; M- H( _# F) {maxy = getmaxy(); </FONT></P>; _' m+ _& |% t! P/ L
<P><FONT color=#0000ff>/* output line with non-default settings */ ; b6 \9 k. F s
setlinestyle(DOTTED_LINE, 0, 3); 1 \* X2 F" K4 ]
line(0, 0, maxx, maxy); . ^5 \; X+ x) N7 `) q" X
outtextxy(maxx/2, maxy/3, "Before default values are restored.");
! v, s% _1 U! Egetch(); </FONT></P>" W/ K$ W1 g0 n
<P><FONT color=#0000ff>/* restore default values for everything */
; u2 S4 J% {# e6 n6 @8 h1 h) A) |graphdefaults(); </FONT></P>
& X7 Q% Y& s3 \/ t! A<P><FONT color=#0000ff>/* clear the screen */
4 \2 A4 q" D/ L) m' c8 scleardevice(); </FONT></P>% P" G: k7 ~; b$ w4 b0 K! y* N9 J8 p
<P><FONT color=#0000ff>/* output line with default settings */
3 v, M$ {9 Y; o: |line(0, 0, maxx, maxy); . d, Q5 X+ s% Z* x7 w
outtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>5 ]2 l: j/ p' y
<P><FONT color=#0000ff>/* clean up */
! S# Q) G8 `! V# ?2 G9 ~7 s5 s3 Vgetch(); 8 ]: p9 y: V/ ~7 O S% c
closegraph(); . _ ?- N( [. D! G6 q
return 0; 0 `! W* E) J* x9 d# b# V+ G
}
" W( D2 @ f% I* |5 N) f</FONT> ^# s2 g. y, [3 x* V2 t
</P>' A- P, k0 j) U( p& n. x; N
<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>- ^; f" ?& Y7 i8 J0 {7 [
功 能: 返回一个错误信息串的指针 8 g, ]# ^# s" Y/ |
用 法: char *far grapherrormsg(int errorcode); # b& _6 Y" d& S) f, }) ?
程序例: </P>
( R* x" @$ ~" ?! P<P><FONT color=#0000ff>#include <GRAPHICS.H>
) @$ Q: O9 B2 J+ j#include <STDLIB.H>% B' B4 @0 a4 u: L1 F! Q
#include <STDIO.H>9 f; g& d5 d0 b) j" j5 V3 z
#include <CONIO.H></FONT></P>
* ^9 M% P! x" }, G<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>' b- |2 p, { B' C- G! U
<P><FONT color=#0000ff>int main(void)
% C' `5 k7 d1 N{
6 a, @; q' {8 O9 k% G, W) f/* FORCE AN ERROR TO OCCUR */ 8 ~; }; `: U9 |+ }
int gdriver = NONSENSE, gmode, errorcode; </FONT></P>9 t/ b0 {# j' P, b
<P><FONT color=#0000ff>/* initialize graphics mode */ 6 v0 q4 s9 t6 z4 ?/ U6 G5 `% K
initgraph(&gdriver, &gmode, ""); </FONT></P>4 l- J b* \6 O2 r" j
<P><FONT color=#0000ff>/* read result of initialization */ 8 X- ]6 r6 M. ~* x
errorcode = graphresult(); </FONT></P>
6 k4 Q {2 n4 g' _% I! F<P><FONT color=#0000ff>/* if an error occurred, then output a */
2 z# a+ A: H7 r5 s. h4 y1 ^9 P; ~/* descriptive error message. */
9 ?* S) I. n% Q' ?. rif (errorcode != grOk) 4 `/ d5 F& i- D; K N P/ m# n3 w
{ 0 T/ _* r$ }; d
printf("Graphics error: %s\n", grapherrormsg(errorcode)); # w# `' Y/ X3 Q
printf("Press any key to halt:"); ' }. @) n% D; b, r- m+ g, R/ _ |) ?6 d
getch(); ( h0 ]( @' v) c3 u4 v
exit(1); /* terminate with an error code */ ) t9 S3 y+ a/ K& l6 @2 I1 S2 E, o3 l
} </FONT></P>
" T* \7 _/ u7 s: X e<P><FONT color=#0000ff>/* draw a line */
! s- P0 y0 p1 E- u' rline(0, 0, getmaxx(), getmaxy()); </FONT></P>
( S( ~9 X* v( ^2 E<P><FONT color=#0000ff>/* clean up */ 5 C z1 W2 X3 h9 t6 v8 O! V
getch(); 7 K' G, i3 _$ \
closegraph(); 0 `3 s8 e5 I ]# M, m$ l
return 0; 7 R: N. m. ]" D \ z/ z- o7 J2 l
}
. `. \; w' {; s% A* T9 J0 z</FONT>
& j/ R' G; @2 q% T! o# x) ^</P>
9 B- Q6 l+ i+ a5 X9 c; f<P><FONT color=#ff0000>函数名: graphresult </FONT>
7 _2 M$ T4 d" F5 Q* i: w: y: E功 能: 返回最后一次不成功的图形操作的错误代码 ; U6 g: h {3 e' P
用 法: int far graphresult(void);
9 k- g% n( y: M1 _4 z( D+ X程序例: </P>7 d( R' U% l& d8 _# @9 f
<P><FONT color=#0000ff>#include <GRAPHICS.H>' G8 d7 ^* K. g) [
#include <STDLIB.H># D4 C6 J3 {' L. L" z
#include <STDIO.H>5 e) e o4 W1 i! V
#include <CONIO.H></FONT></P>
2 }$ q# U) L2 P2 e m* s0 g<P><FONT color=#0000ff>int main(void) ; j" W, `" P. b+ @5 @/ C: M
{
9 }) @) J6 q( J' V* {- _ H/* request auto detection */
4 c4 l4 w% B/ {+ r/ @int gdriver = DETECT, gmode, errorcode; </FONT></P>0 K w2 v- @3 ?
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' p6 Y) P5 G+ z h
initgraph(&gdriver, &gmode, ""); </FONT></P>
! D" P+ t& X! W1 F7 c/ ?, A6 f<P><FONT color=#0000ff>/* read result of initialization */
, R) P% Y; x$ ?& H# Nerrorcode = graphresult(); </FONT></P>
* [9 H* w3 H, j, A$ f! P<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ * t3 c5 q2 W: r3 X8 ~6 w) J9 N
{ ; I! B8 L* x O' d2 i" b
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 t# V& L% Q6 T% W
printf("Press any key to halt:");
; j( m7 W2 g, {9 i) L6 a/ Mgetch(); 8 k, M( Y; E( y
exit(1); /* terminate with an error code */ 2 T S0 r4 p9 r( [+ ]- n
} </FONT></P>8 w, e3 @/ F; T. d+ C7 s$ @$ @
<P><FONT color=#0000ff>/* draw a line */
6 a; p- G7 F" C) ~line(0, 0, getmaxx(), getmaxy()); </FONT></P>9 Z" ]( Q+ c5 N i; F
<P><FONT color=#0000ff>/* clean up */ ! `7 v/ ?0 D, \! }5 w! @
getch(); 8 D+ ?" T1 ~% [! r* @/ ~4 d
closegraph(); 1 O- G9 l) T8 P& N( B
return 0; " @, y, k6 Z; D3 |1 a
}</FONT> 9 c/ ]1 Z' [6 @5 m% i
</P>
- ~# D, ` j- C<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> ; J1 S6 }/ z2 {& N+ }
功 能: 用户可修改的图形存储区释放函数 3 R9 @! D, U# j+ e
用 法: void far _graphfreemem(void far *ptr, unsigned size);
: @8 v( Q+ ]& U, e1 i# k程序例: </P>8 W0 C& o" Z0 [3 U; I& Q y
<P><FONT color=#0000ff>#include <GRAPHICS.H>
# c, K1 q; p; q" H `#include <STDLIB.H>) x$ l2 R2 M1 h- B' W
#include <STDIO.H>
) c; T9 e& g. K0 m" i9 f#include <CONIO.H>
8 S& {/ \ U# |0 v2 y#include <ALLOC.H></FONT></P>
- M+ {+ C4 H! t c9 d0 `<P><FONT color=#0000ff>int main(void) . ^. l& Z7 S. U
{ ! g1 t/ l, V0 ^; G6 o$ I- o8 n1 D
/* request auto detection */ ' w, }) }, F* W1 M3 G6 ]& e
int gdriver = DETECT, gmode, errorcode;
; i' `/ S5 P& D$ L% w! ^int midx, midy; </FONT></P>1 u3 L* d. n' _& g) k
<P><FONT color=#0000ff>/* clear the text screen */
5 O3 Y& ~1 q! |# j" G) Z: z7 _+ U! zclrscr(); 9 ~8 ^, q5 V' R/ O
printf("Press any key to initialize graphics mode:");
7 `* g1 ]0 e3 m- a7 M1 i5 U' Dgetch();
8 n" Z* E' ~8 X, tclrscr(); </FONT></P>
7 i+ p+ c) X- _: i% c0 C<P><FONT color=#0000ff>/* initialize graphics and local variables */ . q9 |! N& m {4 y' j$ Q! d7 N
initgraph(&gdriver, &gmode, ""); </FONT></P>: b' d/ g9 R+ W9 k! N: d
<P><FONT color=#0000ff>/* read result of initialization */ 2 v. v/ d# o( r
errorcode = graphresult(); 8 ~. s) Y' H3 `
if (errorcode != grOk) /* an error occurred */ ( o. w/ D) ?" `7 ^4 O: d
{ , s2 k. C( s! C0 y2 i8 ~. {
printf("Graphics error: %s\n", grapherrormsg(errorcode));
" K c6 `. H b+ r$ ~2 a6 o: f2 dprintf("Press any key to halt:");
% D: z0 u# A B4 ggetch(); 6 ]8 i4 x2 r4 ]
exit(1); /* terminate with an error code */ 5 L5 S% ^' b, Q2 r) z- T
} </FONT></P> d6 H6 w. g$ O! ], |
<P><FONT color=#0000ff>midx = getmaxx() / 2;
6 i+ [2 p1 n( v/ a- }1 I# Amidy = getmaxy() / 2; </FONT></P>+ a: c+ r; D; K7 H& D& ~1 z8 f3 n
<P><FONT color=#0000ff>/* display a message */ - m1 [" k0 T% x \8 I6 I
settextjustify(CENTER_TEXT, CENTER_TEXT); . h2 A' M. l l) q6 M+ r8 _4 E# d
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
: o+ K/ w; o/ k- J<P><FONT color=#0000ff>/* clean up */ % t0 y2 ^- S$ L" v% n5 o5 h
getch(); 9 D- ~% T/ i T
closegraph();
# M% g6 b5 o6 N6 U4 _return 0;
2 }, b4 O+ E3 A; H} </FONT></P>) a$ Q1 ?& @- G" S" }' g, ?
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ 3 l# h/ b4 x* j
void far * far _graphgetmem(unsigned size) 3 j8 [( ^& k- u: v# X
{
2 e3 ] I; a$ r, L2 F3 n$ N# g; yprintf("_graphgetmem called to allocate %d bytes.\n", size);
, L% t& R( a& t* eprintf("hit any key:"); & M0 k+ T" z9 O5 B) r6 W
getch(); $ G0 U2 L# P: C# W
printf("\n"); </FONT></P>) |, c9 N1 b! X7 @% J d2 w2 k, ^
<P><FONT color=#0000ff>/* allocate memory from far heap */ * U; ~6 x6 I M @
return farmalloc(size);
- E3 _) T, [4 b) w} </FONT></P>8 O, T' U0 \0 D! s& }! w
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ % J& t9 d* G% m: ^. R1 c5 S" o1 c
void far _graphfreemem(void far *ptr, unsigned size)
! }. B4 k- V# {* N) j9 ]3 w" P{ # _' a- w# E$ v6 b3 W7 I
printf("_graphfreemem called to free %d bytes.\n", size);
$ Y' O& |8 J" U8 ~# eprintf("hit any key:");
& Y% v2 R8 G, H3 |0 q' Fgetch(); 0 i6 f5 Y: Y$ n* ?
printf("\n"); </FONT></P>
4 F& p2 G( s `<P><FONT color=#0000ff>/* free ptr from far heap */ 5 F' |+ O+ {, i2 w$ i6 M D
farfree(ptr); ; g& w& x% {1 S, \# v0 b$ Z) C
} " D* e4 X A8 z8 u- C2 w# \
</FONT></P>! o9 A7 _1 y6 Z* X
<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>6 Y. { v$ r+ }7 U- f
功 能: 用户可修改的图形存储区分配函数 1 J+ H' N# S3 S& v: X1 n
用 法: void far *far _graphgetmem(unsigned size); ( _7 g( n- o% t' H+ n2 ^2 c, U
程序例: </P>
* q" R4 I9 ?, i) v# R% ?$ l2 c<P><FONT color=#0000ff>#include <GRAPHICS.H>. w0 E D7 W: @" o
#include <STDLIB.H>$ `; L9 ] n* O5 {: H
#include <STDIO.H>
( I' f9 V0 E# I+ \: `# \#include <CONIO.H>, M* c) w* W) C* `
#include <ALLOC.H></FONT></P>
" @4 b9 P* v+ X: h) v& z<P><FONT color=#0000ff>int main(void)
; M& h* K( f7 j. L6 I9 B0 |; ]{
9 p9 e. Y$ C1 ?5 I8 s/* request autodetection */
+ B* }6 r& F; sint gdriver = DETECT, gmode, errorcode; ( L7 ~# y I( j9 z8 Y z& [' e2 }
int midx, midy; </FONT></P>
0 q( L+ ~/ p! H<P><FONT color=#0000ff>/* clear the text screen */
. C7 F+ x" N/ ` M% }clrscr();
* n; g9 }8 K+ r: c3 p* _9 R$ }printf("Press any key to initialize graphics mode:"); : N& v1 z3 l# ^9 U* x
getch(); + u- p$ E/ Q% I- T
clrscr(); </FONT></P>% ]6 p& q( ~: ?. P6 v9 U
<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ w7 i, m. |) [8 {: Cinitgraph(&gdriver, &gmode, ""); </FONT></P>
3 W1 J. b6 D5 w0 b7 k<P><FONT color=#0000ff>/* read result of initialization */
, ~+ c: o1 m+ @$ |& ~1 Qerrorcode = graphresult(); : [' _' z0 K: ?
if (errorcode != grOk) /* an error occurred */
2 |' @7 p; e* m2 }: M4 @" Y/ @{ / R8 e- j$ r' _) Y* K
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 y1 r& o6 A" j; ], a& v
printf("Press any key to halt:");
9 c f% E' K8 G3 j6 n/ Rgetch(); - ~' ~6 Y/ X; e0 M' z* H
exit(1); /* terminate with an error code */
3 P! Z: Y( Y( f} </FONT></P>7 G$ O% G2 f" q; C5 u1 R5 l
<P><FONT color=#0000ff>midx = getmaxx() / 2; - E! W5 A& I5 K/ o$ e
midy = getmaxy() / 2; </FONT></P>
4 m- C2 N4 k3 T, Z3 P" f: `<P><FONT color=#0000ff>/* display a message */ $ F9 H' `* J# f. ^! Z S& j
settextjustify(CENTER_TEXT, CENTER_TEXT); # @( U4 C( g8 V1 x
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P># u7 L5 k6 A! m1 s# t4 W3 Z4 s4 ? l
<P><FONT color=#0000ff>/* clean up */ ( l- g( w. y7 d. C) I6 z
getch(); 2 p; C, c# `# q
closegraph();
$ m: e3 x+ L$ W g: n' t& w: z* kreturn 0; & D7 M6 I d( {. X! j; E2 h
} </FONT></P>
+ ^' i3 y4 w/ ?<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ : z% U: c ^8 y4 k
void far * far _graphgetmem(unsigned size) , N0 T! R9 E# b% F; h
{ 4 a- Z' S; D9 z7 Q9 r) R+ t* t
printf("_graphgetmem called to allocate %d bytes.\n", size);
3 L+ {5 ~$ V) X2 y. B* x4 hprintf("hit any key:");
) _, c1 y8 ^% c2 L' L( lgetch(); $ A) L( _$ v% A$ E4 k! U" F0 v
printf("\n"); </FONT></P>
9 z% e3 I% S+ z1 R m4 n<P><FONT color=#0000ff>/* allocate memory from far heap */
1 n' f+ h4 @0 i: B& H% `return farmalloc(size);
2 X+ p1 g+ r! f! g' h! K4 v6 J} </FONT></P>
9 [' @; n0 b" j! @- n5 x4 Y<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
7 M3 G$ Y' O$ `& r' N0 avoid far _graphfreemem(void far *ptr, unsigned size) / C5 c1 r5 B/ g3 g+ C4 w
{
* H! x, j' t, fprintf("_graphfreemem called to free %d bytes.\n", size); ( p. S. W# r4 j* K: g- E9 P- \+ S
printf("hit any key:"); 2 K( i) I; H0 T* Z" J+ r
getch();
6 |( P# s1 O6 w. K1 d' dprintf("\n"); </FONT></P>2 _3 E) T- F2 W. T- w% Q
<P><FONT color=#0000ff>/* free ptr from far heap */
" z* l- n0 `8 n# wfarfree(ptr);
8 B1 l' z5 h% u. d}
, @; m7 K8 e0 @$ H</FONT></P> |
zan
|