How do I make some part of my code a function so i will just have to call it whenever i need it.

[code=c++]

include <graphics.h>

include <stdio.h>

include <math.h>

include <conio.h>

include <dos.h>

include <stdlib.h>

void main()

{
int i, grd, grm;
int x, y, w;
int left,top,right,bottom;
int margin, width, height;
int gresult;
int cx, cy;
char msg[512];
char buffer[] = "Bataan Peninsula State University";
detectgraph(&grd,&grm);
initgraph(&grd, &grm, "C:\TURBOC3\BGI");

   gresult = graphresult();

   if(gresult != grOk)

   {

      printf(grapherrormsg(gresult));

      getch();

      return;

   }

   setbkcolor(RED);

   setcolor(WHITE);

   rectangle(0,0,getmaxx(),getmaxy());

   width = textwidth(buffer);

   height = textheight(buffer);

   margin = 100; // 100 pixel margin

   left = margin;

   top = margin;

   bottom = getmaxy() - margin;

   right = getmaxx() - margin;

   setfillstyle(SOLID_FILL, BLUE);

   bar(left, top, right, bottom);

   rectangle(left, top, right, bottom);

   setcolor(YELLOW);

   cx = (right + left - width) / 2;

   cy = (bottom + top - height) / 2;

   settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);

   outtextxy(cx,cy,buffer);

   setcolor(WHITE);

   sprintf(msg, "College of Engineering and Architecture", getbkcolor(), getcolor(), getmaxcolor());

   width = textwidth(msg);

   cx = (right + left - width) / 2;

   cy += textheight(msg) + 10;;

   moveto(cx, cy);

   outtext(msg);

   char wew[100]="Press any key to continue...";
   moveto(cx, cy+110);
   outtext(wew);

   getch();

   clrscr();
   getch();

   closegraph();

}
[/code]

Comments

  • I need to make a function for the border like graphics that i need to use after every clrscr() so that i can put new text inside the box how do i make the graphic part of this a function so it will be easier?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion