setgraphmode
Sets the system to graphics mode and clears the screen.
Defined in header <graphics.h>
Syntax
#include <graphics.h>
void far setgraphmode(int mode);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ |
Remarks
setgraphmode selects a graphics mode different than the default one set by initgraph. mode must be a valid mode for the current device driver. setgraphmode clears the screen and resets all graphics settings to their defaults (current position, palette, color, viewport, and so on).
You can use setgraphmode in conjunction with restorecrtmode to switch back and forth between text and graphics modes.
Return value
If you give setgraphmode an invalid mode for the current device driver, graphresult returns a value of-10 (grlnvalidMode).
See also
Example
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main (void)
{
/* request autodetection */
int gdriver = DETECT, . gmode, errorcode;
int X, y;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
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 */
}
X = getmaxx () / 2;
y = getmaxyO / 2;
/* output a message */
settextjustify (CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, "Press any key to exit graphics:");
getchO ;
/* restore system to text mode */
restorecrtmode ();
printf ("We're now in text mode.\n");
printf ("Press any key to return to graphics mode:");
getchO;
/* return to graphics mode */
setgraphmode (getgraphmode());
/* output a message */
settextjustify (CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, "We're back in graphics mode.");
outtextxy(x, y+textheight ("W"), "Press any key to halt;
/* clean up */
getchO ;
closegraphO ;
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/setgraphmode/
· short form /3.1/setgraphmode/