#include <graphics.h> void detectgraph(int *graphdriver, int *graphmode); Descriptiondetectgraph detects your system's graphics adapter and chooses the mode that provides the highest resolution for that adapter. If no graphics hardware is detected, *graphdriver is set to grNotDetected (-2), and graphresult returns grNotDetected (-2).
*graphdriver is an integer that specifies the graphics driver to be used. You can give it a value using a constant of the graphics_drivers enumeration type defined in graphics.h and listed as follows:
| graphics_drivers constant | Numeric value | 
| DETECT | 0 (requests autodetect) | 
| CGA | 1 | 
| MCGA | 2 | 
| EGA | 3 | 
| EGA64 | 4 | 
| EGAMONO | 5 | 
| IBM8514 | 6 | 
| HERCMONO | 7 | 
| ATT400 | 8 | 
| VGA | 9 | 
| PC3270 | 10 | 
*graphmode is an integer that specifies the initial graphics mode (unless *graphdriver equals DETECT; in which case, *graphmode is set to the highest resolution available for the detected driver). You can give *graphmode a value using a constant of the graphics_modes enumeration type defined in graphics.h and listed as follows.
| Graphics | Columns | ||||
| Driver | graphics_mode | Value | x Rows | Palette | Pages | 
| CGA | CGAC0 | 0 | 320 x 200 | C0 | 1 | 
| CGAC1 | 1 | 320 x 200 | C1 | 1 | |
| CGAC2 | 2 | 320 x 200 | C2 | 1 | |
| CGAC3 | 3 | 320 x 200 | C3 | 1 | |
| CGAHI | 4 | 640 x 200 | 2 color | 1 | |
| MCGA | MCGAC0 | 0 | 320 x 200 | C0 | 1 | 
| MCGAC1 | 1 | 320 x 200 | C1 | 1 | |
| MCGAC2 | 2 | 320 x 200 | C2 | 1 | |
| MCGAC3 | 3 | 320 x 200 | C3 | 1 | |
| MCGAMED | 4 | 640 x 200 | 2 color | 1 | |
| MCGAHI | 5 | 640 x 480 | 2 color | 1 | |
| EGA | EGALO | 0 | 640 x 200 | 16 color | 4 | 
| EGAHI | 1 | 640 x 350 | 16 color | 2 | |
| EGA64 | EGA64LO | 0 | 640 x 200 | 16 color | 1 | 
| EGA64HI | 1 | 640 x 350 | 4 color | 1 | |
| EGA-MONO | EGAMONOHI | 3 | 640 x 350 | 2 color | 1 w/64K | 
| EGAMONOHI | 3 | 640 x 350 | 2 color | 2 w/256K | |
| HERC | HERCMONOHI | 0 | 720 x 348 | 2 color | 2 | 
| ATT400 | ATT400C0 | 0 | 320 x 200 | C0 | 1 | 
| ATT400C1 | 1 | 320 x 200 | C1 | 1 | |
| ATT400C2 | 2 | 320 x 200 | C2 | 1 | |
| ATT400C3 | 3 | 320 x 200 | C3 | 1 | |
| ATT400MED | 4 | 640 x 200 | 2 color | 1 | |
| ATT400HI | 5 | 640 x 400 | 2 color | 1 | |
| VGA | VGALO | 0 | 640 x 200 | 16 color | 2 | 
| VGAMED | 1 | 640 x 350 | 16 color | 2 | |
| VGAHI | 2 | 640 x 480 | 16 color | 1 | |
| PC3270 | PC3270HI | 0 | 720 x 350 | 2 color | 1 | 
| IBM8514 | IBM8514HI | 0 | 640 x 480 | 256 color | ? | 
| IBM8514LO | 0 | 1024 x 768 | 256 color | ? | 
![[WIN]](win.gif)
/* detectgraph example */ 
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
/* the names of the various cards supported */
char *dname[] = { "requests detection",
                  "a CGA",
                  "an MCGA",
                  "an EGA",
                  "a 64K EGA",
                  "a monochrome EGA",
                  "an IBM 8514",
                  "a Hercules monochrome",
                  "an AT&T 6300 PC",
                  "a VGA",
                  "an IBM 3270 PC"
                };
int main(void)
{
   /* used to return detected hardware info. */
   int gdriver, gmode, errorcode;
   /* detect the graphics hardware available */
   detectgraph(&gdriver, &gmode);
   /* read result of detectgraph call */
   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 */
   }
   /* display the information detected */
   clrscr();
   printf("You have %s video display card.\n", dname[gdriver]);
   printf("Press any key to halt:");
   getch();
   return 0;
}