/*
@Author:Mr.Suppakit Thongdee
@Website: www.sourcecode.in.th
*/
#include <stdio.h>
#include <conio.h>
void display_menu(int selected){
clrscr();
char menu[4] = " ";
menu[selected] = '>';
printf("\t Main Menu [ENTER to select, ESC to exit]\n");
printf("\t ----------------------------------------\n");
printf("\t %cFirst menu \n",menu[0]);
printf("\t %cSecond menu\n",menu[1]);
printf("\t %cThird menu \n",menu[2]);
printf("\t %cForth menu \n",menu[3]);
printf("\t ----------------------------------------\n");
}
void menu1(){
clrscr();
printf("This is First program \n\t press any key to exit");
getch();
}
void menu2(){
clrscr();
printf("This is Second program \n\t press any key to exit");
getch();
}
void menu3(){
clrscr();
printf("This is Third program \n\t press any key to exit");
getch();
}
void menu4(){
clrscr();
printf("This is Forth program \n\t press any key to exit");
getch();
}
void main(){
int ch;
int selected = 0; //0-3 for 4 menu
clrscr();
//ESC=27, Spacebar=32, Enter=13
//arrow key UP=0,72
//arrow key Down=0,80
do{
//display menu
display_menu(selected);
//get keypress
ch = getch();
if(ch==0){ //check function key or not
ch = getch();
if(ch==72){ //check arrow key UP
selected--;
}else if(ch==80){ //check arrow key DOWN
selected++;
}
//update select menu value 0 to 3
if(selected<0){
selected = 3;
}else if(selected>3){
selected = 0;
}
display_menu(selected);
}else if(ch==13){ //ENTER
//Call select program
switch(selected){
case 0: menu1(); break;
case 1: menu2(); break;
case 2: menu3(); break;
case 3: menu4(); break;
}
}
}while(ch!=27); //exit when press ESC on keyboard
}