1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
// Menu example for tjnapster
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <cstdlib>
using namespace std;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // used for goto
COORD CursorPosition; // used for goto
void gotoXY(int,int); // function defined below if this is new to you.
int main()
{
int menu_item=0, run, x=7;
bool running = true;
gotoXY(18,5); cout << "Main Menu";
gotoXY(18,7); cout << "->";
while(running)
{
gotoXY(20,7); cout << "1) Input";
gotoXY(20,8); cout << "2) Output";
gotoXY(20,9); cout << "3) ...";
gotoXY(20,10); cout << "4) ...";
gotoXY(20,11); cout << "Quit Program";
system("pause>nul"); // the >nul bit causes it the print no message
if(GetAsyncKeyState(VK_DOWN) && x != 11) //down button pressed
{
gotoXY(18,x); cout << " ";
x++;
gotoXY(18,x); cout << "->";
menu_item++;
continue;
}
if(GetAsyncKeyState(VK_UP) && x != 7) //up button pressed
{
gotoXY(18,x); cout << " ";
x--;
gotoXY(18,x); cout << "->";
menu_item--;
continue;
}
if(GetAsyncKeyState(VK_RETURN)){ // Enter key pressed
switch(menu_item){
case 0: {
gotoXY(20,16);
cout << "You chose Input... ";
break;
}
case 1: {
gotoXY(20,16);
cout << "You chose Output... ";
break;
}
case 2: {
gotoXY(20,16);
cout << "You chose Option 3... ";
break;
}
case 3: {
gotoXY(20,16);
cout << "You chose Option 4... ";
break;
}
case 4: {
gotoXY(20,16);
cout << "The program has now terminated!!";
running = false;
}
}
}
}
gotoXY(20,21);
return 0;
}
void gotoXY(int x, int y)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
}
|