This shows you the differences between two versions of the page.
c:graphics.h:setgraphmode [2015/05/06 23:06] |
c:graphics.h:setgraphmode [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== setgraphmode ===== | ||
+ | |||
+ | |||
+ | ====Syntax of setgraphmode ==== | ||
+ | <code c> | ||
+ | #include <graphics.h> | ||
+ | void setgraphmode(int mode); | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== Description of setgraphmode ==== | ||
+ | <code c> | ||
+ | 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. | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== Example of setgraphmode ==== | ||
+ | <code c> | ||
+ | /* setgraphmode 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:"); | ||
+ | |||
+ | getch(); | ||
+ | exit(1); /* terminate with an error code */ | ||
+ | } | ||
+ | |||
+ | x = getmaxx() / 2; | ||
+ | y = getmaxy() / 2; | ||
+ | |||
+ | /* output a message */ | ||
+ | settextjustify(CENTER_TEXT, CENTER_TEXT); | ||
+ | outtextxy(x, y, "Press any key to exit graphics:"); | ||
+ | getch(); | ||
+ | |||
+ | /* restore system to text mode */ | ||
+ | restorecrtmode(); | ||
+ | printf("We're now in text mode.\n"); | ||
+ | printf("Press any key to return to graphics mode:"); | ||
+ | getch(); | ||
+ | |||
+ | /* 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 */ | ||
+ | getch(); | ||
+ | closegraph(); | ||
+ | return 0; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== See also ==== | ||
+ | [[getgraphmode]] | ||
+ | [[getmoderange]] | ||
+ | [[graphresult]] | ||
+ | [[initgraph]] | ||
+ | [[restorecrtmode]] | ||
+ | |||
+ | |||
+ | ===== output of setgraphmode example ===== | ||
+ | |||
+ | no output of example at the moment | ||
+ | do not hesitate and add it... | ||
+ | |||
+ | |||