Documente Academic
Documente Profesional
Documente Cultură
H>
Declaration:
void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);
Remarks:
To start the graphics system, you must first call initgraph.
initgraph initializes the graphics system by loading a graphics driver from disk (or validating a
registered driver) then putting the system into graphics mode.
initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to their
defaults, then resets graphresult to 0.
*graphdriver Integer that specifies the graphics driver to be used. You can give graphdriver
a value using a constant of the graphics_drivers enumeration type.
*graphmode Integer that specifies the initial graphics mode (unless *graphdriver = DETECT).
If *graphdriver = DETECT, initgraph sets *graphmode to the highest resolution
available for the detected driver. You can give *graphmode a value using a
constant of the graphics_modes enumeration type.
pathtodriver Specifies the directory path where initgraph looks for graphics drivers (*.BGI)
first. If they're not there, initgraph looks in the current directory.
If pathtodriver is null, the driver files must be in the current directory. This is
also the path settextstyle searches for the stroked character font files (*.CHR).
*graphdriver and *graphmode must be set to valid graphics_drivers and graphics_mode values or
you'll get unpredictable results. (The exception is graphdriver = DETECT.)
After a call to initgraph, *graphdriver is set to the current graphics driver, and *graphmode is set to
the current graphics mode.
You can tell initgraph to use a particular graphics driver and mode, or to autodetect the attached
video adapter at run time and pick the corresponding driver.
If you tell initgraph to autodetect, it calls detectgraph to select a graphics driver and mode.
Normally, initgraph loads a graphics driver by allocating memory for the driver (through
_graphgetmem), then loading the appropriate .BGI file from disk.
Return Value:
initgraph always sets the internal error code.
- On success, initgraph sets the code to 0
- On error, initgraph sets *graphdriver to -2, -3, -4, or -5, and graphresult returns the same value.
closegraph()
Remarks:
graphics_modes <GRAPHICS.H>
Graphics:
graphics_drivers <GRAPHICS.H>
Declaration:
void far line(int x1, int y1, int x2, int y2);
void far linerel(int dx, int dy);
void far lineto(int x, int y);
Remarks:
line draws a line from (x1, y1) to (x2, y2) using the current color, line style, and thickness. It
does not update the current position (CP).
linerel draws a line from the CP to a point that is a relative distance (dx, dy) from the CP, then
advances the CP by (dx, dy).
lineto draws a line from the CP to (x, y), then moves the CP to (x, y).
rectangle() <GRAPHICS.H>
Declaration:
void far rectangle(int left, int top, int right, int bottom);
Remarks:
rectangle draws a rectangle in the current line style, thickness, and drawing color.
(left, top) is the upper left corner of the rectangle, and (right, bottom) is its lower right corner.
bar() <GRAPHICS.H>
Draws a bar
Declaration: void far bar(int left, int top, int right, int bottom);
Remarks:
bar draws a filled-in, rectangular, two-dimensional bar.
The bar is filled using the current fill pattern and fill color. bar does
not outline the bar.
Declaration:
void far arc(int x, int y, int stangle, int endangle, int radius);
void far circle(int x, int y, int radius);
void far pieslice(int x, int y, int stangle, int endangle, int radius);
Remarks:
arc draws a circular arc in the current drawing color.
circle draws a circle in the current drawing color.
pieslice draws a pie slice in the current drawing color, then fills it using the current fill pattern and
fill color.
90
degrees
180 0 degrees,
degrees 360 degrees
270
degrees
The linestyle parameter does not affect arcs, circles, ellipses, or pie slices. Only the thickness
parameter is used.
If you're using a CGA in high resolution mode or a monochrome graphics adapter, examples in this
Help system that show how to use graphics functions might not produce the expected results.
If your system runs on a CGA or monochrome adapter, pass 1 to those functions that alter the fill or
drawing color (don't pass one of the symbolic color constants defined in GRAPHICS.H).
Remarks:
ellipse draws an elliptical arc in the current drawing color.
fillellipse draws an ellipse, then fills the ellipse with the current fill color and fill pattern.
sector draws and fills an elliptical pie slice in the current drawing color, then fills it using the pattern
and color defined by setfillstyle or setfillpattern.
Argument What It Is
If stangle = 0 and endangle = 360, the call to ellipse draws a complete ellipse.
90 degrees
270 degrees
The linestyle parameter does not affect arcs, circles, ellipses, or pie slices. Only the thickness
parameter is used.
Declaration:
int far getbkcolor(void);
void far setbkcolor(int color);
Remarks:
getbkcolor returns the current background color.
setbkcolor sets the background to the color specified by color.
Color: color is either a number or symbolic name specifying the color to set.
For example, if you want to set the background color to blue, you can call
setbkcolor(BLUE) /* or */ setbkcolor(1)
On CGA and EGA systems, setbkcolor changes the background color by changing
the first entry in the palette.
On an EGA or a VGA, if you call setpalette or setallpalette to change the palette colors, the defined
symbolic constants might not give the correct color.
This is because the color parameter to setbkcolor indicates the entry number in the current palette,
rather than a specific color. (Except 0, which always sets the background color to black).
Return Value:
getbkcolor returns the current background color.
setbkcolor does not return.
floodfill() <GRAPHICS.H>
Remarks:
floodfill fills an enclosed area on bitmap devices.
The area bounded by the color border is flooded with the current fill pattern and fill color.
Use fillpoly instead of floodfill whenever possible so you can maintain code compatibility with
future versions.
Return Value:
If an error occurs while flooding a region, graphresult returns -7.
Declaration:
void far drawpoly(int numpoints, int far *polypoints);
void far fillpoly(int numpoints, int far *polypoints);
Remarks:
drawpoly draws a polygon using the current line style and color.
fillpoly draws the outline of a polygon using the current line style and color, then fills the polygon
using the current fill pattern and fill color.
Each pair of integers gives the x and y coordinates of a point on the polygon.
To draw a closed figure with N vertices, you must pass N+1 coordinates to drawpoly, where the Nth
coordinate == the 0th coordinate.
window() <conio.h>
Declaration: void window(int left, int top, int right, int bottom);
Remarks:
window defines a text window onscreen. If the coordinates are in any way invalid, the call to
window is ignored.
(left, top) is the (x, y) position of the window's upper left corner.
(right, bottom) is the (x, y) position of the window's lower right corner.
The minimum size of the text window is one column by one line.
void main(void)
{
clrscr();
window(10,10,20,20);
textcolor(BLACK);
textbackground(WHITE);
cprintf("This is a test\r\n");
getch();
}
gotoxy() <CONIO.H>
Remarks:
gotoxy moves the cursor to the given position in the current text window.
Declaration:
void textattr(int newattr);
void textbackground(int newcolor);
void textcolor(int newcolor);
Remarks:
These functions work for functions that produce text-mode output directly to
the screen (console output functions).
textattr sets both the foreground and background colors in a single call.
(Normally, you set the attributes with textcolor and textbackground.)
These functions do not affect any characters currently on the screen. Once you have called one of
these three functions, all subsequent functions using direct video output (such as cprintf) will use the
new attributes or colors.
If you use symbolic color constants, the following limitations apply to the background colors you
select:
You can only select one of the first eight colors (0--7).
With textattr, you must shift the selected background color left by
4 bits to move it into the correct "bbb" bit positions.
NOTE: If you use the symbolic color constants, you must include conio.h.
newattr:
7 6 5 4 3 2 1 0
B b b b f f f f
Blinking characters:
If the blink-enable bit is on, the character blinks. To turn the bit on in a
call to textattr, you add the constant BLINK to the attribute.
To make the characters blink in a call to textcolor, you add 128 to the
foreground color. The predefined constant BLINK exists for this purpose; for
example,
textcolor(CYAN + BLINK);
clrscr();
for (i=0; i<9; i++)
{
cprintf("C.W.I.T.");
cprintf("\r\n");
textcolor(i+1);
textbackground(i);
}
for (i=0; i<9; i++)
{
cprintf("C.W.I.T.");
cprintf("\r\n");
textcolor(i+1+BLINK);
textbackground(i);
}
/* textattr example */
/* PROGRAM TO CHANGE TEXT ATTRIBUTE */
#include <conio.h>
void main(void)
{
int i;
// background color = CYAN = 3 = 011
// foreground color = RED = 4 = 0100
// blink true
// control word = 1(blink) 011 (background color) 0100 (foreground color)
// control word = 10110100 = 180 decimal
i=180;
clrscr();
textattr(i);
cprintf("This is a test\r\n");
}
text_modes <conio.h>
cprintf function
Declaration:
int cprintf (const char *format [, argument, ...]);
cputs function
Remarks:
cputs writes the null-terminated string str to the current text window. It
does not append a newline character.