detectgraph
Determines graphics driver and graphics mode to use by checking the hardware.
Defined in header <graphics.h>
Syntax
#include <graphics.h>
void far detectgraph(int far *graphdriver, intfar *graphmode);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ |
Remarks
detectgraph detects your system's graphics adapter and chooses the mode that provides the highest resolution for that adapter. If no graphics hard-ware 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 in the following table.
Table 2.1 detectgraph
graph ics_ drivers
constants
| constant | Numeric value |
| DETECT | 0 (requests autodetection) |
| 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 jnodes enumeration type, defined in graphics.h and listed in the following table.
Table 2.2 Graphics drivers
| Graphics | Column |
information
| driver | graphics_modesValue | X row | Palette | Pages | |
| CGA | CGACO | 0 | 320 X 200 | CO | |
| CGACl | 1 | 320 X 200 | CI | ||
| CGAC2 | 2 | 320 X 200 | C2 | ||
| CGAC3 | 3 | 320x200 | C3 | ||
| CGAHI | 4 | 640 X 200 | 2 color | ||
| MCGA | MCGACO | 0 | 320 X 200 | CO | |
| MCGACl | 1 | 320 X 200 | CI | ||
| MCGAC2 | 2 | 320x200 | C2 | ||
| MCGAC3 | 3 | 320 X 200 | C3 | ||
| MCGAMED | 4 | 640 X 200 | 2 color | ||
| MCGAHI | 5 | 640 X 480 | 2 color | ||
| 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 | |
| EGAMONOHI | 3 | 640 X 350 | 2 color | 2** | |
| HERC | HERCMONOHI | 0 | 720 X 348 | 2 color | 2 |
| ATT400 | ATT400C0 | 0 | 320 X 200 | CO | 1 |
| ATT400C1 | 1 | 320 X 200 | CI | 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 |
* 64K on EGAMONO card ** 256K on EGAMONO card Note: The main reason to call detectgraph directly is to override the
| graphics mode that detectgraph recommends | to initgraph. |
Return value
None.
See also
Example
#include <graphics.h>
#include <stdlib.h>
itinclude <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:");
getchO ;
exit(l); /* terminate with an error code */
/* display the information detected */
clrscr 0;
printf("You have %s video display card.\n", dname[gdriver]);
printf("Press any key to halt:");
getchO ;
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/graphics.h/detectgraph/
· short form /3.1/detectgraph/