?? s.htm
字號:
<PRE>/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ""); </PRE>
<PRE>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} </PRE>
<PRE>midx = getmaxx() / 2;
midy = getmaxy() / 2; </PRE>
<PRE>/* a user defined line pattern */
/* binary: "0000000000000001" */
userpat = 1; </PRE>
<PRE>for (style=SOLID_LINE; style<=USERBIT_LINE; style++)
{
/* select the line style */
setlinestyle(style, userpat, 1); </PRE>
<PRE>/* convert style into a string */
strcpy(stylestr, lname[style]); </PRE>
<PRE>/* draw a line */
line(0, 0, midx-10, midy); </PRE>
<PRE>/* draw a rectangle */
rectangle(0, 0, getmaxx(), getmaxy()); </PRE>
<PRE>/* output a message */
outtextxy(midx, midy, stylestr); </PRE>
<PRE>/* wait for a key */
getch();
cleardevice();
} </PRE>
<PRE>/* clean up */
closegraph();
return 0;
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">setmem </font>
用 法: void setmem(void *addr, int len, char value);
程序例: </PRE>
<PRE>#include
#include
#include </PRE>
<PRE>int main(void)
{
char *dest; </PRE>
<PRE>dest = calloc(21, sizeof(char));
setmem(dest, 20, 'c');
printf("%s\n", dest); </PRE>
<PRE>return 0;
}
</PRE>
<PRE>函數名:<font size="5" color="#FF0000"> setmode </font>
功 能: 設置打開文件方式
用 法: int setmode(int handle, unsigned mode);
程序例: </PRE>
<PRE>#include
#include
#include </PRE>
<PRE>int main(void)
{
int result; </PRE>
<PRE>result = setmode(fileno(stdprn), O_TEXT);
if (result == -1)
perror("Mode not available\n");
else
printf("Mode successfully switched\n");
return 0;
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">setpalette </font>
功 能: 改變調色板的顏色
用 法: void far setpalette(int index, int actural_color);
程序例: </PRE>
<PRE>#include
#include
#include
#include </PRE>
<PRE>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int color, maxcolor, ht;
int y = 10;
char msg[80]; </PRE>
<PRE>/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ""); </PRE>
<PRE>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} </PRE>
<PRE>maxcolor = getmaxcolor();
ht = 2 * textheight("W"); </PRE>
<PRE>/* display the default colors */
for (color=1; color<=maxcolor; color++)
{
setcolor(color);
sprintf(msg, "Color: %d", color);
outtextxy(1, y, msg);
y += ht;
} </PRE>
<PRE>/* wait for a key */
getch(); </PRE>
<PRE>/* black out the colors one by one */
for (color=1; color<=maxcolor; color++)
{
setpalette(color, BLACK);
getch();
} </PRE>
<PRE>/* clean up */
closegraph();
return 0;
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">setrgbpalette </font>
功 能: 定義IBM8514圖形卡的顏色
用 法: void far setrgbpalette(int colornum, int red, int green, int blue);
程序例: </PRE>
<PRE>#include
#include
#include
#include </PRE>
<PRE>int main(void)
{
/* select a driver and mode that supports the use */
/* of the setrgbpalette function. */
int gdriver = VGA, gmode = VGAHI, errorcode;
struct palettetype pal;
int i, ht, y, xmax; </PRE>
<PRE>/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ""); </PRE>
<PRE>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} </PRE>
<PRE>/* grab a copy of the palette */
getpalette(&pal); </PRE>
<PRE>/* create gray scale */
for (i=0; i setrgbpalette(pal.colors[i], i*4, i*4, i*4); </PRE>
<PRE>/* display the gray scale */
ht = getmaxy() / 16;
xmax = getmaxx();
y = 0;
for (i=0; i {
setfillstyle(SOLID_FILL, i);
bar(0, y, xmax, y+ht);
y += ht;
} </PRE>
<PRE>/* clean up */
getch();
closegraph();
return 0;
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">settextjustify </font>
功 能: 為圖形函數設置文本的對齊方式
用 法: void far settextjustify(int horiz, int vert);
程序例: </PRE>
<PRE>#include
#include
#include
#include </PRE>
<PRE>/* function prototype */
void xat(int x, int y); </PRE>
<PRE>/* horizontal text justification settings */
char *hjust[] = { "LEFT_TEXT",
"CENTER_TEXT",
"RIGHT_TEXT"
}; </PRE>
<PRE>/* vertical text justification settings */
char *vjust[] = { "LEFT_TEXT",
"CENTER_TEXT",
"RIGHT_TEXT"
}; </PRE>
<PRE>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy, hj, vj;
char msg[80]; </PRE>
<PRE>/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ""); </PRE>
<PRE>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} </PRE>
<PRE>midx = getmaxx() / 2;
midy = getmaxy() / 2; </PRE>
<PRE>/* loop through text justifications */
for (hj=LEFT_TEXT; hj<=RIGHT_TEXT; hj++)
for (vj=LEFT_TEXT; vj<=RIGHT_TEXT; vj++)
{
cleardevice();
/* set the text justification */
settextjustify(hj, vj); </PRE>
<PRE>/* create a message string */
sprintf(msg, "%s %s", hjust[hj], vjust[vj]); </PRE>
<PRE>/* create cross hairs on the screen */
xat(midx, midy); </PRE>
<PRE>/* output the message */
outtextxy(midx, midy, msg);
getch();
} </PRE>
<PRE>/* clean up */
closegraph();
return 0;
} </PRE>
<PRE>/* draw an "x" at (x, y) */
void xat(int x, int y)
{
line(x-4, y, x+4, y);
line(x, y-4, x, y+4);
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">settextstyle </font>
功 能: 為圖形輸出設置當前的文本屬性
用 法: void far settextstyle (int font, int direction, char size);
程序例: </PRE>
<PRE>#include
#include
#include
#include </PRE>
<PRE>/* the names of the text styles supported */
char *fname[] = { "DEFAULT font",
"TRIPLEX font",
"SMALL font",
"SANS SERIF font",
"GOTHIC font"
}; </PRE>
<PRE>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int style, midx, midy;
int size = 1; </PRE>
<PRE>/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ""); </PRE>
<PRE>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} </PRE>
<PRE>midx = getmaxx() / 2;
midy = getmaxy() / 2; </PRE>
<PRE>settextjustify(CENTER_TEXT, CENTER_TEXT); </PRE>
<PRE>/* loop through the available text styles */
for (style=DEFAULT_FONT; style<=GOTHIC_FONT; style++)
{
cleardevice();
if (style == TRIPLEX_FONT)
size = 4; </PRE>
<PRE>/* select the text style */
settextstyle(style, HORIZ_DIR, size); </PRE>
<PRE>/* output a message */
outtextxy(midx, midy, fname[style]);
getch();
} </PRE>
<PRE>/* clean up */
closegraph();
return 0;
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">settextstyle </font>
功 能: 為圖形輸出設置當前的文本屬性
用 法: void far settextstyle (int font, int direction, char size);
程序例: </PRE>
<PRE>#include
#include
#include
#include </PRE>
<PRE>/* the names of the text styles supported */
char *fname[] = { "DEFAULT font",
"TRIPLEX font",
"SMALL font",
"SANS SERIF font",
"GOTHIC font"
}; </PRE>
<PRE>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int style, midx, midy;
int size = 1; </PRE>
<PRE>/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ""); </PRE>
<PRE>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} </PRE>
<PRE>midx = getmaxx() / 2;
midy = getmaxy() / 2; </PRE>
<PRE>settextjustify(CENTER_TEXT, CENTER_TEXT); </PRE>
<PRE>/* loop through the available text styles */
for (style=DEFAULT_FONT; style<=GOTHIC_FONT; style++)
{
cleardevice();
if (style == TRIPLEX_FONT)
size = 4; </PRE>
<PRE>/* select the text style */
settextstyle(style, HORIZ_DIR, size); </PRE>
<PRE>/* output a message */
outtextxy(midx, midy, fname[style]);
getch();
} </PRE>
<PRE>/* clean up */
closegraph();
return 0;
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">settime </font>
功 能: 設置系統時間
用 法: void settime(struct time *timep);
程序例: </PRE>
<PRE>#include
#include </PRE>
<PRE>int main(void)
{
struct time t; </PRE>
<PRE>gettime(&t);
printf("The current minute is: %d\n", t.ti_min);
printf("The current hour is: %d\n", t.ti_hour);
printf("The current hundredth of a second is: %d\n", t.ti_hund);
printf("The current second is: %d\n", t.ti_sec); </PRE>
<PRE>/* Add one to the minutes struct element and then call settime */
t.ti_min++;
settime(&t); </PRE>
<PRE>return 0;
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">setusercharsize </font>
功 能: 為矢量字體改變字符寬度和高度
用 法: void far setusercharsize(int multx, int dirx, int multy, int diry);
程序例: </PRE>
<PRE>#include
#include
#include
#include </PRE>
<PRE>int main(void)
{
/* request autodetection */
int gdriver = DETECT, gmode, errorcode; </PRE>
<PRE>/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ""); </PRE>
<PRE>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} </PRE>
<PRE>/* select a text style */
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </PRE>
<PRE>/* move to the text starting position */
moveto(0, getmaxy() / 2); </PRE>
<PRE>/* output some normal text */
outtext("Norm "); </PRE>
<PRE>/* make the text 1/3 the normal width */
setusercharsize(1, 3, 1, 1);
outtext("Short "); </PRE>
<PRE>/* make the text 3 times normal width */
setusercharsize(3, 1, 1, 1);
outtext("Wide"); </PRE>
<PRE>/* clean up */
getch();
closegraph();
return 0;
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">setvbuf </font>
功 能: 把緩沖區與流相關
用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);
程序例: </PRE>
<PRE>#include </PRE>
<PRE>int main(void)
{
FILE *input, *output;
char bufr[512]; </PRE>
<PRE>input = fopen("file.in", "r+b");
output = fopen("file.out", "w"); </PRE>
<PRE>/* set up input stream for minimal disk access,
using our own character buffer */
if (setvbuf(input, bufr, _IOFBF, 512) != 0)
printf("failed to set up buffer for input file\n");
else
printf("buffer set up for input file\n"); </PRE>
<PRE>/* set up output stream for line buffering using space that
will be obtained through an indirect call to malloc */
if (setvbuf(output, NULL, _IOLBF, 132) != 0)
printf("failed to set up buffer for output file\n");
else
printf("buffer set up for output file\n"); </PRE>
<PRE>/* perform file I/O here */ </PRE>
<PRE>/* close files */
fclose(input);
fclose(output);
return 0;
}
</PRE>
<PRE>函數名: <font size="5" color="#FF0000">setvect </font>
功 能: 設置中斷矢量入口
用 法: void setvect(int intr_num, void interrupt(*isr)());
程序例: </PRE>
<PRE>/***NOTE:
This is an interrupt service routine. You can NOT compile this
program with Test Stack Overflow turned on and get an executable
file which will operate correctly. */ </PRE>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -