0

Hi, I have some rectangles in the result of a program And i want to make a function called menu (called pressing F1)
that takes me to another screen and gives me some options,

but when i press F1 the screen is all gray!!!
and the rectangles are not there any more

#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "graphics.h"
#include "dos.h"

void iniciar_grafica()
{
   int gdriver = DETECT, gmode, errorcode;
   initgraph(&gdriver, &gmode, "C:\\TC\\BGI");
   errorcode = graphresult();
   if (errorcode != grOk)
   {
   printf("Error de grafica: %s\n", grapherrormsg(errorcode));
   printf("presione una tecla para terminar:");
   getch();
   exit(1);
   }
}

void graficar_datos()
{
   //Dibuja la  estructura basica
   rectangle(20,80,250,450);
   rectangle(420,100,300,450);  
   rectangle(440,100,550,450);
   outtextxy(10,20,"SIMULACION DE UN PROCESADOR");
   outtextxy(290,80,"Procesos Activos");
   outtextxy(440,80,"Procesos Inactivos");
   printf("\n\n\n Menu <<F1>>");                  [U]////this one///[/U]

}


int main(void)
{
   clrscr();
   iniciar_grafica();
   graficar_datos();
   getch();
closegraph();
return 0;
}

this code is only the one that draws the rectangles
the following idea is to make the menu:

I PRESS F1 AND THIS TAKE ME TO ANOTHER MENU
1 opcion
2 opcion
AND thats it

int menu()
{
 char opc;
 clrscr();
 printf("<<F1>> MENU\n");///////WHEN I PRESS F1//
 opc=getch();
 if ( (int) opc==0 )
       opc=getch();
 return((int)opc);
}


void main()
{ int accion=0;
  while(accion!=ESC)
  {
   accion=menu();
   clrscr();
   switch(accion)
    {
       case F1: MENU();
        getch();
        break;

       default:
        printf("  !!!!!! ERROR?????????\n\n");
        printf("Presione cualquier tecla para continuar...");
        getch();
    }
    getch();
  }
}

int MENU()
{
 int accion=0;

   while(accion!=ESC)
      {
       accion=submenu();
       clrscr();
       switch(accion)
    {
      case F1: printf("1 opcion");
           getch();
           break;
      case F2: printf("2 opcion");
           getch();
           break;
      case ESC: printf("\n\n Usted va a salir");
           getch();
           break;

      default: printf("  !!!!!!ERROR?????\n\n");
           printf("Presione cualquier tecla para continuar...");
           getch();
    }
       getch();
      }
}

int submenu()
{
 char opc;
 clrscr();
 printf("\n\n MENU:\n\n");
 printf("<<F1>> 1 opcion  \n");
 printf("<<F2>> 2 opcion     \n");
 printf("<<ESC>> SALIR    \n");

 opc=getch();
 if ( (int) opc==0 )
       opc=getch();
 return((int)opc);
}

How can i do it? i have spent some hours trying to mix this up but i can't
Please help

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by WaltP
0

You have to know what F1 actually is when you press it, and code for that. As it is, I don't see anywhere you actually defined the value you expect for the key.

And since getch() returns an int, and in the function you cast everything to ints anyway, why not just define opc as an int?

And never give two different functions the same name -- even if one is menu and the other MENU .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.