The C/C ++ language provides a wealth of graphic functions. The graphic function file is graphics. h. Before using graphical functions, you must set the screen to the graphical mode. The C/C ++ language provides the following functions:
Void far initgraph (INT far * GD, int far * GM, char * P );
GD and GM represent the graphic drivers respectively.ProgramAnd graphical mode. P indicates the directory path where the graphic driver is located.
The graphic driver is provided by Borland Corporation (for Turbo C and Borland C ++), and the C/C ++ language also provides the function closegraph () for exiting the graph state. The format is:
Void far closegraph (void );
Maybe you often write some graphics programs in C/C ++ language, but you cannot run them independently from the C/C ++ language environment. How can we solve this problem? The following describes how to run a graphical program independently:
1. Convert the driver egavga. BGI to the target file egavga. OBJ:
C:/TC> bgiobj egavga
In the same way, convert the font file *. CHR to the target file *. OBJ:
C:/TC> bgiobj trip
C:/TC> bgiobj Litt
C:/TC> bgiobj sans
C:/TC> bgiobj goth
2. Add the OBJ file created above to the graphics. Lib library file. The specific method is as follows:
C:/TC> tlink C:/TC/lib/graphics. Lib + egavga
C:/TC> tlink C:/TC/lib/graphics. Lib + trip
C:/TC> tlink C:/TC/lib/graphics. Lib + Litt
C:/TC> tlink C:/TC/lib/graphics. Lib + sans
C:/TC> tlink C:/TC/lib/graphics. Lib + goth
You can also use tlib and prj programs to replace tlink.
3. before calling the initgraph () function in a program, add the following statement:
Registerbgidriver (egavga-driver );
It notifies the Connection Program to load the egavga driver into the user's execution program, and also adds the following statement before loading the font file:
Registerbgifont (font file name );
4. After the above processing, the compiled connected execution program can run in any directory. In this case, the function that initializes the screen to the graphic mode can be rewritten:
Void initgra (void)
{Int GD = detect, GM;
Registerbgidriver (egavga_driver );
Registerbgifont (triplex_font );
Registerbgifont (small_font );
Registerbgifont (sansserif_font );
Registerbgifont (gothic_font );
Initgraph (& GD, & GM ,"");
}
Follow these steps to run the graphics program independently.