Let the CC ++ graphics run independently

xiaoxiao2021-03-06  40

The C / C language provides a very rich graphics function, the graphics function file is graphics.h, and must first set the screen to graphics mode before using the graphic function, and the C / C language provides the following functions:

Void Far Initgraph (int Far * GD, INT FAR * GM, CHAR * P);

Where, GD and GM represent graphics drivers and graphics modes, and P refers to the directory path where the graphics driver is located.

The graphics driver is provided by Borland (for Turbo C and Borland C ), and the C / C language also provides functions with the exit graphic state closegraph (), format:

Void Far Closegraph (Void);

You often write some graphics programs in the C / C language, but you can always run out of the C / C language environment. How do we solve it? Below is the specific steps of implementing the graphics independent run:

1. Convert the driver egavga.bgi into target files egavgga.obj:

C: / TC> BGIOBJ Egavga

Convert font file * .chr to target files * .Obj: according to the same approach

C: / TC> BGIOBJ Trip

C: / tc> bgiobj Litt

C: / TC> BGIOBJ SANS

C: / TC> BGIOBJ GOTH

2. Add the above OBJ file 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, the PRJ program instead of TLINK.

3. Before calling the initgraph () function in the program, add the following statement:

RegisterBgidriver (Egavga-Driver);

It notifies the connection program to load the EGAVGA driver into the user's executable, and then add the following statement before loading the font file:

Registerbgifont; font file name);

4. After the above processing, the execution program after compiling the connection can be run in any directory. At this time, the function of initializing the screen into graphics mode can be rewritten as:

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 the steps to implement the independent operation of the graphics program

转载请注明原文地址:https://www.9cbs.com/read-53318.html

New Post(0)