Software & Finance





Turbo C Graphics - closegraph function





closegraph function is used to reset back to text mode screen or in other words it used to exit from the graphics screen. In case your program your requires both graphics and text mode, you can use initgraph and closegraph function to achieve this.

 

detectgraph is used to find out the current graphics driver and mode. The outcome of this function is used in initgraph function as input arguments. initgraph function is used to initialize with the graphics library and changes to the graphics screen for drawing. It is the first step you need to do during graphics programming. The sample code is given below on this page.

 

You need to pass the graphics driver and graphics mode to this function. Usually we will use VGA and VGAHI for graphics driver and mode (640 x 480 pixels) respectively. detectgraph function is used to detect your graphics driver and mode.

 

Back to Turbo C Graphics Index



Source Code


#include <graphics.h>

#include <stdio.h>

#include <math.h>

#include <conio.h>

#include <dos.h>

#include <stdlib.h>

 

void main()

{

      int i, grd, grm;

      int x, y, w, gresult;

      detectgraph(&grd,&grm);

      initgraph(&grd, &grm, "");

 

      gresult = graphresult();

      if(gresult != grOk)

      {

              printf(grapherrormsg(gresult));

              getch();

              return 0;

      }

       outtextxy(100,100,"softwareandfinance.com");

    

      getch();

      closegraph();

}

Output


 

softwareandfinance.com [in graphics screen]

 

after pressing a key, it will come out of graphics screen