This blog is under construction

Sunday, 15 September 2013

restorecrtmode example in c

Header file:
    graphics.h

Synopsis:
      void restorecrtmode();
     
Description:
     restorecrtmode() restores screen mode to text mode.


restorecrtmode function in c graphics



  #include <graphics.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <conio.h>

  int main(void) {
        /* request auto detection */
        int gd = DETECT, gmode, err;
        int midx, midy;

        /* initialize graphics and local variables */
        initgraph(&gd, &gmode, "C:/TURBOC3/BGI");

        /* read result of initialization */
        err = graphresult();

        if (err != grOk) {
                /* an error occurred */
                printf("Graphics error: %s\n", grapherrormsg(err));
                getch();
                return 0;
        }

        /* mid position in x and y-axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

        /* output a message */
        settextjustify(CENTER_TEXT, CENTER_TEXT);
        outtextxy(midx, midy - 100, "GRAPHICS MODE");

        /* draw a rectange at the given position */
        rectangle(midx - 50, midy - 50, midx + 50, midy + 50);
        getch();

        /* restore system to text mode */
        restorecrtmode();
        printf("Restored system to text mode");
        getch();

        /* return to graphics mode */
        setgraphmode(getgraphmode());

        /* output a message */
        settextjustify(CENTER_TEXT, CENTER_TEXT);
        outtextxy(midx, midy - 100, "BACK TO GRAPHIC MODE!!");

        /* draws a rectangle at the given postion */
        rectangle(midx - 50, midy - 50, midx + 50, midy + 50);

        /* clean up */
        getch();
        closegraph();
        return 0;
  }





Output: (restorecrtmode built-in function in c graphics.h)


No comments:

Post a Comment