My menu function looks like this and it works great:
int menu(string * teksty, int ile)
{
static HANDLE h_we = GetStdHandle(STD_INPUT_HANDLE),
h_wy = GetStdHandle(STD_OUTPUT_HANDLE);
int wybor = 1;
CONSOLE_CURSOR_INFO cci = {0};
GetConsoleCursorInfo(h_wy, &cci);
cci.bVisible = false;
SetConsoleCursorInfo(h_wy, &cci);
COORD p = {0};
DWORD k;
//FillConsoleOutputAttribute(h_wy, 0x07, 80 * 25, p, &k);
//FillConsoleOutputCharacter(h_wy, 0x20, 80 * 25, p, &k);
while(1)
{
INPUT_RECORD ipr = {0};
DWORD p = 0;
for (int i = 0; i < ile; i++)
{
COORD poz = {21, 5 + i};
DWORD p;
SetConsoleCursorPosition(h_wy, poz);
SetConsoleTextAttribute(h_wy, (wybor == i + 1) ? 0x84 : 0x07);
cout << teksty[i];
}
if (ReadConsoleInput(h_we, &ipr, 1, &p) && p == 1 &&
ipr.EventType == KEY_EVENT && ipr.Event.KeyEvent.bKeyDown)
switch (ipr.Event.KeyEvent.wVirtualKeyCode)
{
case VK_UP:
wybor = (wybor == 1) ? ile : wybor - 1;
break;
case VK_DOWN:
wybor = (wybor == ile) ? 1 : wybor + 1;
break;
case VK_RETURN:
cci.bVisible = true;
SetConsoleCursorInfo(h_wy, &cci);
return wybor;
}
}
}
Unfortunatelly I dont define array of options for it, It reads whole array from file..and it also works great...
void load_config()
{
ile_opcji=0;
string filename,line;
filename="config.ini";
ifstream plik_wejsciowy (filename.c_str());
if (plik_wejsciowy.is_open())
while (! plik_wejsciowy.eof() )
{
ile_opcji++;
getline (plik_wejsciowy,line);
if (line == "") continue;
opcje_global[ile_opcji]=line;
}
ile_opcji++;
opcje_global[ile_opcji]="CUSTOM";
ile_opcji++;
opcje_global[ile_opcji]="REMOVE";
ile_opcji++;
opcje_global[ile_opcji]="DONE";
}
Unfortunatelly, as far as I know..its impossible to make Case+variable statement. And I need to do that in order to create dependence between number of options and choices.
but...I dont know why only Case solution works...I dont know wht IF...else doesnt work (there is no error but when i choose option that correspons with number defined in if else statement, nothing happens) please HELP!
void system_affected()
{
char input[ 45 ];
int ai,az;
int token;
az=1;
ai=1;
bool wyjscie;
wyjscie=0;
system ("cls");
load_config();
gotoxy(1,15); cout << "Templater";
while (wyjscie !=1)
{
system ("cls");
gotoxy(1,1); cout << "Systems affected: ";
//wyswteitla awarie systemow
wyswietl(i);
cout << token;
// koniec wyswietlania
switch (menu(opcje_global+1, ile_opcji))
{
case 1:
cout << "It works";
system ("pause");
break;
if (menu(opcje_global+1, ile_opcji)==2)
{
cout << "It doesnt work - WHY?";
system ("pause");
break;
}
}
}