This blog is under construction

Saturday 14 September 2013

setgraphmode example in c

Header file:
    graphics.h

Synopsis:
      void setgraphmode(int mode);
     
Description:
     setgraphmode() sets the system to graphic mode.


setgraphmode 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, "In graphics mode!! press any key to exit");
        getch();

        /* restore system to text mode */
        restorecrtmode();
        printf("Inside text mode!! press any key to exit");
        getch();

        /* setting graphic mode */
        setgraphmode(getgraphmode());

        /* output a message */
        settextjustify(CENTER_TEXT, CENTER_TEXT);
        outtextxy(midx, midy, "Back to graphic mode!!");

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





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


No comments:

Post a Comment