/
consolemenu.cpp
executable file
·201 lines (144 loc) · 5.34 KB
/
consolemenu.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
Copyright 2008 David House
This file is part of Microsight.
Microsight is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Microsight is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Microsight. If not, see <http://www.gnu.org/licenses/>.
*/
#include <conio.h>
#include <windows.h>
#include <iostream>
void drawMainMenu(int pos);
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void main()
{
system("cls");
int keyboard_read=0; // integer to store input from the keyboard
int PASS=1; // integer used to signal the application to close
int currpos=1; // integer to store the selection from the menu
drawMainMenu(1); // draw the main menu with selection at option 1
while (PASS)
{
keyboard_read=getch(); // get input from keyboard
if (keyboard_read == 0) // wait for the input to be given
{
keyboard_read = getch();
}
switch(keyboard_read) // check the input against these values
{
case 72: // if the Up cursor key is pressed
if(currpos > 1)
{
currpos=currpos-1; // move the selection 1 step up
}
drawMainMenu(currpos); // draw menu with the new selection value
break;
case 80: // if the Down cursor key is pressed
if(currpos >= 1 && currpos < 5)
{
currpos=currpos+1; // move the selection one step down
}
drawMainMenu(currpos); // draw menu with new selection value
break;
case 13: // if the Return(Enter) key is pressed
if(currpos==5) // is the exit command highlighted?
{
PASS=0; // end the input sequence if yes
}
break;
}
}
}
void drawMainMenu(int pos)
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = false;
cursor.dwSize = 1;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor);
int current=pos; // store the value of the currently highlighted selection
gotoxy(25,4); // position on screen
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
cprintf(" BU MicroSight "); // name of menu item
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
if (current == 1)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
// turn text color to black
// turn the text background color grey
gotoxy(25,7); // position on screen
cprintf("-> Alter System Variables "); // name of menu item
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
// textcolor(7); // turn the text colour back to normal
// textbackground(0); // turn the text BG to black
}
else
{
gotoxy(25, 7);
cprintf(" Alter System Variables ");
}
if(current == 2)
{
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
// textbackground(7);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
gotoxy(25, 9);
cprintf("-> Edit Trial Details ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
//textcolor(7);
//textbackground(0);
}
else
{
gotoxy(25, 9);
cprintf(" Edit Trial Details ");
}
if(current == 3)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
gotoxy(25, 11);
cprintf(" Set Segmentation Method ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
else
{
gotoxy(25, 11);
cprintf(" Set Segmentation Method ");
}
if (current == 4)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
gotoxy(25, 13);
cprintf(" Begin Trial Now ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
else
{
gotoxy(25, 13);
cprintf(" Begin Trial Now ");
}
if(current == 5)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
gotoxy(25, 19);
cprintf(" Exit ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
else
{
gotoxy(25, 19);
cprintf(" Exit ");
}
}