hello ppl

since i am new to the group, il first introduce myself

my name is Aziz Mansur. im a grade 12 student (CBSE in indian curriculum) studyin in Dubai, UAE.

neways for my final exam i have to submit a project and mine is making a student database management software.

i started wit the displays first as the coding for the actual working of the software is pretty simple and also because i know nothing bout graphics in c++ (as it is not part of our portion but v do have to use basic graphics for the prroj) whatever graphics i have used, i have learnt from the compiler help files

now to the prob
(you will nderstand it better if you run the program once)
1) the main problem is that after the toggle there is still some bits of colour in the prev selection i tried the functions setviewport and clearviewport but either i didnt understand how to use them properly or they are not ment for the purpose i dont know cause they didnt work

2) toggling with numbers works only when number keys are pressed twice

3) also could someone tell me how to implement the ascii value for F1 as i want to use it to invoke the help function of the program

thanx in advance

/* THE FOLLOWING ARE JUST SNIPPITS OF THE WHOLE PROGRAM WHICH I HAVE
EDITTED IN ORDER TO MAKE EXECUTABLE FOR TESTING

ALSO CODEING AND FORMATTING IS YET NOT COMPLETING*/


#include <iostream.h>
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <graphics.h>
#include <process.h>



/* This function makes the page border*/

void border ()
{
setbkcolor (1);
setcolor (15);
rectangle (0, 0, 639, 479);
rectangle (5, 5, 634, 474);

struct time t; struct date d;
rectangle (535, 5, 634, 55);
rectangle (530, 5, 634, 60);
gotoxy (72, 2);
gettime (&t);
printf("%2d:%02d\n",t.ti_hour, t.ti_min);
gotoxy (70, 3);
getdate(&d);
printf("%d/%d/%d", d.da_day, d.da_mon, d.da_year);



//  x1 y1 x2 y2
line ( 5, 396, 634, 396);
line ( 5, 391, 634, 391);
}




/*This function makes the selection box*/

void box (int n, int sel)
{
 int top = ( (140 + ( (--n)*30) ) ), bot = ( (160 + ( (n)*30) ) );
// the values for top and bottom are got from the formula of an arithmetic series
 int color_line, color_fill;

 if (sel)	color_line = 15, color_fill = 3;
//to select a particular option, sel will be passed as 1
 else if (!sel) color_line = 15, color_fill = 7;
//to unselect an option, sel will be passed as 0

 setcolor (color_line);
 rectangle (200, top, 450, bot);
 setfillstyle (1, color_fill)  ;
 floodfill (201, (bot-1), color_line);
}


/*this function performs a toggle between the current and prev selections*/
void toggle (int current, int prev)
{
 // current = current selection and prev = previous selection
 char m1[] = "1:  See Student Details",
      m2[] = "2:  List of Students",
      m3[] = "3:  Add New Student",
      m4[] = "4:  Edit Student Details",
      m5[] = "5:  Delete Student Details",
      m6[] = "6:  LOGOUT",
      m7[] = "7:  QUIT";

 if (current == 0)
	current = 7;
 if (prev == 0)
	prev = 7;

 setusercharsize (1,2,1,2);
 switch (prev)
	{
	 case 1:
	 box(1,0);
	 outtextxy (210, 140, m1);
	 break;				//This part of the function
					//unselects the previous selection
	 case 2:			//by printing a new box and text
	 box(2,0);			//over the old 1
	 outtextxy (210, 170, m2);
	 break;

	 case 3:
	 box(3,0);
	 outtextxy (210, 200, m3);
	 break;

	 case 4:
	 box(4,0);
	 outtextxy (210, 230, m4);
	 break;

	 case 5:
	 box(5,0);
	 outtextxy (210, 260, m5);
	 break;

	 case 6:
	 box(6,0);
	 outtextxy (210, 290, m6);
	 break;

	 case 7:
	 box(7,0);
	 outtextxy (210, 320, m7);
	 break;
	}

 switch (current)
	{
	 case 1:
	 box(1,1);
	 outtextxy (210, 140, m1);
	 break;				//This part of the function
					//selects the new selection
	 case 2:			//by printing a new box and text
	 box(2,1);			//over the old 1
	 outtextxy (210, 170, m2);
	 break;

	 case 3:
	 box(3,1);
	 outtextxy (210, 200, m3);
	 break;

	 case 4:
	 box(4,1);
	 outtextxy (210, 230, m4);
	 break;

	 case 5:
	 box(5,5);
	 outtextxy (210, 260, m5);
	 break;

	 case 6:
	 box(6,6);
	 outtextxy (210, 290, m6);
	 break;

	 case 7:
	 box(7,7);
	 outtextxy (210, 320, m7);
	 break;
	}
}



void main()
{

 int gdriver = DETECT, gmode, errorcode;
 initgraph(&gdriver, &gmode, "");

 clrscr();
 cleardevice ();

 border ();

 settextstyle (1,0,3);			//just some of the page background
 outtextxy (240, 20, "WELCOME");
 gotoxy (45,3) ; cout << "Aziz";	// this is just a temp name in the actual prog, the name will come from the class
 setusercharsize (1, 2, 1, 2)  ;
 outtextxy (180, 50, "You are logged in as REGISTRAR");
 settextstyle (1, 0, 3);
 outtextxy (270, 90, "Options");
 settextstyle (1, 0, 0);
 setusercharsize (1, 2, 2, 5);
 outtextxy (50, 405, "IN THE ACTUAL PROGRAM THIS BOX IS FOR POSTING COMMENTS FOR EG:");
 outtextxy (100, 440, "Press F1 For Help");
 outtextxy (350, 440, "Press ESC To Quit");


 char m1[] = "1:  See Student Details",
      m2[] = "2:  List of Students",
      m3[] = "3:  Add New Student",
      m4[] = "4:  Edit Student Details",
      m5[] = "5:  Delete Student Details",
      m6[] = "6:  LOGOUT",
      m7[] = "7:  QUIT";

 box(1,1);
 box(2,0);			// makes the boxes for all the
 box(3,0);			//options (the 1st one selected by default)
 box(4,0);
 box(5,0);
 box(6,0);
 box(7,0);
 setusercharsize (1,2,1,2);
 outtextxy (210, 140, m1 );
 outtextxy (210, 170, m2 );	// displays the options
 outtextxy (210, 200, m3 );
 outtextxy (210, 230, m4 );
 outtextxy (210, 260, m5 );
 outtextxy (210, 290, m6 );
 outtextxy (210, 320, m7 );

 int choice = 1, temp	;	// temp keeps track of the prev selection
 char ch;

 do
	{
	 ch = getch ();		// gets input from user and
	 temp=choice;		// and acts on it using ascii values
	 ch=getch();
	 switch (ch)
		{
		 case 72:
		 case 75: choice=((--choice+7)%7);
			 toggle(choice,temp);
			 break;
		 case 77:
		 case 80: choice=(++choice%7);
			 toggle(choice,temp);
			 break;
		 case 73: choice=(choice+12)%7;
			 toggle(choice,temp);
			 break;
		 case 81: choice=(choice+2)%7;
			 toggle(choice,temp);
			 break;
		 case 71:
		 case 49: choice=1;
			 toggle(choice,temp);
			 break;
		 case 50: choice=2;
			 toggle(choice,temp);
			 break;
		 case 51: choice=3;
			 toggle(choice,temp);
			 break;
		 case 52: choice=4;
			 toggle(choice,temp);
			 break;
		 case 53: choice=5;
			 toggle(choice,temp);
			 break;
		 case 54: choice=6;
			 toggle(choice,temp);
			 break;
		 case 79:
		 case 55: choice=0;
			 toggle(choice,temp);
			 break;
		 case 27: choice=0;
			 toggle(choice,temp);
		 case 13:
			exit (0);
		}
	} while (ch != 13);

closegraph ();
}

What you're writing looks a bit more like pure C then C++. You're obviously using headers imported from Pascal to C and C++ respectively (the names of the functions you're using are calling some memories :-) ). Anyway since you're using a low-level language for something, that it's not meant to be an important aspect of it, namely graphics, you have some options left like:

1. Open your header file and look through the functions you got there. You don't need to understand them, the names will be in the most cases enough as a tip. You can google everything that looks fitting to your case.
2. You have also the option to redraw the screen. Make a function that draws exactly the same window over the already drawn one and make the screen update through it, i.e. add the new stuff after the user has selected an option(for example). This is more or less quite a hard way to get what you want, but it's still an option ..
3. Get into C++ and use the huge range of graphics related libraries. This will be quite time consuming, especially if you're new to this. In the end your program will look exactly as you want it to look, though.. ;)

// ...
do
{
ch = getch (); // gets input from user and
temp=choice; // and acts on it using ascii values
ch=getch();
// ...

You call getch() 2 times, maybe this could be the reason for you to press a key 2 times until it's recognized .. ? ;)

For the F1 key you have 2 options. Since the ASCII table should be quite similar but not necesserily 100% identical on different systems you can either use something like this: http://www.bbsinc.com/iso8859.html or simply write a simple program that gets a char and outputs it's int value. You know how to use getch(), so this will help you in the latter case.

i did write a program to typecast but it didnt work for F1

and also 1 tht bout the second option but it would make the code horribly longer

as for the double getch, sheesh :o

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.